blob: de59c6c32a4d1f511a14571c8f3213d60294e935 [file] [log] [blame]
msarett8c8f22a2015-04-01 06:58:48 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkCodec.h"
9#include "SkImageInfo.h"
10
11#include "gif_lib.h"
12
13/*
14 *
15 * This class implements the decoding for gif images
16 *
17 */
18class SkGifCodec : public SkCodec {
19public:
20
21 /*
22 * Checks the start of the stream to see if the image is a gif
23 */
24 static bool IsGif(SkStream*);
25
26 /*
27 * Assumes IsGif was called and returned true
28 * Creates a gif decoder
29 * Reads enough of the stream to determine the image format
30 */
31 static SkCodec* NewFromStream(SkStream*);
32
33
34protected:
35
36 /*
37 * Initiates the gif decode
38 */
39 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&,
40 SkPMColor*, int32_t*) override;
41
42 SkEncodedFormat onGetEncodedFormat() const override {
43 return kGIF_SkEncodedFormat;
44 }
45
46private:
47
48 /*
49 * This function cleans up the gif object after the decode completes
50 * It is used in a SkAutoTCallIProc template
51 */
52 static int32_t CloseGif(GifFileType* gif);
53
54 /*
55 * Frees any extension data used in the decode
56 * Used in a SkAutoTCallVProc
57 */
58 static void FreeExtension(SavedImage* image);
59
60 /*
61 * Creates an instance of the decoder
62 * Called only by NewFromStream
63 *
64 * @param srcInfo contains the source width and height
65 * @param stream the stream of image data
66 * @param gif pointer to library type that manages gif decode
67 * takes ownership
68 */
69 SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType* gif);
70
71 SkAutoTCallIProc<GifFileType, CloseGif> fGif; // owned
72
73 typedef SkCodec INHERITED;
74};