| 1 | /* |
| 2 | Copyright (C) 2000 Marco Ziech |
| 3 | Copyright (C) 2000 Ross Combs ([email protected]) |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | #ifndef INCLUDED_TGA_H |
| 20 | #define INCLUDED_TGA_H |
| 21 | |
| 22 | #include <cstdint> |
| 23 | #include <cstdio> |
| 24 | |
| 25 | |
| 26 | namespace pvpgn |
| 27 | { |
| 28 | |
| 29 | namespace bni |
| 30 | { |
| 31 | |
| 32 | typedef struct |
| 33 | { |
| 34 | std::uint8_t idlen; /* number of bytes in Field 6: 0==no id */ |
| 35 | std::uint8_t cmaptype; /* colormap: 0==none, 1==included, <128==TrueVision, >=128==developer */ |
| 36 | std::uint8_t imgtype; /* pixel format: <128==TrueVision, >=128==developer */ |
| 37 | std::uint16_t cmapfirst; /* first entry offset */ |
| 38 | std::uint16_t cmaplen; /* number of colormap entries */ |
| 39 | std::uint8_t cmapes; /* size of a single colormap entry in bits, 15 forces 1 attribute bit, 32 forces 8 */ |
| 40 | std::uint16_t xorigin; /* x coordinate of lower left hand corner with origin at left of screen */ |
| 41 | std::uint16_t yorigin; /* y coordinate of lower left hand corner with origin at bottom of screen */ |
| 42 | std::uint16_t width; /* width in pixels */ |
| 43 | std::uint16_t height; /* height in pixels */ |
| 44 | std::uint8_t bpp; /* bits per pixel, including attributes and alpha channel */ |
| 45 | std::uint8_t desc; /* image descriptor: bits 0,1,2,3==num attribute bits per pixel, bit 4==horizontal order, bit 5==vertical order, bits 6,7==interleaving */ |
| 46 | /* field 6, optional */ |
| 47 | /* field 7, colormap data in ARGB, optional, entries are (min(cmapes/3,8)*3+7)/8 bits wide */ |
| 48 | std::uint8_t* data; |
| 49 | /* field 9, developer area, optional */ |
| 50 | /* field 10, extension area, optional */ |
| 51 | std::uint32_t extareaoff; /* extension area offset, 0==none */ |
| 52 | std::uint32_t devareaoff; /* developer area offset, 0==none */ |
| 53 | /* magic, null terminated */ |
| 54 | } t_tgaimg; |
| 55 | |
| 56 | typedef enum |
| 57 | { |
| 58 | tgaimgtype_empty = 0, |
| 59 | tgaimgtype_uncompressed_mapped = 1, |
| 60 | tgaimgtype_uncompressed_truecolor = 2, |
| 61 | tgaimgtype_uncompressed_monochrome = 3, |
| 62 | tgaimgtype_rlecompressed_mapped = 9, |
| 63 | tgaimgtype_rlecompressed_truecolor = 10, |
| 64 | tgaimgtype_rlecompressed_monochrome = 11, |
| 65 | tgaimgtype_huffman_mapped = 32, |
| 66 | tgaimgtype_huffman_4pass_mapped = 33 |
| 67 | } t_tgaimgtype; |
| 68 | |
| 69 | typedef enum { |
| 70 | tgadesc_attrbits0 = 1, |
| 71 | tgadesc_attrbits1 = 2, |
| 72 | tgadesc_attrbits2 = 4, |
| 73 | tgadesc_attrbits3 = 8, |
| 74 | tgadesc_horz = 16, |
| 75 | tgadesc_vert = 32, |
| 76 | tgadesc_interleave1 = 64, |
| 77 | tgadesc_interleave2 = 128 |
| 78 | } t_tgadesc; |
| 79 | |
| 80 | typedef enum { |
| 81 | tgacmap_none = 0, |
| 82 | tgacmap_included = 1 |
| 83 | } t_tgacmap; |
| 84 | |
| 85 | typedef enum { |
| 86 | RLE, |
| 87 | RAW |
| 88 | } t_tgapkttype; |
| 89 | |
| 90 | /* "new" style TGA allowing for developer and extension areas must have this magic at |
| 91 | the end of the file */ |
| 92 | #define TGAMAGIC "TRUEVISION-XFILE." |
| 93 | |
| 94 | extern t_tgaimg * new_tgaimg(unsigned int width, unsigned int height, unsigned int bpp, t_tgaimgtype imgtype); |
| 95 | extern int getpixelsize(t_tgaimg const *img); |
| 96 | extern t_tgaimg * load_tgaheader(void); |
| 97 | extern t_tgaimg * load_tga(std::FILE *f); |
| 98 | extern int write_tga(std::FILE *f, t_tgaimg *img); |
| 99 | extern void destroy_img(t_tgaimg * img); |
| 100 | extern void print_tga_info(t_tgaimg const * img, std::FILE * fp); |
| 101 | |
| 102 | } |
| 103 | |
| 104 | } |
| 105 | #endif |
| 106 |