* Loads the contents of a TFTD BDY image file into * the surface. BDY files are compressed with a custom * algorithm. * @param filename Filename of the BDY image. * @sa http://www.ufopaedia.org/index.php?title=Image_Formats#BDY */
| 332 | * @sa http://www.ufopaedia.org/index.php?title=Image_Formats#BDY |
| 333 | */ |
| 334 | void Surface::loadBdy(const std::string &filename) |
| 335 | { |
| 336 | // Load file and put pixels in surface |
| 337 | std::ifstream imgFile (filename.c_str(), std::ios::in | std::ios::binary); |
| 338 | if (!imgFile) |
| 339 | { |
| 340 | throw Exception(filename + " not found"); |
| 341 | } |
| 342 | |
| 343 | // Lock the surface |
| 344 | lock(); |
| 345 | |
| 346 | Uint8 dataByte; |
| 347 | int pixelCnt; |
| 348 | int x = 0, y = 0; |
| 349 | int currentRow = 0; |
| 350 | |
| 351 | while (imgFile.read((char*)&dataByte, sizeof(dataByte))) |
| 352 | { |
| 353 | if (dataByte >= 129) |
| 354 | { |
| 355 | pixelCnt = 257 - (int)dataByte; |
| 356 | imgFile.read((char*)&dataByte, sizeof(dataByte)); |
| 357 | currentRow = y; |
| 358 | for (int i = 0; i < pixelCnt; ++i) |
| 359 | { |
| 360 | if (currentRow == y) // avoid overscan into next row |
| 361 | setPixelIterative(&x, &y, dataByte); |
| 362 | } |
| 363 | } |
| 364 | else |
| 365 | { |
| 366 | pixelCnt = 1 + (int)dataByte; |
| 367 | currentRow = y; |
| 368 | for (int i = 0; i < pixelCnt; ++i) |
| 369 | { |
| 370 | imgFile.read((char*)&dataByte, sizeof(dataByte)); |
| 371 | if (currentRow == y) // avoid overscan into next row |
| 372 | setPixelIterative(&x, &y, dataByte); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | // Unlock the surface |
| 378 | unlock(); |
| 379 | |
| 380 | imgFile.close(); |
| 381 | } |
| 382 | |
| 383 | |
| 384 | /** |