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 IMAGE_CODECS_XAN_H
24 #define IMAGE_CODECS_XAN_H
25 
26 #include "image/codecs/codec.h"
27 
28 namespace Image {
29 
30 /**
31  * Xan image decoder. (fourcc Xxan)
32  *
33  * Used by Crusader: No Regret AVI files
34  *
35  * This code was created based on the multimedia wiki:
36  * https://wiki.multimedia.cx/index.php/Origin_Xan_Codec
37  * and ffmpeg's libavcodec/xxan.c.
38  * The ffmpeg code is LGPL2 licensed and Copyright (C) 2011
39  * Konstantin Shishkov based on work by Mike Melanson.
40  *
41  * A similar format is used in Wing Commander III (although not in an AVI
42  * container) and IV.
43  */
44 class XanDecoder : public Codec {
45 public:
46 	XanDecoder (int width, int height, int bitsPerPixel);
47 	~XanDecoder();
48 
49 	const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
50 	Graphics::PixelFormat getPixelFormat() const override;
51 
52 private:
53 	void decodeFrameType0(Common::SeekableReadStream &stream);
54 	void decodeFrameType1(Common::SeekableReadStream &stream);
55 
56 	/** Decompress the huffman table for base luma data */
57 	void decompressLuma(Common::SeekableReadStream &stream);
58 
59 	bool decodeChroma(Common::SeekableReadStream &stream, int chroma_off);
60 
61 	/** convert the internally expanded YUV to the output RGBA surface */
62 	void convertYUVtoRGBSurface();
63 
64 	/** A buffer to hold the final frame in RGBA */
65 	Graphics::Surface _surface;
66 
67 	/** Dest surface width and height */
68 	int _width, _height;
69 
70 	/** If true, decode chroma vals in Wing Commander 4 style (false = No Regret style) */
71 	bool _wc4Mode;
72 
73 	/** A buffer to hold scratch data.  Either chroma data in progress, or
74 	 * decompressed delta luma values (5-bit).  Interpretation depends on frame type. */
75 	uint8 *_scratchbuf;
76 	/** A buffer to hold expanded/interpolated absolute luma values (6-bit) from the values in _scratchbuf.
77 	 * These still need to be multiplied out to make 8-bit values. */
78 	uint8 *_lumabuf;
79 	/** a buffer for uncompressed and multiplied out "y" values (of yuv) */
80 	uint8 *_ybuf;
81 	/** a buffer for uncompressed "u" values (of yuv) */
82 	uint8 *_ubuf;
83 	/** a buffer for uncompressed "v" values (of yuv) */
84 	uint8 *_vbuf;
85 };
86 
87 } // End of namespace Image
88 
89 #endif
90