annotate libmpcodecs/vd_mtga.c @ 7386:174e2a58b4cd

avifile sync - 95% cosmetics 5% bug
author arpi
date Fri, 13 Sep 2002 19:43:17 +0000
parents 8ae490fbf89d
children e21841225e2a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
1 /* author: Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
2 * based on: XreaL's x_r_img_tga.* (http://www.sourceforge.net/projects/xreal/)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
3 * libtarga.*
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
4 * xli's tga.*
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
5 */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
6
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
7 #include <stdio.h>
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
8 #include <stdlib.h>
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
9
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
10 #include "config.h"
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
11 #include "mp_msg.h"
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
12
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
13 #include "bswap.h"
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
14 #include "postproc/rgb2rgb.h"
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
15 #include "libvo/fastmemcpy.h"
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
16
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
17 #include "vd_internal.h"
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
18
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
19 static vd_info_t info =
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
20 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
21 "TGA Images decoder",
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
22 "mtga",
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
23 "Tilman Sauerbeck",
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
24 "Tilman Sauerbeck",
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
25 "only 24bpp and 32bpp RGB targa files support so far"
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
26 };
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
27
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
28 LIBVD_EXTERN(mtga)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
29
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
30 typedef enum
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
31 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
32 TGA_NO_DATA,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
33 TGA_UNCOMP_PALETTED,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
34 TGA_UNCOMP_TRUECOLOR,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
35 TGA_UNCOMP_GRAYSCALE,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
36 TGA_RLE_PALETTED = 9,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
37 TGA_RLE_TRUECOLOR,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
38 TGA_RLE_GRAYSCALE
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
39 } TGAImageType;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
40
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
41 typedef struct
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
42 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
43 unsigned char id_len;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
44 unsigned short img_type;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
45
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
46 unsigned short width;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
47 unsigned short height;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
48
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
49 unsigned char bpp;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
50 unsigned char origin; /* 0 = lower left, 1 = upper left */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
51 } TGAInfo;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
52
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
53 typedef struct
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
54 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
55 /* red, green, blue, alpha */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
56 unsigned char r;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
57 unsigned char g;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
58 unsigned char b;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
59 unsigned char a;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
60 } ColorChannels;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
61
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
62
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
63 static unsigned int out_fmt = 0;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
64
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
65 static int last_w = -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
66 static int last_h = -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
67 static int last_c = -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
68
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
69 /* to set/get/query special features/parameters */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
70 static int control(sh_video_t *sh, int cmd, void *arg, ...)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
71 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
72 return CONTROL_UNKNOWN;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
73 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
74
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
75 /* init driver */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
76 static int init(sh_video_t *sh)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
77 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
78 last_w = -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
79 return 1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
80 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
81
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
82
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
83 /* uninit driver */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
84 static void uninit(sh_video_t *sh)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
85 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
86 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
87
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
88
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
89 /* decode a runlength-encoded tga */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
90 static void decode_rle_tga(TGAInfo info, unsigned char *data, mp_image_t **mpi)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
91 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
92 ColorChannels chans = {0, 0, 0, 0};
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
93 unsigned char repetitions, packet_header, *final;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
94 unsigned short row, col, i;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
95 short modifier;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
96
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
97
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
98 /* if img.origin is 0, we decode from bottom to top. if it's 1, we decode from top to bottom */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
99 row = (info.origin) ? 0 : info.height - 1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
100 modifier = (info.origin) ? 1 : -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
101
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
102 for (;;)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
103 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
104 final = (*mpi)->planes[0] + (*mpi)->stride[0] * row;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
105
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
106 for (col = 0; col < info.width;)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
107 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
108 packet_header = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
109 repetitions = 1 + (packet_header & 0x7f);
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
110
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
111 if (packet_header & 0x80)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
112 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
113 chans.b = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
114 chans.g = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
115 chans.r = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
116 chans.a = (info.bpp == 32) ? *data++ : 255;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
117
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
118 for (i = 0; i < repetitions; i++)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
119 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
120 *final++ = chans.r;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
121 *final++ = chans.g;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
122 *final++ = chans.b;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
123 *final++ = chans.a;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
124
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
125 col++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
126 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
127 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
128 else /* raw packet */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
129 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
130 for (i = 0; i < repetitions; i++)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
131 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
132 chans.b = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
133 chans.g = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
134 chans.r = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
135
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
136 *final++ = chans.r;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
137 *final++ = chans.g;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
138 *final++ = chans.b;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
139 *final++ = chans.a = (info.bpp == 32) ? *data++ : 255;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
140
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
141 col++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
142 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
143 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
144 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
145
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
146 row = row + modifier;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
147
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
148 if ((!info.origin && !row) || (info.origin && row >= info.height))
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
149 break;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
150 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
151
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
152
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
153 return;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
154 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
155
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
156
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
157 static void decode_uncompressed_tga(TGAInfo info, unsigned char *data, mp_image_t **mpi)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
158 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
159 ColorChannels chans;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
160 unsigned short row, col;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
161 unsigned char *final;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
162 short modifier;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
163
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
164
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
165 /* if img.origin is 0, we decode from bottom to top. if it's 1, we decode from top to bottom */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
166 row = (info.origin) ? 0 : info.height - 1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
167 modifier = (info.origin) ? 1 : -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
168
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
169 for (;;)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
170 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
171 final = (*mpi)->planes[0] + (*mpi)->stride[0] * row;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
172
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
173 for (col = 0; col < info.width; col++)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
174 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
175 chans.b = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
176 chans.g = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
177 chans.r = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
178
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
179 *final++ = chans.r;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
180 *final++ = chans.g;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
181 *final++ = chans.b;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
182 *final++ = info.bpp == 32 ? *data++ : 255;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
183
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
184 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
185
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
186 row = row + modifier;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
187
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
188 if ((!info.origin && !row) || (info.origin && row >= info.height))
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
189 break;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
190 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
191
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
192
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
193 return;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
194 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
195
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
196
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
197 static short read_tga_header(unsigned char *buf, TGAInfo *info)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
198 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
199 (*info).id_len = buf[0];
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
200
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
201 (*info).img_type = buf[2];
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
202
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
203 /* targa data is always stored in little endian byte order */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
204 (*info).width = le2me_16(*(unsigned short *) &buf[12]);
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
205 (*info).height = le2me_16(*(unsigned short *) &buf[14]);
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
206
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
207 (*info).bpp = buf[16];
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
208
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
209 (*info).origin = (buf[17] & 0x20) >> 5;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
210
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
211 /* FIXME check for valid targa data */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
212
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
213 return 0;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
214 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
215
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
216
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
217 /* decode a frame */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
218 static mp_image_t *decode(sh_video_t *sh, void *raw, int len, int flags)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
219 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
220 TGAInfo info;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
221 unsigned char *data = raw;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
222 mp_image_t *mpi;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
223
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
224
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
225 if (len <= 0)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
226 return NULL; /* skip frame */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
227
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
228 read_tga_header(data, &info); /* read information about the file */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
229
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
230 if (info.bpp == 24)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
231 out_fmt = IMGFMT_RGB24;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
232 else if (info.bpp == 32)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
233 out_fmt = IMGFMT_RGB32;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
234 else
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
235 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
236 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "Unsupported TGA type!\n");
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
237 return NULL;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
238 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
239
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
240 if (info.img_type != TGA_UNCOMP_TRUECOLOR && info.img_type != TGA_RLE_TRUECOLOR) /* not a true color image */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
241 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
242 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "Unsupported TGA type: %i!\n", info.img_type);
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
243 return NULL;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
244 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
245
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
246 /* set data to the beginning of the image data */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
247 data = data + 18 + info.id_len;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
248
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
249 /* (re)init libvo if image parameters changed (width/height/colorspace) */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
250 if (last_w != info.width || last_h != info.height || last_c != out_fmt)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
251 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
252 last_w = info.width;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
253 last_h = info.height;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
254 last_c = out_fmt;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
255
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
256 if (!out_fmt || !mpcodecs_config_vo(sh, info.width, info.height, out_fmt))
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
257 return NULL;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
258 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
259
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
260 if (!(mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, info.width, info.height)))
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
261 return NULL;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
262
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
263 /* finally decode the image */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
264 if (info.img_type == TGA_UNCOMP_TRUECOLOR)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
265 decode_uncompressed_tga(info, data, &mpi);
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
266 else if (info.img_type == TGA_RLE_TRUECOLOR)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
267 decode_rle_tga(info, data, &mpi);
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
268 else
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
269 mpi = NULL;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
270
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
271
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
272 return mpi;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
273 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
274