annotate libmpcodecs/vd_mtga.c @ 20473:6ebbcbeae8c1

Cleanup/simplify nsv check_file function.
author reimar
date Sat, 28 Oct 2006 11:01:18 +0000
parents 497ebe3ecc2b
children 1767c271d710
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 "libvo/fastmemcpy.h"
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
15
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
16 #include "vd_internal.h"
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
17
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
18 static vd_info_t info =
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
19 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
20 "TGA Images decoder",
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
21 "mtga",
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
22 "Tilman Sauerbeck, A'rpi",
7362
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 "only 24bpp and 32bpp RGB targa files support so far"
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
25 };
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 LIBVD_EXTERN(mtga)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
28
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
29 typedef enum
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
30 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
31 TGA_NO_DATA,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
32 TGA_UNCOMP_PALETTED,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
33 TGA_UNCOMP_TRUECOLOR,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
34 TGA_UNCOMP_GRAYSCALE,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
35 TGA_RLE_PALETTED = 9,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
36 TGA_RLE_TRUECOLOR,
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
37 TGA_RLE_GRAYSCALE
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
38 } TGAImageType;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
39
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
40 typedef struct
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
41 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
42 unsigned char id_len;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
43 unsigned short img_type;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
44
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
45 unsigned short width;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
46 unsigned short height;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
47
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
48 unsigned char bpp;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
49 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
50 unsigned short start_row;
9605
1bec441675d1 increment is a signed number (-1 or +1)
arpi
parents: 7472
diff changeset
51 short increment;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
52 } TGAInfo;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
53
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
54 static unsigned int out_fmt = 0;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
55
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
56 static int last_w = -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
57 static int last_h = -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
58 static int last_c = -1;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
59
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
60
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
61 /* to set/get/query special features/parameters */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
62 static int control(sh_video_t *sh, int cmd, void *arg, ...)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
63 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
64 switch (cmd)
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
65 {
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
66 case VDCTRL_QUERY_FORMAT:
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
67 if (*((int *) arg) == out_fmt) return CONTROL_TRUE;
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
68 return CONTROL_FALSE;
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
69 }
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
70 return CONTROL_UNKNOWN;
7362
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
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
73 /* init driver */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
74 static int init(sh_video_t *sh)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
75 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
76 sh->context = (TGAInfo *) calloc(1, sizeof(TGAInfo));
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
77 last_w = -1;
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
78
7362
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 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
86 TGAInfo *info = sh->context;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
87 free(info);
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
88 return;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
89 }
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 /* decode a runlength-encoded tga */
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
93 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
94 {
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
95 int row, col, replen, i, num_bytes = info->bpp / 8;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
96 unsigned char repetitions, packet_header, *final;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
97
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
98 /* 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
99 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
100 {
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
101 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
102
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
103 for (col = 0; col < info->width; col += repetitions)
7362
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 packet_header = *data++;
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
106 repetitions = (1 + (packet_header & 0x7f));
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
107 replen = repetitions * num_bytes;
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 if (packet_header & 0x80) /* runlength encoded packet */
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
110 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
111 memcpy(final, data, num_bytes);
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
112
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
113 // Note: this will be slow when DR to vram!
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
114 i=num_bytes;
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
115 while(2*i<=replen){
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
116 memcpy(final+i,final,i);
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
117 i*=2;
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
118 }
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
119 memcpy(final+i,final,replen-i);
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
120 data += num_bytes;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
121 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
122 else /* raw packet */
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
123 {
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
124 memcpy(final, data, replen);
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
125 data += replen;
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
126 }
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
127
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
128 final += replen;
7362
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 }
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
131
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
132 return;
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
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
135
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
136 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
137 {
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
138 unsigned char *final;
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
139 int row, num_bytes = info->bpp / 8;
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
140
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
141 /* 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
142 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
143 {
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
144 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
145 memcpy(final, data, info->width * num_bytes);
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
146 data += info->width * num_bytes;
7362
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
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
149 return;
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
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
153 static short read_tga_header(unsigned char *buf, TGAInfo *info)
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
154 {
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
155 info->id_len = buf[0];
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
156
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
157 info->img_type = buf[2];
7362
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 /* targa data is always stored in little endian byte order */
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
160 info->width = le2me_16(*(unsigned short *) &buf[12]);
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
161 info->height = le2me_16(*(unsigned short *) &buf[14]);
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
162
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
163 info->bpp = buf[16];
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
164
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
165 info->origin = (buf[17] & 0x20) >> 5;
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
166
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
167 /* FIXME check for valid targa data */
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 return 0;
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
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 /* decode a frame */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
174 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
175 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
176 TGAInfo *info = sh->context;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
177 unsigned char *data = raw;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
178 mp_image_t *mpi;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
179
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
180
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
181 if (len <= 0)
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
182 return NULL; /* skip frame */
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
183
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
184 read_tga_header(data, info); /* read information about the file */
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
185
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
186 if (info->bpp == 24)
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
187 out_fmt = IMGFMT_BGR24;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
188 else if (info->bpp == 32)
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
189 out_fmt = IMGFMT_BGR32;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
190 else
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
191 {
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
192 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "Unsupported TGA type! depth=%d\n",info->bpp);
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
193 return NULL;
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
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
196 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
197 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
198 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
199 return NULL;
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
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
202 /* 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
203 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
204 info->increment = (info->origin) ? 1 : -1;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
205
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
206 /* 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
207 data += 18 + info->id_len;
7362
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 /* (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
210 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
211 {
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
212 last_w = info->width;
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
213 last_h = info->height;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
214 last_c = out_fmt;
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 (!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
217 return NULL;
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
218 }
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
219
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
220 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
221 return NULL;
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 /* finally decode the image */
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
224 if (info->img_type == TGA_UNCOMP_TRUECOLOR)
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
225 decode_uncompressed_tga(info, data, mpi);
7392
e21841225e2a query_format support by Tilman Sauerbeck <tsauerbeck@users.sourceforge.net>
alex
parents: 7362
diff changeset
226 else if (info->img_type == TGA_RLE_TRUECOLOR)
7401
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
227 decode_rle_tga(info, data, mpi);
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
228 // else
8b90281ed8aa - fixed some bugs in RLE decoder
arpi
parents: 7392
diff changeset
229 // mpi = NULL;
7362
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
230
8ae490fbf89d TGA images (-mf on:type=tga) support
arpi
parents:
diff changeset
231 return mpi;
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