File indexing completed on 2024-05-12 05:46:50

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