MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / loadSpk

Method loadSpk

src/Engine/Surface.cpp:278–325  ·  view source on GitHub ↗

* Loads the contents of an X-Com SPK image file into * the surface. SPK files are compressed with a custom * algorithm since they're usually full-screen images. * @param filename Filename of the SPK image. * @sa http://www.ufopaedia.org/index.php?title=Image_Formats#SPK */

Source from the content-addressed store, hash-verified

276 * @sa http://www.ufopaedia.org/index.php?title=Image_Formats#SPK
277 */
278void Surface::loadSpk(const std::string &filename)
279{
280 // Load file and put pixels in surface
281 std::ifstream imgFile (filename.c_str(), std::ios::in | std::ios::binary);
282 if (!imgFile)
283 {
284 throw Exception(filename + " not found");
285 }
286
287 // Lock the surface
288 lock();
289
290 Uint16 flag;
291 Uint8 value;
292 int x = 0, y = 0;
293
294 while (imgFile.read((char*)&flag, sizeof(flag)))
295 {
296 flag = SDL_SwapLE16(flag);
297
298 if (flag == 65535)
299 {
300 imgFile.read((char*)&flag, sizeof(flag));
301 flag = SDL_SwapLE16(flag);
302
303 for (int i = 0; i < flag * 2; ++i)
304 {
305 setPixelIterative(&x, &y, 0);
306 }
307 }
308 else if (flag == 65534)
309 {
310 imgFile.read((char*)&flag, sizeof(flag));
311 flag = SDL_SwapLE16(flag);
312
313 for (int i = 0; i < flag * 2; ++i)
314 {
315 imgFile.read((char*)&value, 1);
316 setPixelIterative(&x, &y, value);
317 }
318 }
319 }
320
321 // Unlock the surface
322 unlock();
323
324 imgFile.close();
325}
326
327/**
328 * Loads the contents of a TFTD BDY image file into

Callers 2

XcomResourcePackMethod · 0.80

Calls 2

ExceptionClass · 0.85
closeMethod · 0.45

Tested by

no test coverage detected