| 1 | /* |
| 2 | * OpenTyrian: A modern cross-platform port of Tyrian |
| 3 | * Copyright (C) 2007-2009 The OpenTyrian Development Team |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #include "pcxload.h" |
| 20 | |
| 21 | #include "file.h" |
| 22 | #include "opentyr.h" |
| 23 | #include "palette.h" |
| 24 | #include "video.h" |
| 25 | |
| 26 | #include <string.h> |
| 27 | |
| 28 | void JE_loadPCX(const char *file) // this is only meant to load tshp2.pcx |
| 29 | { |
| 30 | Uint8 *s = VGAScreen->pixels; /* 8-bit specific */ |
| 31 | |
| 32 | FILE *f = dir_fopen_die(data_dir(), file, "rb"); |
| 33 | |
| 34 | fseek(f, -769, SEEK_END); |
| 35 | |
| 36 | Uint8 temp; |
| 37 | fread_u8_die(&temp, 1, f); |
| 38 | if (temp == 12) |
| 39 | { |
| 40 | for (int i = 0; i < 256; i++) |
| 41 | { |
| 42 | Uint8 rgb[3]; |
| 43 | fread_u8_die(rgb, 3, f); |
| 44 | colors[i].r = rgb[0]; |
| 45 | colors[i].g = rgb[1]; |
| 46 | colors[i].b = rgb[2]; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | fseek(f, 128, SEEK_SET); |
| 51 | |
| 52 | for (int i = 0; i < 320 * 200; ) |
| 53 | { |
| 54 | Uint8 p; |
| 55 | fread_u8_die(&p, 1, f); |
| 56 | if ((p & 0xc0) == 0xc0) |
| 57 | { |
| 58 | i += (p & 0x3f); |
| 59 | fread_u8_die(&temp, 1, f); |
| 60 | memset(s, temp, (p & 0x3f)); |
| 61 | s += (p & 0x3f); |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | i++; |
| 66 | *s = p; |
| 67 | s++; |
| 68 | } |
| 69 | if (i && (i % 320 == 0)) |
| 70 | { |
| 71 | s += VGAScreen->pitch - 320; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | fclose(f); |
| 76 | } |