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 #include "gnap/gnap.h"
24 #include "gnap/resource.h"
25 
26 namespace Gnap {
27 
28 // SequenceFrame
29 
loadFromStream(Common::MemoryReadStream & stream)30 void SequenceFrame::loadFromStream(Common::MemoryReadStream &stream) {
31 	_duration = stream.readUint16LE();
32 	_isScaled = (stream.readUint16LE() != 0);
33 	_rect.left = stream.readUint32LE();
34 	_rect.top = stream.readUint32LE();
35 	_rect.right = stream.readUint32LE();
36 	_rect.bottom = stream.readUint32LE();
37 	_spriteId = stream.readUint32LE();
38 	_soundId = stream.readUint32LE();
39 
40 	// Skip an unused value
41 	stream.readUint32LE();
42 
43 	debugC(kDebugBasic, "SequenceFrame() spriteId: %d; soundId: %d", _spriteId, _soundId);
44 }
45 
46 // SequenceAnimation
47 
loadFromStream(Common::MemoryReadStream & stream)48 void SequenceAnimation::loadFromStream(Common::MemoryReadStream &stream) {
49 	// Skip two unused values
50 	stream.readUint32LE();
51 
52 	_additionalDelay = stream.readUint32LE();
53 	_framesCount = stream.readUint16LE();
54 	_maxTotalDuration = stream.readUint16LE();
55 	debugC(kDebugBasic, "SequenceAnimation() framesCount: %d", _framesCount);
56 	frames = new SequenceFrame[_framesCount];
57 	for (int i = 0; i < _framesCount; ++i)
58 		frames[i].loadFromStream(stream);
59 }
60 
61 // SequenceResource
SequenceResource(byte * data,uint32 size)62 SequenceResource::SequenceResource(byte *data, uint32 size) {
63 	Common::MemoryReadStream stream(data, size, DisposeAfterUse::NO);
64 
65 	// Skip an unused value
66 	stream.readUint32LE();
67 
68 	_sequenceId = stream.readUint32LE();
69 	_defaultId = stream.readUint32LE();
70 	_sequenceId2 = stream.readUint32LE();
71 	_defaultId2 = stream.readUint32LE();
72 	_flags = stream.readUint32LE();
73 	_totalDuration = stream.readUint32LE();
74 	_xOffs = stream.readUint16LE();
75 	_yOffs = stream.readUint16LE();
76 	_animationsCount = stream.readUint32LE();
77 	_animations = new SequenceAnimation[_animationsCount];
78 	debugC(kDebugBasic, "SequenceResource() _animationsCount: %d", _animationsCount);
79 	for (int i = 0; i < _animationsCount; ++i) {
80 		uint32 animationOffs = stream.readUint32LE();
81 		debugC(kDebugBasic, "animationOffs: %08X", animationOffs);
82 		uint32 oldOffs = stream.pos();
83 		stream.seek(animationOffs);
84 		_animations[i].loadFromStream(stream);
85 		stream.seek(oldOffs);
86 	}
87 }
88 
~SequenceResource()89 SequenceResource::~SequenceResource() {
90 	delete[] _animations;
91 }
92 
93 // SpriteResource
SpriteResource(byte * data,uint32 size)94 SpriteResource::SpriteResource(byte *data, uint32 size) {
95 	_data = data;
96 	_width = READ_LE_UINT16(_data);
97 	_height = READ_LE_UINT16(_data + 2);
98 	_unknownVal1 = READ_LE_UINT16(_data + 4);
99 	_unknownVal2 = READ_LE_UINT16(_data + 6);
100 	_transparent = (READ_LE_UINT16(_data + 8) != 0);
101 	_colorsCount = READ_LE_UINT16(_data + 10);
102 	_palette = (uint32 *)(_data + 12);
103 	_pixels = _data + 12 + _colorsCount * 4;
104 #if defined(SCUMM_BIG_ENDIAN)
105 	for (uint16 c = 0; c < _colorsCount; ++c)
106 		_palette[c] = SWAP_BYTES_32(_palette[c]);
107 #endif
108 	debugC(kDebugBasic, "SpriteResource() width: %d; height: %d; colorsCount: %d", _width, _height, _colorsCount);
109 }
110 
~SpriteResource()111 SpriteResource::~SpriteResource() {
112 	delete[] _data;
113 }
114 
115 // SoundResource
SoundResource(byte * data,uint32 size)116 SoundResource::SoundResource(byte *data, uint32 size) {
117 	_data = data;
118 	_size = size;
119 }
120 
~SoundResource()121 SoundResource::~SoundResource() {
122 	delete[] _data;
123 }
124 
125 } // End of namespace Gnap
126