File indexing completed on 2024-06-09 04:27:50
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2003 Dominik Seichter <domseichter@web.de> 0003 SPDX-FileCopyrightText: 2004 Ignacio CastaƱo <castano@ludicon.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 /* this code supports: 0009 * reading: 0010 * uncompressed and run length encoded indexed, grey and color tga files. 0011 * image types 1, 2, 3, 9, 10 and 11. 0012 * only RGB color maps with no more than 256 colors. 0013 * pixel formats 8, 15, 24 and 32. 0014 * writing: 0015 * uncompressed true color tga files 0016 */ 0017 #ifndef TGA_H 0018 #define TGA_H 0019 0020 #include <QDataStream> 0021 #include <QImage> 0022 #include <QColor> 0023 0024 // Header format of saved files. 0025 const uchar targaMagic[12] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 0026 0027 enum TGAType { 0028 TGA_TYPE_INDEXED = 1, 0029 TGA_TYPE_RGB = 2, 0030 TGA_TYPE_GREY = 3, 0031 TGA_TYPE_RLE_INDEXED = 9, 0032 TGA_TYPE_RLE_RGB = 10, 0033 TGA_TYPE_RLE_GREY = 11 0034 }; 0035 0036 #define TGA_INTERLEAVE_MASK 0xc0 0037 #define TGA_INTERLEAVE_NONE 0x00 0038 #define TGA_INTERLEAVE_2WAY 0x40 0039 #define TGA_INTERLEAVE_4WAY 0x80 0040 0041 #define TGA_ORIGIN_MASK 0x30 0042 #define TGA_ORIGIN_LEFT 0x00 0043 #define TGA_ORIGIN_RIGHT 0x10 0044 #define TGA_ORIGIN_LOWER 0x00 0045 #define TGA_ORIGIN_UPPER 0x20 0046 0047 /** Tga Header. */ 0048 struct TgaHeader { 0049 uchar id_length; 0050 uchar colormap_type; 0051 uchar image_type; 0052 ushort colormap_index; 0053 ushort colormap_length; 0054 uchar colormap_size; 0055 ushort x_origin; 0056 ushort y_origin; 0057 ushort width; 0058 ushort height; 0059 uchar pixel_size; 0060 uchar flags; 0061 0062 enum { SIZE = 18 }; // const static int SIZE = 18; 0063 }; 0064 0065 0066 struct Color555 { 0067 ushort b : 5; 0068 ushort g : 5; 0069 ushort r : 5; 0070 }; 0071 0072 struct TgaHeaderInfo { 0073 bool rle; 0074 bool pal; 0075 bool rgb; 0076 bool grey; 0077 0078 TgaHeaderInfo(const TgaHeader & tga) : rle(false), pal(false), rgb(false), grey(false) { 0079 switch (tga.image_type) { 0080 case TGA_TYPE_RLE_INDEXED: 0081 rle = true; 0082 Q_FALLTHROUGH(); 0083 case TGA_TYPE_INDEXED: 0084 pal = true; 0085 break; 0086 0087 case TGA_TYPE_RLE_RGB: 0088 rle = true; 0089 Q_FALLTHROUGH(); 0090 case TGA_TYPE_RGB: 0091 rgb = true; 0092 break; 0093 case TGA_TYPE_RLE_GREY: 0094 rle = true; 0095 Q_FALLTHROUGH(); 0096 case TGA_TYPE_GREY: 0097 grey = true; 0098 break; 0099 default: 0100 // Error, unknown image type. 0101 break; 0102 } 0103 } 0104 }; 0105 0106 0107 0108 0109 0110 0111 #endif // TGA_H