1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef MUTATIONOFJB_ANIMATIONDECODER_H
24 #define MUTATIONOFJB_ANIMATIONDECODER_H
25 
26 #include "common/rect.h"
27 #include "common/scummsys.h"
28 #include "common/str.h"
29 
30 #include "graphics/surface.h"
31 #include "mutationofjb/encryptedfile.h"
32 
33 namespace Common {
34 class SeekableReadStream;
35 }
36 
37 namespace MutationOfJB {
38 
39 enum {
40 	PALETTE_COLORS = 256,
41 	PALETTE_SIZE = PALETTE_COLORS * 3,
42 	IMAGE_WIDTH = 320,
43 	IMAGE_HEIGHT = 200
44 };
45 
46 class AnimationDecoderCallback {
47 public:
48 	virtual void onFrame(int frameNo, Graphics::Surface &surface) = 0;
49 	virtual void onPaletteUpdated(byte palette[PALETTE_SIZE]) = 0;
~AnimationDecoderCallback()50 	virtual ~AnimationDecoderCallback() {}
51 };
52 
53 class AnimationDecoder {
54 public:
55 	AnimationDecoder(const Common::String &fileName);
56 	AnimationDecoder(const Common::String &fileName, const Graphics::Surface &outSurface);
57 	~AnimationDecoder();
58 	bool decode(AnimationDecoderCallback *callback);
59 
60 	/**
61 	 * Enables partial decoding mode.
62 	 *
63 	 * @param fromFrame Frame to start decoding on (inclusive).
64 	 * @param toFrame Frame to end decoding on (inclusive).
65 	 * @param area Output surface will be confined to this area.
66 	 * @param threshold Source pixels with color index above this threshold will not be replaced.
67 	 */
68 	void setPartialMode(int fromFrame, int toFrame, const Common::Rect area = Common::Rect(), uint8 threshold = 0xFF);
69 
70 private:
71 	void loadPalette(Common::SeekableReadStream &stream);
72 	void loadFullFrame(EncryptedFile &file, uint32 size);
73 	void loadDiffFrame(EncryptedFile &file, uint32 size);
74 
75 	Common::String _fileName;
76 	Graphics::Surface _surface;
77 	bool _owningSurface;
78 	byte _palette[PALETTE_SIZE];
79 	int _fromFrame;
80 	int _toFrame;
81 	Common::Rect _area;
82 	uint8 _threshold;
83 };
84 
85 }
86 
87 #endif
88