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 27 class FrameSequence_gif : public FrameSequence { 28 public: 29 FrameSequence_gif(Stream* stream); 30 virtual ~FrameSequence_gif(); 31 getWidth()32 virtual int getWidth() const { 33 return mGif ? mGif->SWidth : 0; 34 } 35 getHeight()36 virtual int getHeight() const { 37 return mGif ? mGif->SHeight : 0; 38 } 39 isOpaque()40 virtual bool isOpaque() const { 41 return (mBgColor & COLOR_8888_ALPHA_MASK) == COLOR_8888_ALPHA_MASK; 42 } 43 getFrameCount()44 virtual int getFrameCount() const { 45 return mGif ? mGif->ImageCount : 0; 46 } 47 getDefaultLoopCount()48 virtual int getDefaultLoopCount() const { 49 return mLoopCount; 50 } 51 52 virtual FrameSequenceState* createState() const; 53 getGif()54 GifFileType* getGif() const { return mGif; } getBackgroundColor()55 Color8888 getBackgroundColor() const { return mBgColor; } getPreservedFrame(int frameIndex)56 bool getPreservedFrame(int frameIndex) const { return mPreservedFrames[frameIndex]; } getRestoringFrame(int frameIndex)57 int getRestoringFrame(int frameIndex) const { return mRestoringFrames[frameIndex]; } 58 59 private: 60 GifFileType* mGif; 61 int mLoopCount; 62 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 71 class FrameSequenceState_gif : public FrameSequenceState { 72 public: 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 80 private: 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 90