summaryrefslogtreecommitdiffstats
path: root/framesequence/jni/FrameSequence_gif.h
blob: 563f5b8ee8945610914ccaf606039b84c84647bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef RASTERMILL_FRAMESQUENCE_GIF_H
#define RASTERMILL_FRAMESQUENCE_GIF_H

#include "config.h"
#include "gif_lib.h"

#include "Stream.h"
#include "Color.h"
#include "FrameSequence.h"

class FrameSequence_gif : public FrameSequence {
public:
    FrameSequence_gif(Stream* stream);
    virtual ~FrameSequence_gif();

    virtual int getWidth() const {
        return mGif ? mGif->SWidth : 0;
    }

    virtual int getHeight() const {
        return mGif ? mGif->SHeight : 0;
    }

    virtual bool isOpaque() const {
        return (mBgColor & COLOR_8888_ALPHA_MASK) == COLOR_8888_ALPHA_MASK;
    }

    virtual int getFrameCount() const {
        return mGif ? mGif->ImageCount : 0;
    }

    virtual int getDefaultLoopCount() const {
        return mLoopCount;
    }

    virtual jobject getRawByteBuffer() const {
        return NULL;
    }

    virtual FrameSequenceState* createState() const;

    GifFileType* getGif() const { return mGif; }
    Color8888 getBackgroundColor() const { return mBgColor; }
    bool getPreservedFrame(int frameIndex) const { return mPreservedFrames[frameIndex]; }
    int getRestoringFrame(int frameIndex) const { return mRestoringFrames[frameIndex]; }

private:
    GifFileType* mGif;
    int mLoopCount;
    Color8888 mBgColor;

    // array of bool per frame - if true, frame data is used by a later DISPOSE_PREVIOUS frame
    bool* mPreservedFrames;

    // array of ints per frame - if >= 0, points to the index of the preserve that frame needs
    int* mRestoringFrames;
};

class FrameSequenceState_gif : public FrameSequenceState {
public:
    FrameSequenceState_gif(const FrameSequence_gif& frameSequence);
    virtual ~FrameSequenceState_gif();

    // returns frame's delay time in ms
    virtual long drawFrame(int frameNr,
            Color8888* outputPtr, int outputPixelStride, int previousFrameNr);

private:
    void savePreserveBuffer(Color8888* outputPtr, int outputPixelStride, int frameNr);
    void restorePreserveBuffer(Color8888* outputPtr, int outputPixelStride);

    const FrameSequence_gif& mFrameSequence;
    Color8888* mPreserveBuffer;
    int mPreserveBufferFrame;
};

#endif //RASTERMILL_FRAMESQUENCE_GIF_H