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

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

Issue 23477009: Change SkImageDecoders to take an SkStreamRewindable. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove accidental whitespace change Created 7 years, 3 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 "SkMovie.h" 10 #include "SkMovie.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 "SkUtils.h" 15 #include "SkUtils.h"
16 16
17 #include "gif_lib.h" 17 #include "gif_lib.h"
18 18
19 class SkGIFMovie : public SkMovie { 19 class SkGIFMovie : public SkMovie {
20 public: 20 public:
21 SkGIFMovie(SkStream* stream); 21 SkGIFMovie(SkStreamRewindable* stream);
22 virtual ~SkGIFMovie(); 22 virtual ~SkGIFMovie();
23 23
24 protected: 24 protected:
25 virtual bool onGetInfo(Info*); 25 virtual bool onGetInfo(Info*);
26 virtual bool onSetTime(SkMSec); 26 virtual bool onSetTime(SkMSec);
27 virtual bool onGetBitmap(SkBitmap*); 27 virtual bool onGetBitmap(SkBitmap*);
28 28
29 private: 29 private:
30 GifFileType* fGIF; 30 GifFileType* fGIF;
31 int fCurrIndex; 31 int fCurrIndex;
32 int fLastDrawIndex; 32 int fLastDrawIndex;
33 SkBitmap fBackup; 33 SkBitmap fBackup;
34 }; 34 };
35 35
36 static int Decode(GifFileType* fileType, GifByteType* out, int size) { 36 static int Decode(GifFileType* fileType, GifByteType* out, int size) {
37 SkStream* stream = (SkStream*) fileType->UserData; 37 SkStreamRewindable* stream = (SkStreamRewindable*) fileType->UserData;
38 return (int) stream->read(out, size); 38 return (int) stream->read(out, size);
39 } 39 }
40 40
41 SkGIFMovie::SkGIFMovie(SkStream* stream) 41 SkGIFMovie::SkGIFMovie(SkStreamRewindable* stream)
42 { 42 {
43 #if GIFLIB_MAJOR < 5 43 #if GIFLIB_MAJOR < 5
44 fGIF = DGifOpen( stream, Decode ); 44 fGIF = DGifOpen( stream, Decode );
45 #else 45 #else
46 fGIF = DGifOpen( stream, Decode, NULL ); 46 fGIF = DGifOpen( stream, Decode, NULL );
47 #endif 47 #endif
48 if (NULL == fGIF) 48 if (NULL == fGIF)
49 return; 49 return;
50 50
51 if (DGifSlurp(fGIF) != GIF_OK) 51 if (DGifSlurp(fGIF) != GIF_OK)
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 425
426 // save index 426 // save index
427 fLastDrawIndex = lastIndex; 427 fLastDrawIndex = lastIndex;
428 return true; 428 return true;
429 } 429 }
430 430
431 /////////////////////////////////////////////////////////////////////////////// 431 ///////////////////////////////////////////////////////////////////////////////
432 432
433 #include "SkTRegistry.h" 433 #include "SkTRegistry.h"
434 434
435 SkMovie* Factory(SkStream* stream) { 435 SkMovie* Factory(SkStreamRewindable* stream) {
436 char buf[GIF_STAMP_LEN]; 436 char buf[GIF_STAMP_LEN];
437 if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) { 437 if (stream->read(buf, GIF_STAMP_LEN) == GIF_STAMP_LEN) {
438 if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 || 438 if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 ||
439 memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 || 439 memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 ||
440 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) { 440 memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) {
441 // must rewind here, since our construct wants to re-read the data 441 // must rewind here, since our construct wants to re-read the data
442 stream->rewind(); 442 stream->rewind();
443 return SkNEW_ARGS(SkGIFMovie, (stream)); 443 return SkNEW_ARGS(SkGIFMovie, (stream));
444 } 444 }
445 } 445 }
446 return NULL; 446 return NULL;
447 } 447 }
448 448
449 static SkTRegistry<SkMovie*, SkStream*> gReg(Factory); 449 static SkTRegistry<SkMovie*, SkStreamRewindable*> gReg(Factory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698