Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: src/codec/SkJpegCodec.cpp

Issue 1472123002: Make SkCodec support peek() and read() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/codec/SkJpegCodec.h ('k') | src/codec/SkWebpCodec.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkJpegCodec.h" 9 #include "SkJpegCodec.h"
10 #include "SkJpegDecoderMgr.h" 10 #include "SkJpegDecoderMgr.h"
11 #include "SkJpegUtility_codec.h" 11 #include "SkJpegUtility_codec.h"
12 #include "SkCodecPriv.h" 12 #include "SkCodecPriv.h"
13 #include "SkColorPriv.h" 13 #include "SkColorPriv.h"
14 #include "SkStream.h" 14 #include "SkStream.h"
15 #include "SkTemplates.h" 15 #include "SkTemplates.h"
16 #include "SkTypes.h" 16 #include "SkTypes.h"
17 17
18 // stdio is needed for libjpeg-turbo 18 // stdio is needed for libjpeg-turbo
19 #include <stdio.h> 19 #include <stdio.h>
20 20
21 extern "C" { 21 extern "C" {
22 #include "jerror.h" 22 #include "jerror.h"
23 #include "jpeglib.h" 23 #include "jpeglib.h"
24 } 24 }
25 25
26 bool SkJpegCodec::IsJpeg(SkStream* stream) { 26 bool SkJpegCodec::IsJpeg(const void* buffer, size_t bytesRead) {
27 static const uint8_t jpegSig[] = { 0xFF, 0xD8, 0xFF }; 27 static const uint8_t jpegSig[] = { 0xFF, 0xD8, 0xFF };
28 char buffer[sizeof(jpegSig)]; 28 return bytesRead >= 3 && !memcmp(buffer, jpegSig, sizeof(jpegSig));
29 return stream->read(buffer, sizeof(jpegSig)) == sizeof(jpegSig) &&
30 !memcmp(buffer, jpegSig, sizeof(jpegSig));
31 } 29 }
32 30
33 bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, 31 bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut,
34 JpegDecoderMgr** decoderMgrOut) { 32 JpegDecoderMgr** decoderMgrOut) {
35 33
36 // Create a JpegDecoderMgr to own all of the decompress information 34 // Create a JpegDecoderMgr to own all of the decompress information
37 SkAutoTDelete<JpegDecoderMgr> decoderMgr(new JpegDecoderMgr(stream)); 35 SkAutoTDelete<JpegDecoderMgr> decoderMgr(new JpegDecoderMgr(stream));
38 36
39 // libjpeg errors will be caught and reported here 37 // libjpeg errors will be caught and reported here
40 if (setjmp(decoderMgr->getJmpBuf())) { 38 if (setjmp(decoderMgr->getJmpBuf())) {
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 #endif 445 #endif
448 446
449 bool SkJpegCodec::onSkipScanlines(int count) { 447 bool SkJpegCodec::onSkipScanlines(int count) {
450 // Set the jump location for libjpeg errors 448 // Set the jump location for libjpeg errors
451 if (setjmp(fDecoderMgr->getJmpBuf())) { 449 if (setjmp(fDecoderMgr->getJmpBuf())) {
452 return fDecoderMgr->returnFalse("setjmp"); 450 return fDecoderMgr->returnFalse("setjmp");
453 } 451 }
454 452
455 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); 453 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count);
456 } 454 }
OLDNEW
« no previous file with comments | « src/codec/SkJpegCodec.h ('k') | src/codec/SkWebpCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698