FrameSequence_webp.h revision b34f1da83570613bb349f8026d4325552ac495ed
1b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi/*
2b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi * Copyright (C) 2013 The Android Open Source Project
3b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi *
4b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi * Licensed under the Apache License, Version 2.0 (the "License");
5b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi * you may not use this file except in compliance with the License.
6b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi * You may obtain a copy of the License at
7b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi *
8b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi *      http://www.apache.org/licenses/LICENSE-2.0
9b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi *
10b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi * Unless required by applicable law or agreed to in writing, software
11b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi * distributed under the License is distributed on an "AS IS" BASIS,
12b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi * See the License for the specific language governing permissions and
14b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi * limitations under the License.
15b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi */
16b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
17b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi#ifndef RASTERMILL_FRAMESQUENCE_WEBP_H
18b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi#define RASTERMILL_FRAMESQUENCE_WEBP_H
19b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
20b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi#include "config.h"
21b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi#include "webp/decode.h"
22b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi#include "webp/demux.h"
23b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
24b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi#include "Stream.h"
25b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi#include "Color.h"
26b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi#include "FrameSequence.h"
27b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
28b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi// Parser for a possibly-animated WebP bitstream.
29b34f1da83570613bb349f8026d4325552ac495edUrvang Joshiclass FrameSequence_webp : public FrameSequence {
30b34f1da83570613bb349f8026d4325552ac495edUrvang Joshipublic:
31b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    FrameSequence_webp(Stream* stream);
32b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    virtual ~FrameSequence_webp();
33b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
34b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    virtual int getWidth() const {
35b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi        return WebPDemuxGetI(mDemux, WEBP_FF_CANVAS_WIDTH);
36b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    }
37b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
38b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    virtual int getHeight() const {
39b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi        return WebPDemuxGetI(mDemux, WEBP_FF_CANVAS_HEIGHT);
40b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    }
41b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
42b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    virtual bool isOpaque() const {
43b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi        return !(mFormatFlags & ALPHA_FLAG);
44b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    }
45b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
46b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    virtual int getFrameCount() const {
47b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi        return WebPDemuxGetI(mDemux, WEBP_FF_FRAME_COUNT);
48b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    }
49b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
50b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    virtual int getDefaultLoopCount() const {
51b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi        return mLoopCount;
52b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    }
53b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
54b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    virtual FrameSequenceState* createState() const;
55b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
56b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    WebPDemuxer* getDemuxer() const { return mDemux; }
57b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
58b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    bool isKeyFrame(size_t frameNr) const { return mIsKeyFrame[frameNr]; /* TODO: CHECK BOUNDS*/ }
59b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
60b34f1da83570613bb349f8026d4325552ac495edUrvang Joshiprivate:
61b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    void constructDependencyChain();
62b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
63b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    WebPData mData;
64b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    WebPDemuxer* mDemux;
65b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    int mLoopCount;
66b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    uint32_t mFormatFlags;
67b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    // mIsKeyFrame[i] is true if ith canvas can be constructed without decoding any prior frames.
68b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    bool* mIsKeyFrame;
69b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi};
70b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
71b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi// Produces frames of a possibly-animated WebP file for display.
72b34f1da83570613bb349f8026d4325552ac495edUrvang Joshiclass FrameSequenceState_webp : public FrameSequenceState {
73b34f1da83570613bb349f8026d4325552ac495edUrvang Joshipublic:
74b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    FrameSequenceState_webp(const FrameSequence_webp& frameSequence);
75b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    virtual ~FrameSequenceState_webp();
76b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
77b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    // Returns frame's delay time in milliseconds.
78b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    virtual long drawFrame(int frameNr,
79b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi            Color8888* outputPtr, int outputPixelStride, int previousFrameNr);
80b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
81b34f1da83570613bb349f8026d4325552ac495edUrvang Joshiprivate:
82b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    void initializeFrame(const WebPIterator& currIter, Color8888* currBuffer, int currStride,
83b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi            const WebPIterator& prevIter, const Color8888* prevBuffer, int prevStride);
84b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    bool decodeFrame(const WebPIterator& iter, Color8888* currBuffer, int currStride,
85b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi            const WebPIterator& prevIter, const Color8888* prevBuffer, int prevStride);
86b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
87b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    const FrameSequence_webp& mFrameSequence;
88b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    WebPDecoderConfig mDecoderConfig;
89b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi    Color8888* mPreservedBuffer;
90b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi};
91b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi
92b34f1da83570613bb349f8026d4325552ac495edUrvang Joshi#endif //RASTERMILL_FRAMESQUENCE_WEBP_H
93