ScummVM API documentation
cinepak.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef IMAGE_CODECS_CINEPAK_H
23 #define IMAGE_CODECS_CINEPAK_H
24 
25 #include "common/scummsys.h"
26 #include "common/rect.h"
27 #include "graphics/pixelformat.h"
28 
29 #include "image/codecs/codec.h"
30 
31 namespace Common {
32 class SeekableReadStream;
33 }
34 
35 namespace Image {
36 
38  // These are not in the normal YUV colorspace, but in the Cinepak YUV colorspace instead.
39  byte y[4]; // [0, 255]
40  int8 u, v; // [-128, 127]
41 };
42 
43 struct CinepakStrip {
44  uint16 id;
45  uint16 length;
46  Common::Rect rect;
47  CinepakCodebook v1_codebook[256], v4_codebook[256];
48  uint32 v1_dither[256 * 4 * 4], v4_dither[256 * 4 * 4];
49 };
50 
51 struct CinepakFrame {
52  byte flags;
53  uint32 length;
54  uint16 width;
55  uint16 height;
56  uint16 stripCount;
57  CinepakStrip *strips;
58 
59  Graphics::Surface *surface;
60 };
61 
70 class CinepakDecoder : public Codec {
71 public:
72  CinepakDecoder(int bitsPerPixel = 24);
73  ~CinepakDecoder() override;
74 
75  const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
76  Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
77  bool setOutputPixelFormat(const Graphics::PixelFormat &format) override;
78 
79  bool containsPalette() const override { return _ditherPalette != 0; }
80  const byte *getPalette() override { _dirtyPalette = false; return _ditherPalette; }
81  bool hasDirtyPalette() const override { return _dirtyPalette; }
82  bool canDither(DitherType type) const override;
83  void setDither(DitherType type, const byte *palette) override;
84 
85 private:
86  CinepakFrame _curFrame;
87  int32 _y;
88  int _bitsPerPixel;
89  Graphics::PixelFormat _pixelFormat;
90  byte *_clipTable, *_clipTableBuf;
91 
92  byte *_ditherPalette;
93  bool _dirtyPalette;
94  byte *_colorMap;
95  DitherType _ditherType;
96 
97  void initializeCodebook(uint16 strip, byte codebookType);
98  void loadCodebook(Common::SeekableReadStream &stream, uint16 strip, byte codebookType, byte chunkID, uint32 chunkSize);
99  void decodeVectors8(Common::SeekableReadStream &stream, uint16 strip, byte chunkID, uint32 chunkSize);
100  void decodeVectors24(Common::SeekableReadStream &stream, uint16 strip, byte chunkID, uint32 chunkSize);
101 
102  byte findNearestRGB(int index) const;
103  void ditherVectors(Common::SeekableReadStream &stream, uint16 strip, byte chunkID, uint32 chunkSize);
104  void ditherCodebookQT(uint16 strip, byte codebookType, uint16 codebookIndex);
105  void ditherCodebookVFW(uint16 strip, byte codebookType, uint16 codebookIndex);
106 };
107 
108 } // End of namespace Image
109 
110 #endif
Definition: cinepak.h:37
Definition: surface.h:67
bool hasDirtyPalette() const override
Definition: cinepak.h:81
Definition: pixelformat.h:138
Definition: rect.h:144
Definition: stream.h:745
Definition: codec.h:55
Definition: cinepak.h:51
bool containsPalette() const override
Definition: cinepak.h:79
Graphics::PixelFormat getPixelFormat() const override
Definition: cinepak.h:76
Definition: algorithm.h:29
const byte * getPalette() override
Definition: cinepak.h:80
Definition: cinepak.h:43
Definition: cinepak.h:70
DitherType
Definition: codec.h:63
Definition: movie_decoder.h:32