Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
dc6.h
1 #pragma once
2 
3 #include <stdint.h>
4 #include <Stream.h>
5 #include <memory>
6 #include <type_traits>
7 #include <vector>
8 #include "Palette.h"
9 
10 namespace WorldStone
11 {
12 // clang-format off
38 // clang-format on
39 class DC6
40 {
41 public:
42  enum Flags
43  {
44  IsSerialized = 1 << 0,
45  IsLoadedInHW = 1 << 1,
46  Is24Bits = 1 << 2,
47  };
48 
49  struct Header
50  {
51  int32_t version;
52  int32_t flags;
53  int32_t format;
54  uint8_t skipColor[4];
55  uint32_t directions;
56  uint32_t framesPerDir;
57  };
59  struct FrameHeader
60  {
61  int32_t flip;
62  int32_t width;
63  int32_t height;
64  int32_t offsetX;
65  int32_t offsetY;
66  int32_t allocSize;
67  int32_t nextBlock;
68  uint32_t length;
69  };
70 
71 protected:
72  StreamPtr stream = nullptr;
73  Header header;
74  std::vector<uint32_t> framePointers;
75  std::vector<FrameHeader> frameHeaders;
76 
77  bool extractHeaders();
78 
79 public:
86  bool initDecoder(StreamPtr&& streamPtr);
87 
89  void reset() { *this = DC6{}; }
90 
91  const Header& getHeader() const { return header; }
92  const std::vector<FrameHeader>& getFrameHeaders() const { return frameHeaders; }
93 
98  std::vector<uint8_t> decompressFrame(size_t frameNumber) const;
99 
102  bool decompressFrameIn(size_t frameNumber, uint8_t* data) const;
103 
104  void exportToPPM(const char* ppmFilenameBase, const Palette& palette) const;
105 };
106 } // namespace WorldStone
int32_t flip
Default (false) means scanlines are from bottom to top.
Definition: dc6.h:61
uint32_t length
Length of the frame in chunks.
Definition: dc6.h:68
Used internally by the game for 24 to 8 bits per color conversion.
Definition: dc6.h:46
std::vector< uint8_t > decompressFrame(size_t frameNumber) const
Decompress the given frame.
Definition: dc6.cpp:56
Always set for files.
Definition: dc6.h:44
int32_t width
Width in pixels.
Definition: dc6.h:62
uint8_t skipColor[4]
Skipped RGB color in D2CMP CelIteratePixels (unused in game)
Definition: dc6.h:54
int32_t nextBlock
Offset/Pointer to the next frame.
Definition: dc6.h:67
void reset()
Resets the decoder and frees resources.
Definition: dc6.h:89
bool initDecoder(StreamPtr &&streamPtr)
Start decoding the stream and preparing data.
Definition: dc6.cpp:17
uint32_t directions
Number of directions in this file.
Definition: dc6.h:55
int32_t format
Always 0 in the game files. 0=indexed 2=24bits.
Definition: dc6.h:53
int32_t allocSize
Used by the game as a slot to store the data size. 0 in the files.
Definition: dc6.h:66
int32_t offsetX
Horizontal offset for left edge of the frame.
Definition: dc6.h:64
int32_t offsetY
Vertical offset for bottom(top if flipped) edge of the frame.
Definition: dc6.h:65
Decoder for the DC6 image format.
Definition: dc6.h:39
bool decompressFrameIn(size_t frameNumber, uint8_t *data) const
Same as decompressFrame but will output the data in a given buffer.
Definition: dc6.cpp:66
int32_t version
DC6 major version, usually 6.
Definition: dc6.h:51
Used by the game to know if the file was loaded in the renderer.
Definition: dc6.h:45
uint32_t framesPerDir
Number of frames for each direction.
Definition: dc6.h:56
int32_t height
Height in pixels.
Definition: dc6.h:63
int32_t flags
DC6::Flags
Definition: dc6.h:52