LoadPCX
(String filename, byte[] palette, cinematics_t cin)
| 1373 | * LoadPCX |
| 1374 | */ |
| 1375 | private static int LoadPCX(String filename, byte[] palette, cinematics_t cin) { |
| 1376 | qfiles.pcx_t pcx; |
| 1377 | |
| 1378 | // load the file |
| 1379 | ByteBuffer raw = FS.LoadMappedFile(filename); |
| 1380 | |
| 1381 | if (raw == null) { |
| 1382 | Com.Printf(Defines.PRINT_DEVELOPER, "Bad pcx file " + filename |
| 1383 | + '\n'); |
| 1384 | return 0; |
| 1385 | } |
| 1386 | |
| 1387 | // parse the PCX file |
| 1388 | pcx = new qfiles.pcx_t(raw); |
| 1389 | |
| 1390 | if (pcx.manufacturer != 0x0a || pcx.version != 5 || pcx.encoding != 1 |
| 1391 | || pcx.bits_per_pixel != 8 || pcx.xmax >= 640 |
| 1392 | || pcx.ymax >= 480) { |
| 1393 | |
| 1394 | Com.Printf(Defines.PRINT_ALL, "Bad pcx file " + filename + '\n'); |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | int width = pcx.xmax - pcx.xmin + 1; |
| 1399 | int height = pcx.ymax - pcx.ymin + 1; |
| 1400 | |
| 1401 | byte[] pix = new byte[width * height]; |
| 1402 | |
| 1403 | if (palette != null) { |
| 1404 | raw.position(raw.limit() - 768); |
| 1405 | raw.get(palette); |
| 1406 | } |
| 1407 | |
| 1408 | if (cin != null) { |
| 1409 | cin.pic = pix; |
| 1410 | cin.width = width; |
| 1411 | cin.height = height; |
| 1412 | } |
| 1413 | |
| 1414 | // |
| 1415 | // decode pcx |
| 1416 | // |
| 1417 | int count = 0; |
| 1418 | byte dataByte = 0; |
| 1419 | int runLength = 0; |
| 1420 | int x, y; |
| 1421 | |
| 1422 | // simple counter for buffer indexing |
| 1423 | int p = 0; |
| 1424 | |
| 1425 | for (y = 0; y < height; y++) { |
| 1426 | for (x = 0; x < width;) { |
| 1427 | |
| 1428 | dataByte = pcx.data.get(p++); |
| 1429 | |
| 1430 | if ((dataByte & 0xC0) == 0xC0) { |
| 1431 | runLength = dataByte & 0x3F; |
| 1432 | dataByte = pcx.data.get(p++); |
no test coverage detected