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

Side by Side Diff: src/images/SkImageDecoder_libgif.cpp

Issue 14363003: Updates to skimage tool to use it for testing. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Implement onGetFormat for other decoders. Created 7 years, 8 months 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
11 #include "SkColor.h" 11 #include "SkColor.h"
12 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
13 #include "SkStream.h" 13 #include "SkStream.h"
14 #include "SkTemplates.h" 14 #include "SkTemplates.h"
15 #include "SkPackBits.h" 15 #include "SkPackBits.h"
16 16
17 #include "gif_lib.h" 17 #include "gif_lib.h"
18 18
19 class SkGIFImageDecoder : public SkImageDecoder { 19 class SkGIFImageDecoder : public SkImageDecoder {
20 public: 20 public:
21 virtual Format getFormat() const SK_OVERRIDE { 21 virtual Format getFormat() const SK_OVERRIDE {
22 return kGIF_Format; 22 return kGIF_Format;
23 } 23 }
24 24
25 virtual Format onGetFormat(SkStream*) const SK_OVERRIDE;
26
25 protected: 27 protected:
26 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE ; 28 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE ;
27 29
28 private: 30 private:
29 typedef SkImageDecoder INHERITED; 31 typedef SkImageDecoder INHERITED;
30 }; 32 };
31 33
32 static const uint8_t gStartingIterlaceYValue[] = { 34 static const uint8_t gStartingIterlaceYValue[] = {
33 0, 4, 2, 1 35 0, 4, 2, 1
34 }; 36 };
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 private: 86 private:
85 const int fHeight; 87 const int fHeight;
86 int fCurrY; 88 int fCurrY;
87 int fDeltaY; 89 int fDeltaY;
88 const uint8_t* fStartYPtr; 90 const uint8_t* fStartYPtr;
89 const uint8_t* fDeltaYPtr; 91 const uint8_t* fDeltaYPtr;
90 }; 92 };
91 93
92 /////////////////////////////////////////////////////////////////////////////// 94 ///////////////////////////////////////////////////////////////////////////////
93 95
94 //#define GIF_STAMP "GIF" /* First chars in file - GIF stamp. */
95 //#define GIF_STAMP_LEN (sizeof(GIF_STAMP) - 1)
96
97 static int DecodeCallBackProc(GifFileType* fileType, GifByteType* out, 96 static int DecodeCallBackProc(GifFileType* fileType, GifByteType* out,
98 int size) { 97 int size) {
99 SkStream* stream = (SkStream*) fileType->UserData; 98 SkStream* stream = (SkStream*) fileType->UserData;
100 return (int) stream->read(out, size); 99 return (int) stream->read(out, size);
101 } 100 }
102 101
103 void CheckFreeExtension(SavedImage* Image) { 102 void CheckFreeExtension(SavedImage* Image) {
104 if (Image->ExtensionBlocks) { 103 if (Image->ExtensionBlocks) {
105 #if GIFLIB_MAJOR < 5 104 #if GIFLIB_MAJOR < 5
106 FreeExtension(Image); 105 FreeExtension(Image);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 353
355 default: /* Should be trapped by DGifGetRecordType */ 354 default: /* Should be trapped by DGifGetRecordType */
356 break; 355 break;
357 } 356 }
358 } while (recType != TERMINATE_RECORD_TYPE); 357 } while (recType != TERMINATE_RECORD_TYPE);
359 358
360 DONE: 359 DONE:
361 return true; 360 return true;
362 } 361 }
363 362
363 static bool is_gif(SkStream* stream) {
364 char buf[GIF_STAMP_LEN];
365 if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) {
366 if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 ||
367 memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 ||
368 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) {
369 return true;
370 }
371 }
372 return false;
373 }
374
375 SkImageDecoder::Format SkGIFImageDecoder::onGetFormat(SkStream* stream) const {
376 if (is_gif(stream)) {
377 return kGIF_Format;
378 }
379 return kUnknown_Format;
380 }
381
364 /////////////////////////////////////////////////////////////////////////////// 382 ///////////////////////////////////////////////////////////////////////////////
365 DEFINE_DECODER_CREATOR(GIFImageDecoder); 383 DEFINE_DECODER_CREATOR(GIFImageDecoder);
366 /////////////////////////////////////////////////////////////////////////////// 384 ///////////////////////////////////////////////////////////////////////////////
367 385
368 #include "SkTRegistry.h" 386 #include "SkTRegistry.h"
369 387
370 static SkImageDecoder* sk_libgif_dfactory(SkStream* stream) { 388 static SkImageDecoder* sk_libgif_dfactory(SkStream* stream) {
371 char buf[GIF_STAMP_LEN]; 389 if (is_gif(stream)) {
372 if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) { 390 return SkNEW(SkGIFImageDecoder);
373 if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 ||
374 memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 ||
375 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) {
376 return SkNEW(SkGIFImageDecoder);
377 }
378 } 391 }
379 return NULL; 392 return NULL;
380 } 393 }
381 394
382 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libgif_dfactory); 395 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libgif_dfactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698