(String filename, byte[][] palette, Dimension dim)
| 435 | ============== |
| 436 | */ |
| 437 | byte[] LoadPCX(String filename, byte[][] palette, Dimension dim) { |
| 438 | qfiles.pcx_t pcx; |
| 439 | |
| 440 | // |
| 441 | // load the file |
| 442 | // |
| 443 | byte[] raw = FS.LoadFile(filename); |
| 444 | |
| 445 | if (raw == null) { |
| 446 | Com.Printf(Defines.PRINT_DEVELOPER, "Bad pcx file " + filename + '\n'); |
| 447 | return null; |
| 448 | } |
| 449 | |
| 450 | // |
| 451 | // parse the PCX file |
| 452 | // |
| 453 | pcx = new qfiles.pcx_t(raw); |
| 454 | |
| 455 | if (pcx.manufacturer != 0x0a |
| 456 | || pcx.version != 5 |
| 457 | || pcx.encoding != 1 |
| 458 | || pcx.bits_per_pixel != 8 |
| 459 | || pcx.xmax >= 640 |
| 460 | || pcx.ymax >= 480) { |
| 461 | |
| 462 | Com.Printf(Defines.PRINT_ALL, "Bad pcx file " + filename + '\n'); |
| 463 | return null; |
| 464 | } |
| 465 | |
| 466 | int width = pcx.xmax - pcx.xmin + 1; |
| 467 | int height = pcx.ymax - pcx.ymin + 1; |
| 468 | |
| 469 | byte[] pix = new byte[width * height]; |
| 470 | |
| 471 | if (palette != null) { |
| 472 | palette[0] = new byte[768]; |
| 473 | System.arraycopy(raw, raw.length - 768, palette[0], 0, 768); |
| 474 | } |
| 475 | |
| 476 | if (dim != null) { |
| 477 | dim.width = width; |
| 478 | dim.height = height; |
| 479 | } |
| 480 | |
| 481 | // |
| 482 | // decode pcx |
| 483 | // |
| 484 | int count = 0; |
| 485 | byte dataByte = 0; |
| 486 | int runLength = 0; |
| 487 | int x, y; |
| 488 | |
| 489 | for (y = 0; y < height; y++) { |
| 490 | for (x = 0; x < width;) { |
| 491 | |
| 492 | dataByte = pcx.data.get(); |
| 493 | |
| 494 | if ((dataByte & 0xC0) == 0xC0) { |
no test coverage detected