| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 "SkImageDecoder_libgif.h" |
| 9 |
| 8 #include "SkColor.h" | 10 #include "SkColor.h" |
| 9 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 10 #include "SkColorTable.h" | 12 #include "SkColorTable.h" |
| 11 #include "SkImageDecoder.h" | |
| 12 #include "SkRTConf.h" | 13 #include "SkRTConf.h" |
| 13 #include "SkScaledBitmapSampler.h" | 14 #include "SkScaledBitmapSampler.h" |
| 14 #include "SkStream.h" | 15 #include "SkStream.h" |
| 15 #include "SkTemplates.h" | 16 #include "SkTemplates.h" |
| 16 #include "SkUtils.h" | 17 #include "SkUtils.h" |
| 17 | 18 |
| 18 #include "gif_lib.h" | 19 #include "gif_lib.h" |
| 19 | 20 |
| 20 class SkGIFImageDecoder : public SkImageDecoder { | 21 class SkGIFImageDecoder : public SkImageDecoder { |
| 21 public: | 22 public: |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 495 |
| 495 default: /* Should be trapped by DGifGetRecordType */ | 496 default: /* Should be trapped by DGifGetRecordType */ |
| 496 break; | 497 break; |
| 497 } | 498 } |
| 498 } while (recType != TERMINATE_RECORD_TYPE); | 499 } while (recType != TERMINATE_RECORD_TYPE); |
| 499 | 500 |
| 500 sanitize_indexed_bitmap(bm); | 501 sanitize_indexed_bitmap(bm); |
| 501 return true; | 502 return true; |
| 502 } | 503 } |
| 503 | 504 |
| 504 /////////////////////////////////////////////////////////////////////////////// | 505 SkImageDecoder::Format SkDetectFormatGIFImageDecoder(SkStreamRewindable* stream)
{ |
| 505 DEFINE_DECODER_CREATOR(GIFImageDecoder); | |
| 506 /////////////////////////////////////////////////////////////////////////////// | |
| 507 | |
| 508 static bool is_gif(SkStreamRewindable* stream) { | |
| 509 char buf[GIF_STAMP_LEN]; | 506 char buf[GIF_STAMP_LEN]; |
| 510 if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) { | 507 if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) { |
| 511 if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 || | 508 if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 || |
| 512 memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 || | 509 memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 || |
| 513 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) { | 510 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) { |
| 514 return true; | 511 return SkImageDecoder::kGIF_Format; |
| 515 } | 512 } |
| 516 } | 513 } |
| 517 return false; | 514 return SkImageDecoder::kUnknown_Format; |
| 518 } | 515 } |
| 519 | 516 |
| 520 static SkImageDecoder* sk_libgif_dfactory(SkStreamRewindable* stream) { | 517 SkImageDecoder* SkCreateGIFImageDecoder(SkStreamRewindable* stream) { |
| 521 if (is_gif(stream)) { | 518 if (SkDetectFormatGIFImageDecoder(stream) == SkImageDecoder::kGIF_Format) { |
| 522 return SkNEW(SkGIFImageDecoder); | 519 return SkNEW(SkGIFImageDecoder); |
| 523 } | 520 } |
| 524 return NULL; | 521 return NULL; |
| 525 } | 522 } |
| 526 | |
| 527 static SkImageDecoder_DecodeReg gReg(sk_libgif_dfactory); | |
| 528 | |
| 529 static SkImageDecoder::Format get_format_gif(SkStreamRewindable* stream) { | |
| 530 if (is_gif(stream)) { | |
| 531 return SkImageDecoder::kGIF_Format; | |
| 532 } | |
| 533 return SkImageDecoder::kUnknown_Format; | |
| 534 } | |
| 535 | |
| 536 static SkImageDecoder_FormatReg gFormatReg(get_format_gif); | |
| OLD | NEW |