1 /*
2 * Targa (.tga) image encoder
3 * Copyright (c) 2007 Bobby Bingham
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <string.h>
23
34
37
40
41 /**
42 * RLE compress the image, with maximum size of out_size
43 * @param outbuf Output buffer
44 * @param out_size Maximum output size
45 * @param pic Image to compress
46 * @param bpp Bytes per pixel
47 * @param w Image width
48 * @param h Image height
49 * @return Size of output in bytes, or -1 if larger than out_size
50 */
52 int bpp,
int w,
int h)
53 {
56
58
59 for(y = 0; y <
h; y ++) {
62 return -1;
63 }
66 }
67
69 }
70
72 {
74 uint8_t *
out = outbuf;
75 uint8_t *ptr = pic->
data[0];
76
77 for(
i=0;
i <
h;
i++) {
81 }
82
84 }
85
87 const AVFrame *p,
int *got_packet)
88 {
90 int bpp, picsize, datasize = -1,
ret,
i;
92
97
98 /* zero out the header and only set applicable fields */
102 /* image descriptor byte: origin is always top-left, bits 0-3 specify alpha */
104
105 out =
pkt->
data + 18;
/* skip past the header we write */
106
110 int pal_bpp = 24; /* Only write 32bit palette if there is transparency information */
111 for (
i = 0;
i < 256;
i++)
113 pal_bpp = 32;
114 break;
115 }
116 pkt->
data[1] = 1;
/* palette present */
118 pkt->
data[6] = 1;
/* palette contains 256 entries */
119 pkt->
data[7] = pal_bpp;
/* palette contains pal_bpp bit entries */
121 for (
i = 0;
i < 256;
i++)
122 if (pal_bpp == 32) {
124 } else {
126 }
127 out += 32 * pal_bpp;
/* skip past the palette we just output */
128 break;
129 }
134 break;
139 break;
143 break;
147 break;
148 default:
152 }
154
155
156 /* try RLE compression */
159
160 /* if that worked well, mark the picture as RLE compressed */
161 if(datasize >= 0)
163
164 /* if RLE didn't make it smaller, go back to no compression */
166
168
169 /* The standard recommends including this section, even if we don't use
170 * any of the features it affords. TODO: take advantage of the pixel
171 * aspect ratio and encoder ID fields available? */
172 memcpy(
out,
"0円0円0円0円0円0円0円0円TRUEVISION-XFILE.", 26);
173
175 *got_packet = 1;
176
177 return 0;
178 }
179
181 {
182 if (avctx->
width > 0xffff || avctx->
height > 0xffff) {
185 }
186
187 return 0;
188 }
189
190 #define OFFSET(x) offsetof(TargaContext, x)
191 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
194
196 };
197
203 };
204
217 },
219 };