ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 #include "graphics/palette.h"
29 
30 #include "image/codecs/codec.h"
31 
32 namespace Common {
33 class SeekableReadStream;
34 }
35 
36 namespace Image {
37 
39  // These are not in the normal YUV colorspace, but in the Cinepak YUV colorspace instead.
40  byte y[4]; // [0, 255]
41  int8 u, v; // [-128, 127]
42 };
43 
44 struct CinepakStrip {
45  uint16 id;
46  uint16 length;
47  Common::Rect rect;
48  CinepakCodebook v1_codebook[256], v4_codebook[256];
49  uint32 v1_dither[256 * 4 * 4], v4_dither[256 * 4 * 4];
50 };
51 
52 struct CinepakFrame {
53  byte flags;
54  uint32 length;
55  uint16 width;
56  uint16 height;
57  uint16 stripCount;
58  CinepakStrip *strips;
59 
60  Graphics::Surface *surface;
61 };
62 
71 class CinepakDecoder : public Codec {
72 public:
73  CinepakDecoder(int bitsPerPixel = 24);
74  ~CinepakDecoder() override;
75 
76  const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
77  Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
78  bool setOutputPixelFormat(const Graphics::PixelFormat &format) override;
79 
80  bool containsPalette() const override { return _ditherPalette != 0; }
81  const byte *getPalette() override { _dirtyPalette = false; return _ditherPalette.data(); }
82  bool hasDirtyPalette() const override { return _dirtyPalette; }
83  bool canDither(DitherType type) const override;
84  void setDither(DitherType type, const byte *palette) override;
85 
86 private:
87  CinepakFrame _curFrame;
88  int32 _y;
89  int _bitsPerPixel;
90  Graphics::PixelFormat _pixelFormat;
91  byte *_clipTable, *_clipTableBuf;
92 
93  Graphics::Palette _ditherPalette;
94  bool _dirtyPalette;
95  byte *_colorMap;
96  DitherType _ditherType;
97 
98  void initializeCodebook(uint16 strip, byte codebookType);
99  void loadCodebook(Common::SeekableReadStream &stream, uint16 strip, byte codebookType, byte chunkID, uint32 chunkSize);
100  void decodeVectors8(Common::SeekableReadStream &stream, uint16 strip, byte chunkID, uint32 chunkSize);
101  void decodeVectors24(Common::SeekableReadStream &stream, uint16 strip, byte chunkID, uint32 chunkSize);
102 
103  byte findNearestRGB(int index) const;
104  void ditherVectors(Common::SeekableReadStream &stream, uint16 strip, byte chunkID, uint32 chunkSize);
105  void ditherCodebookQT(uint16 strip, byte codebookType, uint16 codebookIndex);
106  void ditherCodebookVFW(uint16 strip, byte codebookType, uint16 codebookIndex);
107 };
108 
109 } // End of namespace Image
110 
111 #endif
Definition: cinepak.h:38
Definition: surface.h:67
bool hasDirtyPalette() const override
Definition: cinepak.h:82
Definition: pixelformat.h:138
Definition: rect.h:144
Definition: stream.h:745
Definition: codec.h:57
Definition: cinepak.h:52
bool containsPalette() const override
Definition: cinepak.h:80
Graphics::PixelFormat getPixelFormat() const override
Definition: cinepak.h:77
Definition: algorithm.h:29
const byte * getPalette() override
Definition: cinepak.h:81
Definition: cinepak.h:44
Definition: cinepak.h:71
Simple class for handling a palette data.
Definition: palette.h:51
DitherType
Definition: codec.h:65
Definition: movie_decoder.h:32