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