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

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

Issue 1184083002: SkGIFMovie: Fix corrupted background color (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Change commit message Created 5 years, 6 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
« no previous file with comments | « no previous file | no next file » | 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 /* 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 "SkMovie.h" 10 #include "SkMovie.h"
(...skipping 17 matching lines...) Expand all
28 protected: 28 protected:
29 virtual bool onGetInfo(Info*); 29 virtual bool onGetInfo(Info*);
30 virtual bool onSetTime(SkMSec); 30 virtual bool onSetTime(SkMSec);
31 virtual bool onGetBitmap(SkBitmap*); 31 virtual bool onGetBitmap(SkBitmap*);
32 32
33 private: 33 private:
34 GifFileType* fGIF; 34 GifFileType* fGIF;
35 int fCurrIndex; 35 int fCurrIndex;
36 int fLastDrawIndex; 36 int fLastDrawIndex;
37 SkBitmap fBackup; 37 SkBitmap fBackup;
38 SkColor fPaintingColor;
38 }; 39 };
39 40
40 static int Decode(GifFileType* fileType, GifByteType* out, int size) { 41 static int Decode(GifFileType* fileType, GifByteType* out, int size) {
41 SkStream* stream = (SkStream*) fileType->UserData; 42 SkStream* stream = (SkStream*) fileType->UserData;
42 return (int) stream->read(out, size); 43 return (int) stream->read(out, size);
43 } 44 }
44 45
45 SkGIFMovie::SkGIFMovie(SkStream* stream) 46 SkGIFMovie::SkGIFMovie(SkStream* stream)
46 { 47 {
47 #if GIFLIB_MAJOR < 5 48 #if GIFLIB_MAJOR < 5
48 fGIF = DGifOpen( stream, Decode ); 49 fGIF = DGifOpen( stream, Decode );
49 #else 50 #else
50 fGIF = DGifOpen( stream, Decode, NULL ); 51 fGIF = DGifOpen( stream, Decode, NULL );
51 #endif 52 #endif
52 if (NULL == fGIF) 53 if (NULL == fGIF)
53 return; 54 return;
54 55
55 if (DGifSlurp(fGIF) != GIF_OK) 56 if (DGifSlurp(fGIF) != GIF_OK)
56 { 57 {
57 DGifCloseFile(fGIF, NULL); 58 DGifCloseFile(fGIF, NULL);
58 fGIF = NULL; 59 fGIF = NULL;
59 } 60 }
60 fCurrIndex = -1; 61 fCurrIndex = -1;
61 fLastDrawIndex = -1; 62 fLastDrawIndex = -1;
63 fPaintingColor = SkPackARGB32(0, 0, 0, 0);
62 } 64 }
63 65
64 SkGIFMovie::~SkGIFMovie() 66 SkGIFMovie::~SkGIFMovie()
65 { 67 {
66 if (fGIF) 68 if (fGIF)
67 DGifCloseFile(fGIF, NULL); 69 DGifCloseFile(fGIF, NULL);
68 } 70 }
69 71
70 static SkMSec savedimage_duration(const SavedImage* image) 72 static SkMSec savedimage_duration(const SavedImage* image)
71 { 73 {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 // this block must not be reached. 390 // this block must not be reached.
389 lastIndex = fGIF->ImageCount - 1; 391 lastIndex = fGIF->ImageCount - 1;
390 } 392 }
391 393
392 SkColor bgColor = SkPackARGB32(0, 0, 0, 0); 394 SkColor bgColor = SkPackARGB32(0, 0, 0, 0);
393 if (gif->SColorMap != NULL) { 395 if (gif->SColorMap != NULL) {
394 const GifColorType& col = gif->SColorMap->Colors[fGIF->SBackGroundColor] ; 396 const GifColorType& col = gif->SColorMap->Colors[fGIF->SBackGroundColor] ;
395 bgColor = SkColorSetARGB(0xFF, col.Red, col.Green, col.Blue); 397 bgColor = SkColorSetARGB(0xFF, col.Red, col.Green, col.Blue);
396 } 398 }
397 399
398 static SkColor paintingColor = SkPackARGB32(0, 0, 0, 0);
399 // draw each frames - not intelligent way 400 // draw each frames - not intelligent way
400 for (int i = startIndex; i <= lastIndex; i++) { 401 for (int i = startIndex; i <= lastIndex; i++) {
401 const SavedImage* cur = &fGIF->SavedImages[i]; 402 const SavedImage* cur = &fGIF->SavedImages[i];
402 if (i == 0) { 403 if (i == 0) {
403 bool trans; 404 bool trans;
404 int disposal; 405 int disposal;
405 getTransparencyAndDisposalMethod(cur, &trans, &disposal); 406 getTransparencyAndDisposalMethod(cur, &trans, &disposal);
406 if (!trans && gif->SColorMap != NULL) { 407 if (!trans && gif->SColorMap != NULL) {
407 paintingColor = bgColor; 408 fPaintingColor = bgColor;
408 } else { 409 } else {
409 paintingColor = SkColorSetARGB(0, 0, 0, 0); 410 fPaintingColor = SkColorSetARGB(0, 0, 0, 0);
410 } 411 }
411 412
412 bm->eraseColor(paintingColor); 413 bm->eraseColor(fPaintingColor);
413 fBackup.eraseColor(paintingColor); 414 fBackup.eraseColor(fPaintingColor);
414 } else { 415 } else {
415 // Dispose previous frame before move to next frame. 416 // Dispose previous frame before move to next frame.
416 const SavedImage* prev = &fGIF->SavedImages[i-1]; 417 const SavedImage* prev = &fGIF->SavedImages[i-1];
417 disposeFrameIfNeeded(bm, prev, cur, &fBackup, paintingColor); 418 disposeFrameIfNeeded(bm, prev, cur, &fBackup, fPaintingColor);
418 } 419 }
419 420
420 // Draw frame 421 // Draw frame
421 // We can skip this process if this index is not last and disposal 422 // We can skip this process if this index is not last and disposal
422 // method == 2 or method == 3 423 // method == 2 or method == 3
423 if (i == lastIndex || !checkIfWillBeCleared(cur)) { 424 if (i == lastIndex || !checkIfWillBeCleared(cur)) {
424 drawFrame(bm, cur, gif->SColorMap); 425 drawFrame(bm, cur, gif->SColorMap);
425 } 426 }
426 } 427 }
427 428
(...skipping 14 matching lines...) Expand all
442 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) { 443 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) {
443 // must rewind here, since our construct wants to re-read the data 444 // must rewind here, since our construct wants to re-read the data
444 stream->rewind(); 445 stream->rewind();
445 return SkNEW_ARGS(SkGIFMovie, (stream)); 446 return SkNEW_ARGS(SkGIFMovie, (stream));
446 } 447 }
447 } 448 }
448 return NULL; 449 return NULL;
449 } 450 }
450 451
451 static SkTRegistry<SkMovie*(*)(SkStreamRewindable*)> gReg(Factory); 452 static SkTRegistry<SkMovie*(*)(SkStreamRewindable*)> gReg(Factory);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698