MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / WSA_LoadFile

Function WSA_LoadFile

src/wsa.c:192–321  ·  view source on GitHub ↗

* Load a WSA file. * @param filename Name of the file. * @param wsa Data buffer for the WSA. * @param wsaSize Current size of buffer. * @param reserveDisplayFrame True if we need to reserve the display frame. * @return Address of loaded WSA file, or NULL. */

Source from the content-addressed store, hash-verified

190 * @return Address of loaded WSA file, or NULL.
191 */
192void *WSA_LoadFile(const char *filename, void *wsa, uint32 wsaSize, bool reserveDisplayFrame)
193{
194 WSAFlags flags;
195 WSAFileHeader fileheader;
196 WSAHeader *header;
197 uint32 bufferSizeMinimal;
198 uint32 bufferSizeOptimal;
199 uint16 lengthHeader;
200 uint8 fileno;
201 uint16 lengthPalette;
202 uint16 lengthFirstFrame;
203 uint32 lengthFileContent;
204 uint32 displaySize;
205 uint8 *buffer;
206
207 memset(&flags, 0, sizeof(flags));
208
209 fileno = File_Open(filename, FILE_MODE_READ);
210 fileheader.frames = File_Read_LE16(fileno);
211 fileheader.width = File_Read_LE16(fileno);
212 fileheader.height = File_Read_LE16(fileno);
213 fileheader.requiredBufferSize = File_Read_LE16(fileno);
214 fileheader.hasPalette = File_Read_LE16(fileno); /* has palette */
215 fileheader.firstFrameOffset = File_Read_LE32(fileno); /* Offset of 1st frame */
216 fileheader.secondFrameOffset = File_Read_LE32(fileno); /* Offset of 2nd frame (end of 1st frame) */
217
218 lengthPalette = 0;
219 if (fileheader.hasPalette) {
220 flags.hasPalette = true;
221
222 lengthPalette = 0x300; /* length of a 256 color RGB palette */
223 }
224
225 lengthFileContent = File_Seek(fileno, 0, 2);
226
227 lengthFirstFrame = 0;
228 if (fileheader.firstFrameOffset != 0) {
229 lengthFirstFrame = fileheader.secondFrameOffset - fileheader.firstFrameOffset;
230 } else {
231 flags.hasNoFirstFrame = true; /* is the continuation of another WSA */
232 }
233
234 lengthFileContent -= lengthPalette + lengthFirstFrame + 10;
235
236 displaySize = 0;
237 if (reserveDisplayFrame) {
238 flags.displayInBuffer = true;
239 displaySize = fileheader.width * fileheader.height;
240 }
241
242 bufferSizeMinimal = displaySize + fileheader.requiredBufferSize - 33 + sizeof(WSAHeader);
243 bufferSizeOptimal = bufferSizeMinimal + lengthFileContent;
244
245 if (wsaSize > 1 && wsaSize < bufferSizeMinimal) {
246 File_Close(fileno);
247
248 return NULL;
249 }

Callers 9

House_UpdateRadarStateFunction · 0.85
GameLoop_PlayAnimationFunction · 0.85
Gameloop_LogosFunction · 0.85
GUI_FactoryWindow_InitFunction · 0.85
GUI_Mentat_ShowFunction · 0.85
GUI_Mentat_DisplayFunction · 0.85
GUI_Mentat_LoopFunction · 0.85
GUI_Security_ShowFunction · 0.85

Calls 8

File_Read_LE16Function · 0.85
File_Read_LE32Function · 0.85
File_SeekFunction · 0.85
File_CloseFunction · 0.85
File_ReadFunction · 0.85
Format80_DecodeFunction · 0.85

Tested by

no test coverage detected