Load image pixels for 8-bit RLE compressed dib @param io FreeImage IO @param handle FreeImage IO handle @param width Image width @param height Image height @param dib Image to be loaded @return Returns TRUE if successful, returns FALSE otherwise */
| 348 | @return Returns TRUE if successful, returns FALSE otherwise |
| 349 | */ |
| 350 | static BOOL |
| 351 | LoadPixelDataRLE8(FreeImageIO *io, fi_handle handle, int width, int height, FIBITMAP *dib) { |
| 352 | BYTE status_byte = 0; |
| 353 | BYTE second_byte = 0; |
| 354 | int scanline = 0; |
| 355 | int bits = 0; |
| 356 | |
| 357 | for (;;) { |
| 358 | if( io->read_proc(&status_byte, sizeof(BYTE), 1, handle) != 1) { |
| 359 | return FALSE; |
| 360 | } |
| 361 | |
| 362 | switch (status_byte) { |
| 363 | case RLE_COMMAND : |
| 364 | if(io->read_proc(&status_byte, sizeof(BYTE), 1, handle) != 1) { |
| 365 | return FALSE; |
| 366 | } |
| 367 | |
| 368 | switch (status_byte) { |
| 369 | case RLE_ENDOFLINE : |
| 370 | bits = 0; |
| 371 | scanline++; |
| 372 | break; |
| 373 | |
| 374 | case RLE_ENDOFBITMAP : |
| 375 | return TRUE; |
| 376 | |
| 377 | case RLE_DELTA : |
| 378 | { |
| 379 | // read the delta values |
| 380 | |
| 381 | BYTE delta_x = 0; |
| 382 | BYTE delta_y = 0; |
| 383 | |
| 384 | if(io->read_proc(&delta_x, sizeof(BYTE), 1, handle) != 1) { |
| 385 | return FALSE; |
| 386 | } |
| 387 | if(io->read_proc(&delta_y, sizeof(BYTE), 1, handle) != 1) { |
| 388 | return FALSE; |
| 389 | } |
| 390 | |
| 391 | // apply them |
| 392 | |
| 393 | bits += delta_x; |
| 394 | scanline += delta_y; |
| 395 | |
| 396 | break; |
| 397 | } |
| 398 | |
| 399 | default : |
| 400 | { |
| 401 | if(scanline >= abs(height)) { |
| 402 | return TRUE; |
| 403 | } |
| 404 | |
| 405 | int count = MIN((int)status_byte, width - bits); |
| 406 | |
| 407 | BYTE *sline = FreeImage_GetScanLine(dib, scanline); |
no test coverage detected