ScummVM API documentation
sequence.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 LASTEXPRESS_SEQUENCE_H
23 #define LASTEXPRESS_SEQUENCE_H
24 
25 /*
26  Sequence format (.SEQ / .NIS (frame header & data only))
27 
28  uint32 {4} - Number of frames in sequence
29  uint32 {4} - Unknown
30 
31  frames headers (68 bytes):
32  // for each frame
33  uint32 {4} - Data offset (from beginning of file)
34  uint32 {4} - Unknown
35  uint32 {4} - Palette offset (from beginning of file)
36  uint32 {4} - Top-left X coordinate
37  uint32 {4} - Top-left Y coordinate
38  uint32 {4} - Bottom-right X coordinate
39  uint32 {4} - Bottom-right Y coordinate
40  uint32 {4} - Initial offset of decompressed data (doubled, since each pixel occupies one color word)
41  uint32 {4} - End of data after decompression
42 
43  (for SEQ files only)
44  uint16 {2} - Hotspot left
45  uint16 {2} - Hotspot right
46  uint16 {2} - Hotspot top
47  uint16 {2} - Hotspot bottom
48  byte {1} - Compression type
49  byte {1} - Subtype (determines which set of decompression functions will be called) => 0, 1, 2, 3
50  byte {1} - Unknown
51  byte {1} - Keep previous frame while drawing
52  byte {1} - Unknown
53  byte {1} - Unknown
54  byte {1} - Sound action
55  byte {1} - Unknown
56  uint32 {4} - positionId
57  uint32 {4} - Unknown
58  uint16 {2} - Entity Position
59  uint16 {2} - Location (~z-order)
60  uint32 {4} - Next sequence in the linked list
61 
62  (for NIS files: found at 0x124)
63  byte {1} - Compression type
64 
65  palette data:
66  uint16 {x} - palette data (max size: 256)
67 
68  data
69  byte {x} - compressed image data
70 */
71 
72 #include "lastexpress/drawable.h"
73 
74 #include "lastexpress/shared.h"
75 
76 #include "common/array.h"
77 #include "common/rect.h"
78 #include "common/str.h"
79 
80 namespace Common {
81 class SeekableReadStream;
82 }
83 
84 namespace LastExpress {
85 
86 enum FrameSubType {
87  kFrameTypeNone = 0,
88  kFrameType1 = 1,
89  kFrameType2 = 2,
90  kFrameType3 = 3
91 };
92 
93 struct FrameInfo {
94  void read(Common::SeekableReadStream *in, bool isSequence);
95 
96  uint32 dataOffset;
97  uint32 unknown;
98  uint32 paletteOffset;
99  uint32 xPos1;
100  uint32 yPos1;
101  uint32 xPos2;
102  uint32 yPos2;
103  uint32 initialSkip;
105 
106  // NIS frame headers end here. SEQ frame headers have additional 32 bytes of
107  // data, notably the compression type at the position outlined above in
108  // CompPos_SEQ
109 
110  Common::Rect hotspot;
111 
113  FrameSubType subType;
114 
115  byte field_2E;
116  byte keepPreviousFrame;
117  byte field_30;
118  byte field_31;
119  byte soundAction;
120  byte field_33;
121  Position position;
122  byte field_35;
123  int16 field_36;
124  uint32 field_38;
125  EntityPosition entityPosition;
126  uint16 location;
127  uint32 next;
128 };
129 
130 class AnimFrame : public Drawable {
131 public:
132  AnimFrame(Common::SeekableReadStream *in, const FrameInfo &f, bool ignoreSubtype = false);
133  ~AnimFrame() override;
134  Common::Rect draw(Graphics::Surface *s) override;
135 
136 private:
137  void decomp3(Common::SeekableReadStream *in, const FrameInfo &f);
138  void decomp4(Common::SeekableReadStream *in, const FrameInfo &f);
139  void decomp34(Common::SeekableReadStream *in, const FrameInfo &f, byte mask, byte shift);
140  void decomp5(Common::SeekableReadStream *in, const FrameInfo &f);
141  void decomp7(Common::SeekableReadStream *in, const FrameInfo &f);
142  void decompFF(Common::SeekableReadStream *in, const FrameInfo &f);
143  void readPalette(Common::SeekableReadStream *in, const FrameInfo &f);
144 
145  Graphics::Surface _image;
146  uint16 _palSize;
147  uint16 *_palette;
148  Common::Rect _rect;
149 };
150 
151 class Sequence {
152 public:
153  Sequence(Common::String name) : _stream(NULL), _isLoaded(false), _name(name), _field30(15) {}
154  ~Sequence();
155 
156  static Sequence *load(Common::String name, Common::SeekableReadStream *stream = NULL, byte field30 = 15);
157 
158  bool load(Common::SeekableReadStream *stream, byte field30 = 15);
159 
160  uint16 count() const { return (uint16)_frames.size(); }
161  AnimFrame *getFrame(uint16 index = 0);
162  FrameInfo *getFrameInfo(uint16 index = 0);
163 
164  Common::String getName() { return _name; }
165  byte getField30() { return _field30; }
166 
167  bool isLoaded() { return _isLoaded; }
168 
169 private:
170  static const uint32 _sequenceHeaderSize = 8;
171  static const uint32 _sequenceFrameSize = 68;
172 
173  void reset();
174 
175  Common::Array<FrameInfo> _frames;
177  bool _isLoaded;
178 
179  Common::String _name;
180  byte _field30; // used when copying sequences
181 };
182 
183 class SequenceFrame : public Drawable {
184 public:
185  SequenceFrame(Sequence *sequence, uint16 frame = 0, bool dispose = false) : _sequence(sequence), _frame(frame), _dispose(dispose) {}
186  ~SequenceFrame() override;
187 
188  Common::Rect draw(Graphics::Surface *surface) override;
189 
190  bool setFrame(uint16 frame);
191  uint32 getFrame() { return _frame; }
192  bool nextFrame();
193 
194  Common::String getName();
195  FrameInfo *getInfo();
196 
197  bool equal(const SequenceFrame *other) const;
198 
199 private:
200  Sequence *_sequence;
201  uint16 _frame;
202  bool _dispose;
203 };
204 
205 } // End of namespace LastExpress
206 
207 #endif // LASTEXPRESS_SEQUENCE_H
Definition: sequence.h:93
Definition: str.h:59
FrameSubType subType
Subtype (byte)
Definition: sequence.h:113
Definition: surface.h:67
uint32 xPos2
Bottom-right X coordinate.
Definition: sequence.h:101
byte compressionType
Type of frame compression (0x03, 0x04, 0x05, 0x07, 0xFF)
Definition: sequence.h:112
Definition: array.h:52
uint32 unknown
FIXME: unknown data.
Definition: sequence.h:97
Definition: sequence.h:130
Definition: rect.h:144
uint32 decompressedEndOffset
End of data after decompression.
Definition: sequence.h:104
Definition: stream.h:745
Definition: animation.h:45
uint32 xPos1
Top-left X coordinate.
Definition: sequence.h:99
Definition: drawable.h:29
uint32 dataOffset
Data offset (from beginning of file)
Definition: sequence.h:96
Definition: sequence.h:151
Definition: algorithm.h:29
uint32 initialSkip
Initial on-screen offset of decompressed data (doubled, since each pixel occupies one color word) ...
Definition: sequence.h:103
Definition: sequence.h:183
uint32 paletteOffset
Palette offset (from beginning of file)
Definition: sequence.h:98
uint32 yPos2
Bottom-right Y coordinate.
Definition: sequence.h:102
uint32 yPos1
Top-left Y coordinate.
Definition: sequence.h:100