annotate libmpcodecs/vd_mtga.c @ 7399:56bb20a00bc9

cross-ref
author arpi
date Sun, 15 Sep 2002 01:40:59 +0000
parents e21841225e2a
children 8b90281ed8aa
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 */
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
51 unsigned short start_row;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
52 unsigned short increment;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
53 } TGAInfo;
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 static unsigned int out_fmt = 0;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
56
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
57 static int last_w = -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
58 static int last_h = -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
59 static int last_c = -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
60
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
61
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
62 /* to set/get/query special features/parameters */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
63 static int control(sh_video_t *sh, int cmd, void *arg, ...)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
64 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
65 TGAInfo *info = (TGAInfo *) sh->context;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
66
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
67
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
68 switch (cmd)
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
69 {
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
70 case VDCTRL_QUERY_FORMAT:
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
71 if ((*((int *) arg) == IMGFMT_BGR32 && info->bpp == 32) || (*((int *) arg) == IMGFMT_BGR24 && info->bpp == 24))
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
72 return CONTROL_TRUE;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
73 else
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
74 return CONTROL_FALSE;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
75 break;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
76 default:
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
77 return CONTROL_UNKNOWN;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
78 break;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
79 }
7362
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 /* init driver */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
83 static int init(sh_video_t *sh)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
84 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
85 sh->context = (TGAInfo *) calloc(1, sizeof(TGAInfo));
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
86 last_w = -1;
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
87
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
88
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
89 return 1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
90 }
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
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
93 /* uninit driver */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
94 static void uninit(sh_video_t *sh)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
95 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
96 TGAInfo *info = sh->context;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
97
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
98
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
99 free(info);
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
100
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
101
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
102 return;
7362
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
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 /* decode a runlength-encoded tga */
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
107 static void decode_rle_tga(TGAInfo *info, unsigned char *data, mp_image_t **mpi)
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
108 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
109 short i, num_bytes = info->bpp / 8;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
110 unsigned char repetitions, packet_header, *final;
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
111 unsigned short row, col;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
112
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
113
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
114 /* see line 207 to see why this loop is set up like this */
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
115 for (row = info->start_row; (!info->origin && row) || (info->origin && row < info->height); row += info->increment)
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
116 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
117 final = (*mpi)->planes[0] + (*mpi)->stride[0] * row;
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
118
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
119 for (col = 0; col < info->width; col += repetitions)
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
120 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
121 packet_header = *data++;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
122 repetitions = 1 + (packet_header & 0x7f);
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
123
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
124 if (packet_header & 0x80) /* runlength encoded packet */
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
125 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
126 memcpy(final, data, num_bytes);
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
127
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
128 for (i = num_bytes; i < repetitions; i *= 2)
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
129 memcpy(&final[i], final, i);
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
130
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
131 for (; i < repetitions * num_bytes; i += 3)
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
132 memcpy(&final[i], final, num_bytes);
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
133 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
134 else /* raw packet */
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
135 memcpy(final, data, repetitions * num_bytes);
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
136
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
137 data += (packet_header & 0x80) ? num_bytes : repetitions * num_bytes;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
138 final += repetitions * num_bytes;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
139 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
140 }
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
141
7362
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 return;
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
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
147 static void decode_uncompressed_tga(TGAInfo *info, unsigned char *data, mp_image_t **mpi)
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
148 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
149 unsigned short row;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
150 unsigned char *final;
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
151 short num_bytes = info->bpp / 8;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
152
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
153
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
154 /* see line 207 to see why this loop is set up like this */
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
155 for (row = info->start_row; (!info->origin && row) || (info->origin && row < info->height); row += info->increment)
7362
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 final = (*mpi)->planes[0] + (*mpi)->stride[0] * row;
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
158 memcpy(final, data, info->width * num_bytes);
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
159 data += info->width * num_bytes;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
160 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
161
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
162
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
163 return;
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
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
166
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
167 static short read_tga_header(unsigned char *buf, TGAInfo **info)
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
168 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
169 (*info)->id_len = buf[0];
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
170
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
171 (*info)->img_type = buf[2];
7362
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 /* targa data is always stored in little endian byte order */
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
174 (*info)->width = le2me_16(*(unsigned short *) &buf[12]);
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
175 (*info)->height = le2me_16(*(unsigned short *) &buf[14]);
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
176
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
177 (*info)->bpp = buf[16];
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
178
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
179 (*info)->origin = (buf[17] & 0x20) >> 5;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
180
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
181 /* FIXME check for valid targa data */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
182
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
183 return 0;
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
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
187 /* decode a frame */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
188 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
189 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
190 TGAInfo *info = sh->context;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
191 unsigned char *data = raw;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
192 mp_image_t *mpi;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
193
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 if (len <= 0)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
196 return NULL; /* skip frame */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
197
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
198 read_tga_header(data, &info); /* read information about the file */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
199
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
200 if (info->bpp == 24)
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
201 out_fmt = IMGFMT_BGR24;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
202 else if (info->bpp == 32)
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
203 out_fmt = IMGFMT_BGR32;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
204 else
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
205 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
206 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "Unsupported TGA type!\n");
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
207 return NULL;
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
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
210 if (info->img_type != TGA_UNCOMP_TRUECOLOR && info->img_type != TGA_RLE_TRUECOLOR) /* not a true color image */
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
211 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
212 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "Unsupported TGA type: %i!\n", info->img_type);
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
213 return NULL;
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
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
216 /* if img.origin is 0, we decode from bottom to top. if it's 1, we decode from top to bottom */
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
217 info->start_row = (info->origin) ? 0 : info->height - 1;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
218 info->increment = (info->origin) ? 1 : -1;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
219
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
220 /* set data to the beginning of the image data */
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
221 data += 18 + info->id_len;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
222
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
223 /* (re)init libvo if image parameters changed (width/height/colorspace) */
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
224 if (last_w != info->width || last_h != info->height || last_c != out_fmt)
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
225 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
226 last_w = info->width;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
227 last_h = info->height;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
228 last_c = out_fmt;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
229
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
230 if (!out_fmt || !mpcodecs_config_vo(sh, info->width, info->height, out_fmt))
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
231 return NULL;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
232 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
233
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
234 if (!(mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, info->width, info->height)))
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
235 return NULL;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
236
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
237 /* finally decode the image */
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
238 if (info->img_type == TGA_UNCOMP_TRUECOLOR)
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
239 decode_uncompressed_tga(info, data, &mpi);
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
240 else if (info->img_type == TGA_RLE_TRUECOLOR)
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
241 decode_rle_tga(info, data, &mpi);
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
242 else
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
243 mpi = 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 return mpi;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
247 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
248