OLD | NEW |
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" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 private: | 84 private: |
85 const int fHeight; | 85 const int fHeight; |
86 int fCurrY; | 86 int fCurrY; |
87 int fDeltaY; | 87 int fDeltaY; |
88 const uint8_t* fStartYPtr; | 88 const uint8_t* fStartYPtr; |
89 const uint8_t* fDeltaYPtr; | 89 const uint8_t* fDeltaYPtr; |
90 }; | 90 }; |
91 | 91 |
92 /////////////////////////////////////////////////////////////////////////////// | 92 /////////////////////////////////////////////////////////////////////////////// |
93 | 93 |
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, | 94 static int DecodeCallBackProc(GifFileType* fileType, GifByteType* out, |
98 int size) { | 95 int size) { |
99 SkStream* stream = (SkStream*) fileType->UserData; | 96 SkStream* stream = (SkStream*) fileType->UserData; |
100 return (int) stream->read(out, size); | 97 return (int) stream->read(out, size); |
101 } | 98 } |
102 | 99 |
103 void CheckFreeExtension(SavedImage* Image) { | 100 void CheckFreeExtension(SavedImage* Image) { |
104 if (Image->ExtensionBlocks) { | 101 if (Image->ExtensionBlocks) { |
105 #if GIFLIB_MAJOR < 5 | 102 #if GIFLIB_MAJOR < 5 |
106 FreeExtension(Image); | 103 FreeExtension(Image); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 } while (recType != TERMINATE_RECORD_TYPE); | 355 } while (recType != TERMINATE_RECORD_TYPE); |
359 | 356 |
360 DONE: | 357 DONE: |
361 return true; | 358 return true; |
362 } | 359 } |
363 | 360 |
364 /////////////////////////////////////////////////////////////////////////////// | 361 /////////////////////////////////////////////////////////////////////////////// |
365 DEFINE_DECODER_CREATOR(GIFImageDecoder); | 362 DEFINE_DECODER_CREATOR(GIFImageDecoder); |
366 /////////////////////////////////////////////////////////////////////////////// | 363 /////////////////////////////////////////////////////////////////////////////// |
367 | 364 |
368 #include "SkTRegistry.h" | 365 static bool is_gif(SkStream* stream) { |
369 | |
370 static SkImageDecoder* sk_libgif_dfactory(SkStream* stream) { | |
371 char buf[GIF_STAMP_LEN]; | 366 char buf[GIF_STAMP_LEN]; |
372 if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) { | 367 if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) { |
373 if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 || | 368 if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 || |
374 memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 || | 369 memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 || |
375 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) { | 370 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) { |
376 return SkNEW(SkGIFImageDecoder); | 371 return true; |
377 } | 372 } |
378 } | 373 } |
| 374 return false; |
| 375 } |
| 376 |
| 377 #include "SkTRegistry.h" |
| 378 |
| 379 static SkImageDecoder* sk_libgif_dfactory(SkStream* stream) { |
| 380 if (is_gif(stream)) { |
| 381 return SkNEW(SkGIFImageDecoder); |
| 382 } |
379 return NULL; | 383 return NULL; |
380 } | 384 } |
381 | 385 |
382 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libgif_dfactory); | 386 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libgif_dfactory); |
| 387 |
| 388 static SkImageDecoder::Format get_format_gif(SkStream* stream) { |
| 389 if (is_gif(stream)) { |
| 390 return SkImageDecoder::kGIF_Format; |
| 391 } |
| 392 return SkImageDecoder::kUnknown_Format; |
| 393 } |
| 394 |
| 395 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_gif)
; |
OLD | NEW |