blob: 8bf57b68ebe350117ff792321a7fe882f122a6a6 [file] [log] [blame]
Chris Craika3ac0a22014-01-06 12:43:42 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef RASTERMILL_FRAMESQUENCE_GIF_H
18#define RASTERMILL_FRAMESQUENCE_GIF_H
19
20#include "config.h"
21#include "gif_lib.h"
22
23#include "Stream.h"
24#include "Color.h"
25#include "FrameSequence.h"
26
27class FrameSequence_gif : public FrameSequence {
28public:
29 FrameSequence_gif(Stream* stream);
30 virtual ~FrameSequence_gif();
31
32 virtual int getWidth() const {
33 return mGif ? mGif->SWidth : 0;
34 }
35
36 virtual int getHeight() const {
37 return mGif ? mGif->SHeight : 0;
38 }
39
Chris Craike36c5d62014-01-13 19:37:04 -080040 virtual bool isOpaque() const {
41 return (mBgColor & COLOR_8888_ALPHA_MASK) == COLOR_8888_ALPHA_MASK;
42 }
43
Chris Craika3ac0a22014-01-06 12:43:42 -080044 virtual int getFrameCount() const {
45 return mGif ? mGif->ImageCount : 0;
46 }
47
Chris Craike36c5d62014-01-13 19:37:04 -080048 virtual int getDefaultLoopCount() const {
49 return mLoopCount;
Chris Craika3ac0a22014-01-06 12:43:42 -080050 }
51
52 virtual FrameSequenceState* createState() const;
53
54 GifFileType* getGif() const { return mGif; }
55 Color8888 getBackgroundColor() const { return mBgColor; }
56 bool getPreservedFrame(int frameIndex) const { return mPreservedFrames[frameIndex]; }
57 int getRestoringFrame(int frameIndex) const { return mRestoringFrames[frameIndex]; }
58
59private:
60 GifFileType* mGif;
Chris Craike36c5d62014-01-13 19:37:04 -080061 int mLoopCount;
Chris Craika3ac0a22014-01-06 12:43:42 -080062 Color8888 mBgColor;
63
64 // array of bool per frame - if true, frame data is used by a later DISPOSE_PREVIOUS frame
65 bool* mPreservedFrames;
66
67 // array of ints per frame - if >= 0, points to the index of the preserve that frame needs
68 int* mRestoringFrames;
69};
70
71class FrameSequenceState_gif : public FrameSequenceState {
72public:
73 FrameSequenceState_gif(const FrameSequence_gif& frameSequence);
74 virtual ~FrameSequenceState_gif();
75
76 // returns frame's delay time in ms
77 virtual long drawFrame(int frameNr,
78 Color8888* outputPtr, int outputPixelStride, int previousFrameNr);
79
80private:
81 void savePreserveBuffer(Color8888* outputPtr, int outputPixelStride, int frameNr);
82 void restorePreserveBuffer(Color8888* outputPtr, int outputPixelStride);
83
84 const FrameSequence_gif& mFrameSequence;
85 Color8888* mPreserveBuffer;
86 int mPreserveBufferFrame;
87};
88
89#endif //RASTERMILL_FRAMESQUENCE_GIF_H