FrameSequence_gif.h revision a3ac0a2df64dcfb8b0b01f1cf05e9afd1439e1f4
1/* 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 40 virtual int getFrameCount() const { 41 return mGif ? mGif->ImageCount : 0; 42 } 43 44 virtual bool isOpaque() const { 45 return (mBgColor & COLOR_8888_ALPHA_MASK) == COLOR_8888_ALPHA_MASK; 46 } 47 48 virtual FrameSequenceState* createState() const; 49 50 GifFileType* getGif() const { return mGif; } 51 Color8888 getBackgroundColor() const { return mBgColor; } 52 bool getPreservedFrame(int frameIndex) const { return mPreservedFrames[frameIndex]; } 53 int getRestoringFrame(int frameIndex) const { return mRestoringFrames[frameIndex]; } 54 55private: 56 GifFileType* mGif; 57 Color8888 mBgColor; 58 59 // array of bool per frame - if true, frame data is used by a later DISPOSE_PREVIOUS frame 60 bool* mPreservedFrames; 61 62 // array of ints per frame - if >= 0, points to the index of the preserve that frame needs 63 int* mRestoringFrames; 64}; 65 66class FrameSequenceState_gif : public FrameSequenceState { 67public: 68 FrameSequenceState_gif(const FrameSequence_gif& frameSequence); 69 virtual ~FrameSequenceState_gif(); 70 71 // returns frame's delay time in ms 72 virtual long drawFrame(int frameNr, 73 Color8888* outputPtr, int outputPixelStride, int previousFrameNr); 74 75private: 76 void savePreserveBuffer(Color8888* outputPtr, int outputPixelStride, int frameNr); 77 void restorePreserveBuffer(Color8888* outputPtr, int outputPixelStride); 78 79 const FrameSequence_gif& mFrameSequence; 80 Color8888* mPreserveBuffer; 81 int mPreserveBufferFrame; 82}; 83 84#endif //RASTERMILL_FRAMESQUENCE_GIF_H 85