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