1d61900aaSMatthew Wilber /*****************************************************************************/
2d61900aaSMatthew Wilber // tgainfo
3*2ca13760SColdfirex // Written by Michael Wilber, Haiku Translation Kit Team
4d61900aaSMatthew Wilber //
5d61900aaSMatthew Wilber // Version:
6d61900aaSMatthew Wilber //
7d61900aaSMatthew Wilber // tgainfo is a command line program for displaying information about
8d61900aaSMatthew Wilber // TGA images.
9d61900aaSMatthew Wilber //
10d61900aaSMatthew Wilber //
11d61900aaSMatthew Wilber // This application and all source files used in its construction, except
12d61900aaSMatthew Wilber // where noted, are licensed under the MIT License, and have been written
13d61900aaSMatthew Wilber // and are:
14d61900aaSMatthew Wilber //
15*2ca13760SColdfirex // Copyright (c) 2003 Haiku Project
16d61900aaSMatthew Wilber //
17d61900aaSMatthew Wilber // Permission is hereby granted, free of charge, to any person obtaining a
18d61900aaSMatthew Wilber // copy of this software and associated documentation files (the "Software"),
19d61900aaSMatthew Wilber // to deal in the Software without restriction, including without limitation
20d61900aaSMatthew Wilber // the rights to use, copy, modify, merge, publish, distribute, sublicense,
21d61900aaSMatthew Wilber // and/or sell copies of the Software, and to permit persons to whom the
22d61900aaSMatthew Wilber // Software is furnished to do so, subject to the following conditions:
23d61900aaSMatthew Wilber //
24d61900aaSMatthew Wilber // The above copyright notice and this permission notice shall be included
25d61900aaSMatthew Wilber // in all copies or substantial portions of the Software.
26d61900aaSMatthew Wilber //
27d61900aaSMatthew Wilber // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
28d61900aaSMatthew Wilber // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29d61900aaSMatthew Wilber // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30d61900aaSMatthew Wilber // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31d61900aaSMatthew Wilber // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32d61900aaSMatthew Wilber // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33d61900aaSMatthew Wilber // DEALINGS IN THE SOFTWARE.
34d61900aaSMatthew Wilber /*****************************************************************************/
35d61900aaSMatthew Wilber #include <stdio.h>
36d61900aaSMatthew Wilber #include <stdlib.h>
37d61900aaSMatthew Wilber #include <string.h>
38d61900aaSMatthew Wilber #include <ByteOrder.h>
399d79ce81SJorma Karvonen #include <Catalog.h>
40d61900aaSMatthew Wilber #include <File.h>
41d61900aaSMatthew Wilber #include <TranslatorFormats.h>
425d71fdcbSshatty #include <StorageDefs.h>
43d61900aaSMatthew Wilber
4489067672SAugustin Cavalier #undef B_TRANSLATION_CONTEXT
4589067672SAugustin Cavalier #define B_TRANSLATION_CONTEXT "tgainfo"
469d79ce81SJorma Karvonen
47d61900aaSMatthew Wilber #define max(x,y) ((x > y) ? x : y)
48d61900aaSMatthew Wilber #define DATA_BUFFER_SIZE 64
49d61900aaSMatthew Wilber
50d61900aaSMatthew Wilber struct TGAFileHeader {
51d61900aaSMatthew Wilber uint8 idlength;
52d61900aaSMatthew Wilber // Number of bytes in the Image ID field
53d61900aaSMatthew Wilber uint8 colormaptype;
54d61900aaSMatthew Wilber uint8 imagetype;
55d61900aaSMatthew Wilber };
56d61900aaSMatthew Wilber
57d61900aaSMatthew Wilber #define TGA_NO_COLORMAP 0
58d61900aaSMatthew Wilber #define TGA_COLORMAP 1
59d61900aaSMatthew Wilber
60d61900aaSMatthew Wilber #define TGA_NO_IMAGE_DATA 0
61d61900aaSMatthew Wilber
62d61900aaSMatthew Wilber #define TGA_NOCOMP_COLORMAP 1
63d61900aaSMatthew Wilber #define TGA_NOCOMP_TRUECOLOR 2
64d61900aaSMatthew Wilber #define TGA_NOCOMP_BW 3
65d61900aaSMatthew Wilber #define TGA_RLE_COLORMAP 9
66d61900aaSMatthew Wilber #define TGA_RLE_TRUECOLOR 10
67d61900aaSMatthew Wilber #define TGA_RLE_BW 11
68d61900aaSMatthew Wilber
69d61900aaSMatthew Wilber // Information about the color map (palette). These bytes are
70d61900aaSMatthew Wilber // always present, but are zero if no color map is present
71d61900aaSMatthew Wilber struct TGAColorMapSpec {
72d61900aaSMatthew Wilber uint16 firstentry; // first useful entry in the color map
73d61900aaSMatthew Wilber uint16 length; // number of color map entries
74d61900aaSMatthew Wilber uint8 entrysize; // number of bits per entry
75d61900aaSMatthew Wilber };
76d61900aaSMatthew Wilber
77d61900aaSMatthew Wilber struct TGAImageSpec {
78d61900aaSMatthew Wilber uint16 xorigin;
79d61900aaSMatthew Wilber uint16 yorigin;
80d61900aaSMatthew Wilber uint16 width;
81d61900aaSMatthew Wilber uint16 height;
82d61900aaSMatthew Wilber uint8 depth;
83d61900aaSMatthew Wilber uint8 descriptor;
84d61900aaSMatthew Wilber };
85d61900aaSMatthew Wilber
86d61900aaSMatthew Wilber #define TGA_ORIGIN_VERT_BIT 0x20
87d61900aaSMatthew Wilber #define TGA_ORIGIN_BOTTOM 0
88d61900aaSMatthew Wilber #define TGA_ORIGIN_TOP 1
89d61900aaSMatthew Wilber
90d61900aaSMatthew Wilber #define TGA_ORIGIN_HORZ_BIT 0x10
91d61900aaSMatthew Wilber #define TGA_ORIGIN_LEFT 0
92d61900aaSMatthew Wilber #define TGA_ORIGIN_RIGHT 1
93d61900aaSMatthew Wilber
94d61900aaSMatthew Wilber #define TGA_DESC_BITS76 0xc0
95d61900aaSMatthew Wilber #define TGA_DESC_ALPHABITS 0x0f
96d61900aaSMatthew Wilber
97d61900aaSMatthew Wilber #define TGA_HEADERS_SIZE 18
98d61900aaSMatthew Wilber #define TGA_FTR_LEN 26
99735e7442SMatthew Wilber #define TGA_EXT_LEN 495
100735e7442SMatthew Wilber #define LINE_LEN 82
101d61900aaSMatthew Wilber
102d61900aaSMatthew Wilber const char *
colormaptype(uint8 n)103d61900aaSMatthew Wilber colormaptype(uint8 n)
104d61900aaSMatthew Wilber {
105d61900aaSMatthew Wilber switch (n) {
1069d79ce81SJorma Karvonen case 0: return B_TRANSLATE("No colormap");
1079d79ce81SJorma Karvonen case 1: return B_TRANSLATE("colormap");
108d61900aaSMatthew Wilber }
109d61900aaSMatthew Wilber return "unknown";
110d61900aaSMatthew Wilber }
111d61900aaSMatthew Wilber
112d61900aaSMatthew Wilber const char *
imagetype(uint8 n)113d61900aaSMatthew Wilber imagetype(uint8 n)
114d61900aaSMatthew Wilber {
115d61900aaSMatthew Wilber switch (n) {
1169d79ce81SJorma Karvonen case 0: return B_TRANSLATE("No Image Data");
1179d79ce81SJorma Karvonen case 1: return B_TRANSLATE("colormap");
1189d79ce81SJorma Karvonen case 2: return B_TRANSLATE("true color");
1199d79ce81SJorma Karvonen case 3: return B_TRANSLATE("grayscale");
1209d79ce81SJorma Karvonen case 9: return B_TRANSLATE("RLE colormap");
1219d79ce81SJorma Karvonen case 10: return B_TRANSLATE("RLE true color");
1229d79ce81SJorma Karvonen case 11: return B_TRANSLATE("RLE grayscale");
1239d79ce81SJorma Karvonen default: break;
124d61900aaSMatthew Wilber }
1259d79ce81SJorma Karvonen return B_TRANSLATE("unknown");
126d61900aaSMatthew Wilber }
127d61900aaSMatthew Wilber
128735e7442SMatthew Wilber uint16
tga_uint16(char * buffer,int32 offset)129735e7442SMatthew Wilber tga_uint16(char *buffer, int32 offset)
130735e7442SMatthew Wilber {
131735e7442SMatthew Wilber return B_LENDIAN_TO_HOST_INT16(*(reinterpret_cast<uint16 *>(buffer + offset)));
132735e7442SMatthew Wilber }
133735e7442SMatthew Wilber
134735e7442SMatthew Wilber uint32
tga_uint32(char * buffer,int32 offset)135735e7442SMatthew Wilber tga_uint32(char *buffer, int32 offset)
136735e7442SMatthew Wilber {
137735e7442SMatthew Wilber return B_LENDIAN_TO_HOST_INT32(*(reinterpret_cast<uint32 *>(buffer + offset)));
138735e7442SMatthew Wilber }
139735e7442SMatthew Wilber
140d61900aaSMatthew Wilber void
print_tga_info(BFile & file)141d61900aaSMatthew Wilber print_tga_info(BFile &file)
142d61900aaSMatthew Wilber {
143d61900aaSMatthew Wilber uint8 buf[TGA_HEADERS_SIZE];
144d61900aaSMatthew Wilber
145d61900aaSMatthew Wilber // read in TGA headers
146d61900aaSMatthew Wilber ssize_t size = TGA_HEADERS_SIZE;
147d61900aaSMatthew Wilber if (size > 0 && file.Read(buf, size) != size) {
1489d79ce81SJorma Karvonen printf(B_TRANSLATE("Error: unable to read all TGA headers\n"));
149d61900aaSMatthew Wilber return;
150d61900aaSMatthew Wilber }
151d61900aaSMatthew Wilber
152d61900aaSMatthew Wilber // TGA file header
153d61900aaSMatthew Wilber TGAFileHeader fh;
154d61900aaSMatthew Wilber fh.idlength = buf[0];
155d61900aaSMatthew Wilber fh.colormaptype = buf[1];
156d61900aaSMatthew Wilber fh.imagetype = buf[2];
157d61900aaSMatthew Wilber
1589d79ce81SJorma Karvonen printf(B_TRANSLATE("\nFile Header:\n"));
1599d79ce81SJorma Karvonen printf(B_TRANSLATE(" id length: %d\n"), static_cast<int>(fh.idlength));
160d61900aaSMatthew Wilber
1619d79ce81SJorma Karvonen printf(B_TRANSLATE("colormap type: %d (%s)\n"),
1629d79ce81SJorma Karvonen static_cast<int>(fh.colormaptype),
1639d79ce81SJorma Karvonen static_cast<const char *>(colormaptype(fh.colormaptype)));
1649d79ce81SJorma Karvonen printf(B_TRANSLATE(" image type: %d (%s)\n"),
1659d79ce81SJorma Karvonen static_cast<int>(fh.imagetype),
1669d79ce81SJorma Karvonen static_cast<const char *>(imagetype(fh.imagetype)));
167d61900aaSMatthew Wilber
168d61900aaSMatthew Wilber
169d61900aaSMatthew Wilber // TGA color map spec
170d61900aaSMatthew Wilber TGAColorMapSpec mapspec;
171735e7442SMatthew Wilber mapspec.firstentry = tga_uint16(reinterpret_cast<char *>(buf), 3);
172735e7442SMatthew Wilber mapspec.length = tga_uint16(reinterpret_cast<char *>(buf), 5);
173d61900aaSMatthew Wilber mapspec.entrysize = buf[7];
174d61900aaSMatthew Wilber
1759d79ce81SJorma Karvonen printf(B_TRANSLATE("\nColormap Spec:\n"));
1769d79ce81SJorma Karvonen printf(B_TRANSLATE("first entry: %d\n"),
1779d79ce81SJorma Karvonen static_cast<int>(mapspec.firstentry));
1789d79ce81SJorma Karvonen printf(B_TRANSLATE(" length: %d\n"),
1799d79ce81SJorma Karvonen static_cast<int>(mapspec.length));
1809d79ce81SJorma Karvonen printf(B_TRANSLATE(" entry size: %d\n"),
1819d79ce81SJorma Karvonen static_cast<int>(mapspec.entrysize));
182d61900aaSMatthew Wilber
183d61900aaSMatthew Wilber
184d61900aaSMatthew Wilber // TGA image spec
185d61900aaSMatthew Wilber TGAImageSpec imagespec;
186735e7442SMatthew Wilber imagespec.xorigin = tga_uint16(reinterpret_cast<char *>(buf), 8);
187735e7442SMatthew Wilber imagespec.yorigin = tga_uint16(reinterpret_cast<char *>(buf), 10);
188735e7442SMatthew Wilber imagespec.width = tga_uint16(reinterpret_cast<char *>(buf), 12);
189735e7442SMatthew Wilber imagespec.height = tga_uint16(reinterpret_cast<char *>(buf), 14);
190d61900aaSMatthew Wilber imagespec.depth = buf[16];
191d61900aaSMatthew Wilber imagespec.descriptor = buf[17];
192d61900aaSMatthew Wilber
1939d79ce81SJorma Karvonen printf(B_TRANSLATE("\nImage Spec:\n"));
1949d79ce81SJorma Karvonen printf(B_TRANSLATE(" x origin: %d\n"),
1959d79ce81SJorma Karvonen static_cast<int>(imagespec.xorigin));
1969d79ce81SJorma Karvonen printf(B_TRANSLATE(" y origin: %d\n"),
1979d79ce81SJorma Karvonen static_cast<int>(imagespec.yorigin));
1989d79ce81SJorma Karvonen printf(B_TRANSLATE(" width: %d\n"),
1999d79ce81SJorma Karvonen static_cast<int>(imagespec.width));
2009d79ce81SJorma Karvonen printf(B_TRANSLATE(" height: %d\n"),
2019d79ce81SJorma Karvonen static_cast<int>(imagespec.height));
2029d79ce81SJorma Karvonen printf(B_TRANSLATE(" depth: %d\n"),
2039d79ce81SJorma Karvonen static_cast<int>(imagespec.depth));
2049d79ce81SJorma Karvonen printf(B_TRANSLATE("descriptor: 0x%.2x\n"),
2059d79ce81SJorma Karvonen static_cast<int>(imagespec.descriptor));
2069d79ce81SJorma Karvonen printf(B_TRANSLATE("\talpha (attr): %d\n"),
2079d79ce81SJorma Karvonen static_cast<int>(imagespec.descriptor & TGA_DESC_ALPHABITS));
2089d79ce81SJorma Karvonen if (imagespec.descriptor & TGA_ORIGIN_VERT_BIT)
2099d79ce81SJorma Karvonen if (imagespec.descriptor & TGA_ORIGIN_HORZ_BIT)
2109d79ce81SJorma Karvonen printf(B_TRANSLATE("\t origin: %d (%s %s)\n"),
2119d79ce81SJorma Karvonen static_cast<int>(imagespec.descriptor & (TGA_ORIGIN_VERT_BIT
2129d79ce81SJorma Karvonen | TGA_ORIGIN_HORZ_BIT)), static_cast<const char *>("top"),
2139d79ce81SJorma Karvonen static_cast<const char *>("right"));
2149d79ce81SJorma Karvonen else
2159d79ce81SJorma Karvonen printf(B_TRANSLATE("\t origin: %d (%s %s)\n"),
2169d79ce81SJorma Karvonen static_cast<int>(imagespec.descriptor & (TGA_ORIGIN_VERT_BIT
2179d79ce81SJorma Karvonen | TGA_ORIGIN_HORZ_BIT)), static_cast<const char *>("top"),
2189d79ce81SJorma Karvonen static_cast<const char *>("left"));
2199d79ce81SJorma Karvonen else
2209d79ce81SJorma Karvonen if (imagespec.descriptor & TGA_ORIGIN_HORZ_BIT)
2219d79ce81SJorma Karvonen printf(B_TRANSLATE("\t origin: %d (%s %s)\n"),
2229d79ce81SJorma Karvonen static_cast<int>(imagespec.descriptor & (TGA_ORIGIN_VERT_BIT
2239d79ce81SJorma Karvonen | TGA_ORIGIN_HORZ_BIT)), static_cast<const char *>("bottom"),
2249d79ce81SJorma Karvonen static_cast<const char *>("right"));
2259d79ce81SJorma Karvonen else
2269d79ce81SJorma Karvonen printf(B_TRANSLATE("\t origin: %d (%s %s)\n"),
2279d79ce81SJorma Karvonen static_cast<int>(imagespec.descriptor & (TGA_ORIGIN_VERT_BIT
2289d79ce81SJorma Karvonen | TGA_ORIGIN_HORZ_BIT)), static_cast<const char *>("bottom"),
2299d79ce81SJorma Karvonen static_cast<const char *>("left"));
2309d79ce81SJorma Karvonen
2319d79ce81SJorma Karvonen
2329d79ce81SJorma Karvonen printf(B_TRANSLATE("\t bits 7 & 6: %d\n"),
2339d79ce81SJorma Karvonen static_cast<int>(imagespec.descriptor & TGA_DESC_BITS76));
234d61900aaSMatthew Wilber
235d61900aaSMatthew Wilber
236d61900aaSMatthew Wilber // Optional TGA Footer
237d61900aaSMatthew Wilber off_t filesize = 0;
238d61900aaSMatthew Wilber if (file.GetSize(&filesize) == B_OK) {
239d61900aaSMatthew Wilber
240d61900aaSMatthew Wilber char tgafooter[TGA_FTR_LEN + 1] = { 0 };
241d61900aaSMatthew Wilber if (file.ReadAt(filesize - TGA_FTR_LEN, tgafooter, TGA_FTR_LEN) == TGA_FTR_LEN) {
242d61900aaSMatthew Wilber
243d61900aaSMatthew Wilber if (strcmp(tgafooter + 8, "TRUEVISION-XFILE.") == 0) {
244d61900aaSMatthew Wilber
245d61900aaSMatthew Wilber uint32 extoffset = 0, devoffset = 0;
246735e7442SMatthew Wilber extoffset = tga_uint32(tgafooter, 0);
247735e7442SMatthew Wilber devoffset = tga_uint32(tgafooter, 4);
248d61900aaSMatthew Wilber
2499d79ce81SJorma Karvonen printf(B_TRANSLATE("\nTGA Footer:\n"));
2509d79ce81SJorma Karvonen printf(B_TRANSLATE("extension offset: 0x%.8lx (%ld)\n"),
2519d79ce81SJorma Karvonen static_cast<long int>(extoffset),
2529d79ce81SJorma Karvonen static_cast<long int>(extoffset));
2539d79ce81SJorma Karvonen printf(B_TRANSLATE("developer offset: 0x%.8lx (%ld)\n"),
2549d79ce81SJorma Karvonen static_cast<long int>(devoffset),
2559d79ce81SJorma Karvonen static_cast<long int>(devoffset));
2569d79ce81SJorma Karvonen printf(B_TRANSLATE("signature: %s\n"), tgafooter + 8);
257d61900aaSMatthew Wilber
258735e7442SMatthew Wilber if (extoffset) {
259735e7442SMatthew Wilber char extbuf[TGA_EXT_LEN];
260735e7442SMatthew Wilber if (file.ReadAt(extoffset, extbuf, TGA_EXT_LEN) == TGA_EXT_LEN) {
261735e7442SMatthew Wilber
2629d79ce81SJorma Karvonen printf(B_TRANSLATE("\nExtension Area:\n"));
263735e7442SMatthew Wilber
264735e7442SMatthew Wilber char strbuffer[LINE_LEN];
265735e7442SMatthew Wilber
266735e7442SMatthew Wilber uint16 extsize = tga_uint16(extbuf, 0);
267735e7442SMatthew Wilber if (extsize < TGA_EXT_LEN) {
2689d79ce81SJorma Karvonen printf(B_TRANSLATE("\nError: extension "
2699d79ce81SJorma Karvonen "area is too small (%d)\n"), extsize);
270735e7442SMatthew Wilber return;
271735e7442SMatthew Wilber }
2729d79ce81SJorma Karvonen printf(B_TRANSLATE("size: %d\n"), extsize);
273735e7442SMatthew Wilber
274735e7442SMatthew Wilber memset(strbuffer, 0, LINE_LEN);
275735e7442SMatthew Wilber strncpy(strbuffer, extbuf + 2, 41);
276735e7442SMatthew Wilber printf("author: \"%s\"\n", strbuffer);
277735e7442SMatthew Wilber
2789d79ce81SJorma Karvonen printf(B_TRANSLATE("comments:\n"));
279735e7442SMatthew Wilber for (int32 i = 0; i < 4; i++) {
280735e7442SMatthew Wilber memset(strbuffer, 0, LINE_LEN);
281735e7442SMatthew Wilber strcpy(strbuffer, extbuf + 43 + (i * 81));
2829d79ce81SJorma Karvonen printf(B_TRANSLATE("\tline %ld: \"%s\"\n"),
2839d79ce81SJorma Karvonen static_cast<long int>(i + 1),
2849d79ce81SJorma Karvonen static_cast<const char *>(strbuffer));
285735e7442SMatthew Wilber }
286735e7442SMatthew Wilber
2879d79ce81SJorma Karvonen printf(B_TRANSLATE("date/time (yyyy-mm-dd hh:mm:ss): "
2889d79ce81SJorma Karvonen "%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n"),
289735e7442SMatthew Wilber tga_uint16(extbuf, 367), tga_uint16(extbuf, 369),
290735e7442SMatthew Wilber tga_uint16(extbuf, 371), tga_uint16(extbuf, 373),
291735e7442SMatthew Wilber tga_uint16(extbuf, 375), tga_uint16(extbuf, 377));
292735e7442SMatthew Wilber
293735e7442SMatthew Wilber memset(strbuffer, 0, LINE_LEN);
294735e7442SMatthew Wilber strncpy(strbuffer, extbuf + 379, 41);
2959d79ce81SJorma Karvonen printf(B_TRANSLATE("job name: \"%s\"\n"), strbuffer);
296735e7442SMatthew Wilber
2979d79ce81SJorma Karvonen printf(B_TRANSLATE("job time (hh:mm:ss): "
2989d79ce81SJorma Karvonen "%.2d:%.2d:%.2d\n"), tga_uint16(extbuf, 420),
2999d79ce81SJorma Karvonen tga_uint16(extbuf, 422), tga_uint16(extbuf, 424));
300735e7442SMatthew Wilber
301735e7442SMatthew Wilber memset(strbuffer, 0, LINE_LEN);
302735e7442SMatthew Wilber strncpy(strbuffer, extbuf + 426, 41);
3039d79ce81SJorma Karvonen printf(B_TRANSLATE("software id: \"%s\"\n"),
3049d79ce81SJorma Karvonen strbuffer);
305735e7442SMatthew Wilber
306735e7442SMatthew Wilber char strver[] = "[null]";
307735e7442SMatthew Wilber if (extbuf[469] != '\0') {
308735e7442SMatthew Wilber strver[0] = extbuf[469];
309735e7442SMatthew Wilber strver[1] = '\0';
310735e7442SMatthew Wilber }
3119d79ce81SJorma Karvonen printf(B_TRANSLATE("software version, letter: %d, "
3129d79ce81SJorma Karvonen "%s\n"), tga_uint16(extbuf, 467), strver);
313735e7442SMatthew Wilber
3149d79ce81SJorma Karvonen printf(B_TRANSLATE("key color (A,R,G,B): %d, %d, %d, "
3159d79ce81SJorma Karvonen "%d\n"), extbuf[470], extbuf[471], extbuf[472],
3169d79ce81SJorma Karvonen extbuf[473]);
317735e7442SMatthew Wilber
3189d79ce81SJorma Karvonen printf(B_TRANSLATE("pixel aspect ratio: %d / %d\n"),
319735e7442SMatthew Wilber tga_uint16(extbuf, 474), tga_uint16(extbuf, 476));
320735e7442SMatthew Wilber
3219d79ce81SJorma Karvonen printf(B_TRANSLATE("gamma value: %d / %d\n"),
322735e7442SMatthew Wilber tga_uint16(extbuf, 478), tga_uint16(extbuf, 480));
323735e7442SMatthew Wilber
3249d79ce81SJorma Karvonen printf(B_TRANSLATE("color correction offset: 0x%.8lx "
3259d79ce81SJorma Karvonen "(%ld)\n"), tga_uint32(extbuf, 482),
3269d79ce81SJorma Karvonen tga_uint32(extbuf, 482));
3279d79ce81SJorma Karvonen printf(B_TRANSLATE("postage stamp offset: 0x%.8lx "
3289d79ce81SJorma Karvonen "(%ld)\n"), tga_uint32(extbuf, 486),
3299d79ce81SJorma Karvonen tga_uint32(extbuf, 486));
3309d79ce81SJorma Karvonen printf(B_TRANSLATE("scan line offset: 0x%.8lx "
3319d79ce81SJorma Karvonen "(%ld)\n"), tga_uint32(extbuf, 490),
3329d79ce81SJorma Karvonen tga_uint32(extbuf, 490));
333735e7442SMatthew Wilber
334735e7442SMatthew Wilber const char *strattrtype = NULL;
335735e7442SMatthew Wilber uint8 attrtype = extbuf[494];
336735e7442SMatthew Wilber switch (attrtype) {
3379d79ce81SJorma Karvonen case 0: strattrtype
3389d79ce81SJorma Karvonen = B_TRANSLATE("no alpha"); break;
3399d79ce81SJorma Karvonen case 1: strattrtype
3409d79ce81SJorma Karvonen = B_TRANSLATE("undefined, ignore"); break;
3419d79ce81SJorma Karvonen case 2: strattrtype
3429d79ce81SJorma Karvonen = B_TRANSLATE("undefined, retain"); break;
3439d79ce81SJorma Karvonen case 3: strattrtype
3449d79ce81SJorma Karvonen = B_TRANSLATE("alpha"); break;
3459d79ce81SJorma Karvonen case 4: strattrtype
3469d79ce81SJorma Karvonen = B_TRANSLATE("pre-multiplied alpha"); break;
347735e7442SMatthew Wilber default:
348735e7442SMatthew Wilber if (attrtype > 4 && attrtype < 128)
3499d79ce81SJorma Karvonen strattrtype = B_TRANSLATE("reserved");
350735e7442SMatthew Wilber else
3519d79ce81SJorma Karvonen strattrtype = B_TRANSLATE("unassigned");
352735e7442SMatthew Wilber break;
353735e7442SMatthew Wilber }
3549d79ce81SJorma Karvonen printf(B_TRANSLATE("attributes type: %d (%s)\n"),
3559d79ce81SJorma Karvonen attrtype, strattrtype);
356735e7442SMatthew Wilber
357735e7442SMatthew Wilber } else
3589d79ce81SJorma Karvonen printf(B_TRANSLATE("\nError: Unable to read entire "
3599d79ce81SJorma Karvonen "extension area\n"));
360735e7442SMatthew Wilber }
361735e7442SMatthew Wilber
362d61900aaSMatthew Wilber } else
3639d79ce81SJorma Karvonen printf(B_TRANSLATE("\nTGA footer not found\n"));
364d61900aaSMatthew Wilber
365d61900aaSMatthew Wilber } else
3669d79ce81SJorma Karvonen printf(B_TRANSLATE("\nError: Unable to read TGA footer "
3679d79ce81SJorma Karvonen "section\n"));
368d61900aaSMatthew Wilber
369d61900aaSMatthew Wilber } else
3709d79ce81SJorma Karvonen printf(B_TRANSLATE("\nError: Unable to get file size\n"));
371d61900aaSMatthew Wilber }
372d61900aaSMatthew Wilber
373d61900aaSMatthew Wilber int
main(int argc,char ** argv)374d61900aaSMatthew Wilber main(int argc, char **argv)
375d61900aaSMatthew Wilber {
376d61900aaSMatthew Wilber printf("\n");
377d61900aaSMatthew Wilber
378735e7442SMatthew Wilber if (argc == 1) {
3799d79ce81SJorma Karvonen printf(B_TRANSLATE("tgainfo - reports information about a TGA image file\n"));
3809d79ce81SJorma Karvonen printf(B_TRANSLATE("\nUsage:\n"));
3819d79ce81SJorma Karvonen printf(B_TRANSLATE("tgainfo filename.tga\n"));
382d61900aaSMatthew Wilber }
383735e7442SMatthew Wilber else {
384735e7442SMatthew Wilber BFile file;
385735e7442SMatthew Wilber
386735e7442SMatthew Wilber for (int32 i = 1; i < argc; i++) {
387735e7442SMatthew Wilber if (file.SetTo(argv[i], B_READ_ONLY) != B_OK)
3889d79ce81SJorma Karvonen printf(B_TRANSLATE("\nError opening %s\n"), argv[i]);
389735e7442SMatthew Wilber else {
3909d79ce81SJorma Karvonen printf(B_TRANSLATE("\nTGA image information for: %s\n"), argv[i]);
391735e7442SMatthew Wilber print_tga_info(file);
392735e7442SMatthew Wilber }
393735e7442SMatthew Wilber }
394735e7442SMatthew Wilber
395735e7442SMatthew Wilber }
396d61900aaSMatthew Wilber
397d61900aaSMatthew Wilber printf("\n");
398d61900aaSMatthew Wilber
399d61900aaSMatthew Wilber return 0;
400d61900aaSMatthew Wilber }
401d61900aaSMatthew Wilber
402