epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkImageDecoder.h" |
| 11 | #include "SkColor.h" |
| 12 | #include "SkColorPriv.h" |
| 13 | #include "SkStream.h" |
| 14 | #include "SkTemplates.h" |
| 15 | #include "SkPackBits.h" |
| 16 | |
| 17 | #include "gif_lib.h" |
| 18 | |
| 19 | class SkGIFImageDecoder : public SkImageDecoder { |
| 20 | public: |
commit-bot@chromium.org | a936e37 | 2013-03-14 14:42:18 +0000 | [diff] [blame] | 21 | virtual Format getFormat() const SK_OVERRIDE { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | return kGIF_Format; |
| 23 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 24 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | protected: |
commit-bot@chromium.org | a936e37 | 2013-03-14 14:42:18 +0000 | [diff] [blame] | 26 | virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE; |
| 27 | |
| 28 | private: |
| 29 | typedef SkImageDecoder INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | static const uint8_t gStartingIterlaceYValue[] = { |
| 33 | 0, 4, 2, 1 |
| 34 | }; |
| 35 | static const uint8_t gDeltaIterlaceYValue[] = { |
| 36 | 8, 8, 4, 2 |
| 37 | }; |
| 38 | |
| 39 | /* Implement the GIF interlace algorithm in an iterator. |
| 40 | 1) grab every 8th line beginning at 0 |
| 41 | 2) grab every 8th line beginning at 4 |
| 42 | 3) grab every 4th line beginning at 2 |
| 43 | 4) grab every 2nd line beginning at 1 |
| 44 | */ |
| 45 | class GifInterlaceIter { |
| 46 | public: |
| 47 | GifInterlaceIter(int height) : fHeight(height) { |
| 48 | fStartYPtr = gStartingIterlaceYValue; |
| 49 | fDeltaYPtr = gDeltaIterlaceYValue; |
| 50 | |
| 51 | fCurrY = *fStartYPtr++; |
| 52 | fDeltaY = *fDeltaYPtr++; |
| 53 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 54 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | int currY() const { |
| 56 | SkASSERT(fStartYPtr); |
| 57 | SkASSERT(fDeltaYPtr); |
| 58 | return fCurrY; |
| 59 | } |
| 60 | |
| 61 | void next() { |
| 62 | SkASSERT(fStartYPtr); |
| 63 | SkASSERT(fDeltaYPtr); |
| 64 | |
| 65 | int y = fCurrY + fDeltaY; |
| 66 | // We went from an if statement to a while loop so that we iterate |
| 67 | // through fStartYPtr until a valid row is found. This is so that images |
| 68 | // that are smaller than 5x5 will not trash memory. |
| 69 | while (y >= fHeight) { |
| 70 | if (gStartingIterlaceYValue + |
| 71 | SK_ARRAY_COUNT(gStartingIterlaceYValue) == fStartYPtr) { |
| 72 | // we done |
| 73 | SkDEBUGCODE(fStartYPtr = NULL;) |
| 74 | SkDEBUGCODE(fDeltaYPtr = NULL;) |
| 75 | y = 0; |
| 76 | } else { |
| 77 | y = *fStartYPtr++; |
| 78 | fDeltaY = *fDeltaYPtr++; |
| 79 | } |
| 80 | } |
| 81 | fCurrY = y; |
| 82 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 83 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 84 | private: |
| 85 | const int fHeight; |
| 86 | int fCurrY; |
| 87 | int fDeltaY; |
| 88 | const uint8_t* fStartYPtr; |
| 89 | const uint8_t* fDeltaYPtr; |
| 90 | }; |
| 91 | |
| 92 | /////////////////////////////////////////////////////////////////////////////// |
| 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, |
| 98 | int size) { |
| 99 | SkStream* stream = (SkStream*) fileType->UserData; |
| 100 | return (int) stream->read(out, size); |
| 101 | } |
| 102 | |
| 103 | void CheckFreeExtension(SavedImage* Image) { |
| 104 | if (Image->ExtensionBlocks) { |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 105 | #if GIFLIB_MAJOR < 5 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | FreeExtension(Image); |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 107 | #else |
| 108 | GifFreeExtensions(&Image->ExtensionBlockCount, &Image->ExtensionBlocks); |
| 109 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
| 113 | // return NULL on failure |
| 114 | static const ColorMapObject* find_colormap(const GifFileType* gif) { |
| 115 | const ColorMapObject* cmap = gif->Image.ColorMap; |
| 116 | if (NULL == cmap) { |
| 117 | cmap = gif->SColorMap; |
| 118 | } |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 119 | |
| 120 | if (NULL == cmap) { |
| 121 | // no colormap found |
| 122 | return NULL; |
| 123 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 124 | // some sanity checks |
reed@android.com | bc7d2fb | 2010-02-05 15:43:07 +0000 | [diff] [blame] | 125 | if (cmap && ((unsigned)cmap->ColorCount > 256 || |
| 126 | cmap->ColorCount != (1 << cmap->BitsPerPixel))) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 127 | cmap = NULL; |
| 128 | } |
| 129 | return cmap; |
| 130 | } |
| 131 | |
| 132 | // return -1 if not found (i.e. we're completely opaque) |
| 133 | static int find_transpIndex(const SavedImage& image, int colorCount) { |
| 134 | int transpIndex = -1; |
| 135 | for (int i = 0; i < image.ExtensionBlockCount; ++i) { |
| 136 | const ExtensionBlock* eb = image.ExtensionBlocks + i; |
| 137 | if (eb->Function == 0xF9 && eb->ByteCount == 4) { |
| 138 | if (eb->Bytes[0] & 1) { |
| 139 | transpIndex = (unsigned char)eb->Bytes[3]; |
| 140 | // check for valid transpIndex |
| 141 | if (transpIndex >= colorCount) { |
| 142 | transpIndex = -1; |
| 143 | } |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | return transpIndex; |
| 149 | } |
| 150 | |
| 151 | static bool error_return(GifFileType* gif, const SkBitmap& bm, |
| 152 | const char msg[]) { |
| 153 | #if 0 |
| 154 | SkDebugf("libgif error <%s> bitmap [%d %d] pixels %p colortable %p\n", |
| 155 | msg, bm.width(), bm.height(), bm.getPixels(), bm.getColorTable()); |
| 156 | #endif |
| 157 | return false; |
| 158 | } |
| 159 | |
reed@android.com | 3f1f06a | 2010-03-03 21:04:12 +0000 | [diff] [blame] | 160 | bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, Mode mode) { |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 161 | #if GIFLIB_MAJOR < 5 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 162 | GifFileType* gif = DGifOpen(sk_stream, DecodeCallBackProc); |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 163 | #else |
| 164 | GifFileType* gif = DGifOpen(sk_stream, DecodeCallBackProc, NULL); |
| 165 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 166 | if (NULL == gif) { |
| 167 | return error_return(gif, *bm, "DGifOpen"); |
| 168 | } |
| 169 | |
| 170 | SkAutoTCallIProc<GifFileType, DGifCloseFile> acp(gif); |
| 171 | |
| 172 | SavedImage temp_save; |
| 173 | temp_save.ExtensionBlocks=NULL; |
| 174 | temp_save.ExtensionBlockCount=0; |
| 175 | SkAutoTCallVProc<SavedImage, CheckFreeExtension> acp2(&temp_save); |
| 176 | |
| 177 | int width, height; |
| 178 | GifRecordType recType; |
| 179 | GifByteType *extData; |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 180 | #if GIFLIB_MAJOR >= 5 |
| 181 | int extFunction; |
| 182 | #endif |
reed@android.com | 9781ca5 | 2009-04-14 14:28:22 +0000 | [diff] [blame] | 183 | int transpIndex = -1; // -1 means we don't have it (yet) |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 184 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 185 | do { |
| 186 | if (DGifGetRecordType(gif, &recType) == GIF_ERROR) { |
| 187 | return error_return(gif, *bm, "DGifGetRecordType"); |
| 188 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 189 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 190 | switch (recType) { |
| 191 | case IMAGE_DESC_RECORD_TYPE: { |
| 192 | if (DGifGetImageDesc(gif) == GIF_ERROR) { |
| 193 | return error_return(gif, *bm, "IMAGE_DESC_RECORD_TYPE"); |
| 194 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 195 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 196 | if (gif->ImageCount < 1) { // sanity check |
| 197 | return error_return(gif, *bm, "ImageCount < 1"); |
| 198 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 199 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 200 | width = gif->SWidth; |
| 201 | height = gif->SHeight; |
| 202 | if (width <= 0 || height <= 0 || |
| 203 | !this->chooseFromOneChoice(SkBitmap::kIndex8_Config, |
| 204 | width, height)) { |
| 205 | return error_return(gif, *bm, "chooseFromOneChoice"); |
| 206 | } |
skia.committer@gmail.com | c49cabf | 2013-03-15 07:05:19 +0000 | [diff] [blame^] | 207 | |
commit-bot@chromium.org | a936e37 | 2013-03-14 14:42:18 +0000 | [diff] [blame] | 208 | if (SkImageDecoder::kDecodeBounds_Mode == mode) { |
| 209 | bm->setConfig(SkBitmap::kIndex8_Config, width, height); |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | // No Bitmap reuse supported for this format |
| 214 | if (!bm->isNull()) { |
| 215 | return false; |
| 216 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 217 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 218 | bm->setConfig(SkBitmap::kIndex8_Config, width, height); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 219 | SavedImage* image = &gif->SavedImages[gif->ImageCount-1]; |
| 220 | const GifImageDesc& desc = image->ImageDesc; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 221 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 222 | // check for valid descriptor |
| 223 | if ( (desc.Top | desc.Left) < 0 || |
| 224 | desc.Left + desc.Width > width || |
| 225 | desc.Top + desc.Height > height) { |
| 226 | return error_return(gif, *bm, "TopLeft"); |
| 227 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 228 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 229 | // now we decode the colortable |
| 230 | int colorCount = 0; |
| 231 | { |
| 232 | const ColorMapObject* cmap = find_colormap(gif); |
| 233 | if (NULL == cmap) { |
| 234 | return error_return(gif, *bm, "null cmap"); |
| 235 | } |
| 236 | |
| 237 | colorCount = cmap->ColorCount; |
| 238 | SkColorTable* ctable = SkNEW_ARGS(SkColorTable, (colorCount)); |
| 239 | SkPMColor* colorPtr = ctable->lockColors(); |
| 240 | for (int index = 0; index < colorCount; index++) |
| 241 | colorPtr[index] = SkPackARGB32(0xFF, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 242 | cmap->Colors[index].Red, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 243 | cmap->Colors[index].Green, |
| 244 | cmap->Colors[index].Blue); |
| 245 | |
reed@android.com | 9781ca5 | 2009-04-14 14:28:22 +0000 | [diff] [blame] | 246 | transpIndex = find_transpIndex(temp_save, colorCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 247 | if (transpIndex < 0) |
| 248 | ctable->setFlags(ctable->getFlags() | SkColorTable::kColorsAreOpaque_Flag); |
| 249 | else |
| 250 | colorPtr[transpIndex] = 0; // ram in a transparent SkPMColor |
| 251 | ctable->unlockColors(true); |
| 252 | |
| 253 | SkAutoUnref aurts(ctable); |
| 254 | if (!this->allocPixelRef(bm, ctable)) { |
| 255 | return error_return(gif, *bm, "allocPixelRef"); |
| 256 | } |
| 257 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 258 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 259 | SkAutoLockPixels alp(*bm); |
| 260 | |
| 261 | // time to decode the scanlines |
| 262 | // |
| 263 | uint8_t* scanline = bm->getAddr8(0, 0); |
| 264 | const int rowBytes = bm->rowBytes(); |
| 265 | const int innerWidth = desc.Width; |
| 266 | const int innerHeight = desc.Height; |
| 267 | |
| 268 | // abort if either inner dimension is <= 0 |
| 269 | if (innerWidth <= 0 || innerHeight <= 0) { |
| 270 | return error_return(gif, *bm, "non-pos inner width/height"); |
| 271 | } |
| 272 | |
| 273 | // are we only a subset of the total bounds? |
| 274 | if ((desc.Top | desc.Left) > 0 || |
| 275 | innerWidth < width || innerHeight < height) |
| 276 | { |
reed@android.com | 9781ca5 | 2009-04-14 14:28:22 +0000 | [diff] [blame] | 277 | int fill; |
| 278 | if (transpIndex >= 0) { |
| 279 | fill = transpIndex; |
| 280 | } else { |
| 281 | fill = gif->SBackGroundColor; |
| 282 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 283 | // check for valid fill index/color |
reed@android.com | 9781ca5 | 2009-04-14 14:28:22 +0000 | [diff] [blame] | 284 | if (static_cast<unsigned>(fill) >= |
| 285 | static_cast<unsigned>(colorCount)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 286 | fill = 0; |
| 287 | } |
reed@android.com | 9781ca5 | 2009-04-14 14:28:22 +0000 | [diff] [blame] | 288 | memset(scanline, fill, bm->getSize()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 289 | // bump our starting address |
| 290 | scanline += desc.Top * rowBytes + desc.Left; |
| 291 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 292 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 293 | // now decode each scanline |
| 294 | if (gif->Image.Interlace) |
| 295 | { |
| 296 | GifInterlaceIter iter(innerHeight); |
| 297 | for (int y = 0; y < innerHeight; y++) |
| 298 | { |
| 299 | uint8_t* row = scanline + iter.currY() * rowBytes; |
| 300 | if (DGifGetLine(gif, row, innerWidth) == GIF_ERROR) { |
| 301 | return error_return(gif, *bm, "interlace DGifGetLine"); |
| 302 | } |
| 303 | iter.next(); |
| 304 | } |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | // easy, non-interlace case |
| 309 | for (int y = 0; y < innerHeight; y++) { |
| 310 | if (DGifGetLine(gif, scanline, innerWidth) == GIF_ERROR) { |
| 311 | return error_return(gif, *bm, "DGifGetLine"); |
| 312 | } |
| 313 | scanline += rowBytes; |
| 314 | } |
| 315 | } |
| 316 | goto DONE; |
| 317 | } break; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 318 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 319 | case EXTENSION_RECORD_TYPE: |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 320 | #if GIFLIB_MAJOR < 5 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 321 | if (DGifGetExtension(gif, &temp_save.Function, |
| 322 | &extData) == GIF_ERROR) { |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 323 | #else |
| 324 | if (DGifGetExtension(gif, &extFunction, &extData) == GIF_ERROR) { |
| 325 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 326 | return error_return(gif, *bm, "DGifGetExtension"); |
| 327 | } |
| 328 | |
| 329 | while (extData != NULL) { |
| 330 | /* Create an extension block with our data */ |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 331 | #if GIFLIB_MAJOR < 5 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 332 | if (AddExtensionBlock(&temp_save, extData[0], |
| 333 | &extData[1]) == GIF_ERROR) { |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 334 | #else |
| 335 | if (GifAddExtensionBlock(&gif->ExtensionBlockCount, |
| 336 | &gif->ExtensionBlocks, |
| 337 | extFunction, |
| 338 | extData[0], |
| 339 | &extData[1]) == GIF_ERROR) { |
| 340 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 341 | return error_return(gif, *bm, "AddExtensionBlock"); |
| 342 | } |
| 343 | if (DGifGetExtensionNext(gif, &extData) == GIF_ERROR) { |
| 344 | return error_return(gif, *bm, "DGifGetExtensionNext"); |
| 345 | } |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 346 | #if GIFLIB_MAJOR < 5 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 347 | temp_save.Function = 0; |
reed@google.com | bb89613 | 2013-02-01 19:05:48 +0000 | [diff] [blame] | 348 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 349 | } |
| 350 | break; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 351 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 352 | case TERMINATE_RECORD_TYPE: |
| 353 | break; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 354 | |
| 355 | default: /* Should be trapped by DGifGetRecordType */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 356 | break; |
| 357 | } |
| 358 | } while (recType != TERMINATE_RECORD_TYPE); |
| 359 | |
| 360 | DONE: |
| 361 | return true; |
| 362 | } |
| 363 | |
| 364 | /////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | ec51cb8 | 2012-03-23 18:13:47 +0000 | [diff] [blame] | 365 | DEFINE_DECODER_CREATOR(GIFImageDecoder); |
| 366 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 367 | |
reed@android.com | 00bf85a | 2009-01-22 13:04:56 +0000 | [diff] [blame] | 368 | #include "SkTRegistry.h" |
| 369 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 370 | static SkImageDecoder* sk_libgif_dfactory(SkStream* stream) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 371 | char buf[GIF_STAMP_LEN]; |
| 372 | if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) { |
| 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 | } |
| 379 | return NULL; |
| 380 | } |
| 381 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 382 | static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libgif_dfactory); |