annotate targa.c @ 10974:b1ccfdc1b409 libavcodec

Moved reusable code from dxva2_h264.c:end_frame to ff_dxva2_common_end_frame.
author fenrir
date Sat, 23 Jan 2010 17:59:08 +0000
parents 9a577b684548
children 8a4984c5cacc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
1 /*
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
2 * Targa (.tga) image decoder
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
3 * Copyright (c) 2006 Konstantin Shishkov
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
4 *
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
5 * This file is part of FFmpeg.
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
6 *
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
11 *
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
15 * Lesser General Public License for more details.
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
16 *
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
20 */
8573
2acf0ae7b041 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 7040
diff changeset
21
2acf0ae7b041 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 7040
diff changeset
22 #include "libavutil/intreadwrite.h"
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
23 #include "avcodec.h"
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
24
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
25 enum TargaCompr{
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
26 TGA_NODATA = 0, // no image data
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
27 TGA_PAL = 1, // palettized
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
28 TGA_RGB = 2, // true-color
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
29 TGA_BW = 3, // black & white or grayscale
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
30 TGA_RLE = 8, // flag pointing that data is RLE-coded
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
31 };
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
32
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
33 typedef struct TargaContext {
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
34 AVFrame picture;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
35
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
36 int width, height;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
37 int bpp;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
38 int color_type;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
39 int compression_type;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
40 } TargaContext;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
41
6281
michael
parents: 5215
diff changeset
42 static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, const uint8_t *src, uint8_t *dst, int w, int h, int stride, int bpp)
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
43 {
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
44 int i, x, y;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
45 int depth = (bpp + 1) >> 3;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
46 int type, count;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
47 int diff;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
48
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
49 diff = stride - w * depth;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
50 x = y = 0;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
51 while(y < h){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
52 type = *src++;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
53 count = (type & 0x7F) + 1;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
54 type &= 0x80;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
55 if((x + count > w) && (x + count + 1 > (h - y) * w)){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
56 av_log(avctx, AV_LOG_ERROR, "Packet went out of bounds: position (%i,%i) size %i\n", x, y, count);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
57 return;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
58 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
59 for(i = 0; i < count; i++){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
60 switch(depth){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
61 case 1:
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
62 *dst = *src;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
63 break;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
64 case 2:
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4132
diff changeset
65 *((uint16_t*)dst) = AV_RL16(src);
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
66 break;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
67 case 3:
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
68 dst[0] = src[0];
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
69 dst[1] = src[1];
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
70 dst[2] = src[2];
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
71 break;
4132
c9e0315f9954 RGB32 support in Targa
kostya
parents: 4128
diff changeset
72 case 4:
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4132
diff changeset
73 *((uint32_t*)dst) = AV_RL32(src);
4132
c9e0315f9954 RGB32 support in Targa
kostya
parents: 4128
diff changeset
74 break;
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
75 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
76 dst += depth;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
77 if(!type)
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
78 src += depth;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
79
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
80 x++;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
81 if(x == w){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
82 x = 0;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
83 y++;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
84 dst += diff;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
85 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
86 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
87 if(type)
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
88 src += depth;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
89 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
90 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
91
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
92 static int decode_frame(AVCodecContext *avctx,
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
93 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8573
diff changeset
94 AVPacket *avpkt)
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
95 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8573
diff changeset
96 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8573
diff changeset
97 int buf_size = avpkt->size;
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
98 TargaContext * const s = avctx->priv_data;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
99 AVFrame *picture = data;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
100 AVFrame * const p= (AVFrame*)&s->picture;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
101 uint8_t *dst;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
102 int stride;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
103 int idlen, pal, compr, x, y, w, h, bpp, flags;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
104 int first_clr, colors, csize;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
105
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
106 /* parse image header */
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
107 idlen = *buf++;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
108 pal = *buf++;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
109 compr = *buf++;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4132
diff changeset
110 first_clr = AV_RL16(buf); buf += 2;
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4132
diff changeset
111 colors = AV_RL16(buf); buf += 2;
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
112 csize = *buf++;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4132
diff changeset
113 x = AV_RL16(buf); buf += 2;
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4132
diff changeset
114 y = AV_RL16(buf); buf += 2;
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4132
diff changeset
115 w = AV_RL16(buf); buf += 2;
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4132
diff changeset
116 h = AV_RL16(buf); buf += 2;
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
117 bpp = *buf++;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
118 flags = *buf++;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
119 //skip identifier if any
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
120 buf += idlen;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
121 s->bpp = bpp;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
122 s->width = w;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
123 s->height = h;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
124 switch(s->bpp){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
125 case 8:
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
126 avctx->pix_fmt = ((compr & (~TGA_RLE)) == TGA_BW) ? PIX_FMT_GRAY8 : PIX_FMT_PAL8;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
127 break;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
128 case 15:
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
129 avctx->pix_fmt = PIX_FMT_RGB555;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
130 break;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
131 case 16:
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
132 avctx->pix_fmt = PIX_FMT_RGB555;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
133 break;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
134 case 24:
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
135 avctx->pix_fmt = PIX_FMT_BGR24;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
136 break;
4132
c9e0315f9954 RGB32 support in Targa
kostya
parents: 4128
diff changeset
137 case 32:
4494
ce643a22f049 Replace deprecated PIX_FMT names by the newer variants.
diego
parents: 4364
diff changeset
138 avctx->pix_fmt = PIX_FMT_RGB32;
4132
c9e0315f9954 RGB32 support in Targa
kostya
parents: 4128
diff changeset
139 break;
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
140 default:
4128
2e93c877d264 Use bpp from header in error message
kostya
parents: 3986
diff changeset
141 av_log(avctx, AV_LOG_ERROR, "Bit depth %i is not supported\n", s->bpp);
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
142 return -1;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
143 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
144
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
145 if(s->picture.data[0])
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
146 avctx->release_buffer(avctx, &s->picture);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
147
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
148 if(avcodec_check_dimensions(avctx, w, h))
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
149 return -1;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
150 if(w != avctx->width || h != avctx->height)
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
151 avcodec_set_dimensions(avctx, w, h);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
152 if(avctx->get_buffer(avctx, p) < 0){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
153 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
154 return -1;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
155 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
156 if(flags & 0x20){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
157 dst = p->data[0];
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
158 stride = p->linesize[0];
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
159 }else{ //image is upside-down
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
160 dst = p->data[0] + p->linesize[0] * (h - 1);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
161 stride = -p->linesize[0];
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
162 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
163
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
164 if(avctx->pix_fmt == PIX_FMT_PAL8 && avctx->palctrl){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
165 memcpy(p->data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
166 if(avctx->palctrl->palette_changed){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
167 p->palette_has_changed = 1;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
168 avctx->palctrl->palette_changed = 0;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
169 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
170 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
171 if(colors){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
172 if((colors + first_clr) > 256){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
173 av_log(avctx, AV_LOG_ERROR, "Incorrect palette: %i colors with offset %i\n", colors, first_clr);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
174 return -1;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
175 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
176 if(csize != 24){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
177 av_log(avctx, AV_LOG_ERROR, "Palette entry size %i bits is not supported\n", csize);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
178 return -1;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
179 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
180 if(avctx->pix_fmt != PIX_FMT_PAL8)//should not occur but skip palette anyway
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
181 buf += colors * ((csize + 1) >> 3);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
182 else{
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
183 int r, g, b, t;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
184 int32_t *pal = ((int32_t*)p->data[1]) + first_clr;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
185 for(t = 0; t < colors; t++){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
186 r = *buf++;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
187 g = *buf++;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
188 b = *buf++;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
189 *pal++ = (b << 16) | (g << 8) | r;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
190 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
191 p->palette_has_changed = 1;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
192 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
193 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
194 if((compr & (~TGA_RLE)) == TGA_NODATA)
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
195 memset(p->data[0], 0, p->linesize[0] * s->height);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
196 else{
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
197 if(compr & TGA_RLE)
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
198 targa_decode_rle(avctx, s, buf, dst, avctx->width, avctx->height, stride, bpp);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
199 else{
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
200 for(y = 0; y < s->height; y++){
9985
266bf83f634d Replace WORDS_BIGENDIAN with HAVE_BIGENDIAN
mru
parents: 9810
diff changeset
201 #if HAVE_BIGENDIAN
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
202 if((s->bpp + 1) >> 3 == 2){
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
203 uint16_t *dst16 = (uint16_t*)dst;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
204 for(x = 0; x < s->width; x++)
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4132
diff changeset
205 dst16[x] = AV_RL16(buf + x * 2);
4132
c9e0315f9954 RGB32 support in Targa
kostya
parents: 4128
diff changeset
206 }else if((s->bpp + 1) >> 3 == 4){
c9e0315f9954 RGB32 support in Targa
kostya
parents: 4128
diff changeset
207 uint32_t *dst32 = (uint32_t*)dst;
c9e0315f9954 RGB32 support in Targa
kostya
parents: 4128
diff changeset
208 for(x = 0; x < s->width; x++)
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4132
diff changeset
209 dst32[x] = AV_RL32(buf + x * 4);
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
210 }else
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
211 #endif
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
212 memcpy(dst, buf, s->width * ((s->bpp + 1) >> 3));
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
213
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
214 dst += stride;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
215 buf += s->width * ((s->bpp + 1) >> 3);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
216 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
217 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
218 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
219
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
220 *picture= *(AVFrame*)&s->picture;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
221 *data_size = sizeof(AVPicture);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
222
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
223 return buf_size;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
224 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
225
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6281
diff changeset
226 static av_cold int targa_init(AVCodecContext *avctx){
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
227 TargaContext *s = avctx->priv_data;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
228
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
229 avcodec_get_frame_defaults((AVFrame*)&s->picture);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
230 avctx->coded_frame= (AVFrame*)&s->picture;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
231
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
232 return 0;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
233 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
234
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6281
diff changeset
235 static av_cold int targa_end(AVCodecContext *avctx){
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
236 TargaContext *s = avctx->priv_data;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
237
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
238 if(s->picture.data[0])
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
239 avctx->release_buffer(avctx, &s->picture);
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
240
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
241 return 0;
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
242 }
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
243
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
244 AVCodec targa_decoder = {
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
245 "targa",
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
246 CODEC_TYPE_VIDEO,
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
247 CODEC_ID_TARGA,
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
248 sizeof(TargaContext),
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
249 targa_init,
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
250 NULL,
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
251 targa_end,
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
252 decode_frame,
9810
8f56bd47d2c8 targa image decoder uses get_buffer, set CODEC_CAP_DR1
bcoudurier
parents: 9553
diff changeset
253 CODEC_CAP_DR1,
6722
6eeb19edcee3 Add long names to some AVCodec declarations.
diego
parents: 6517
diff changeset
254 NULL,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6722
diff changeset
255 .long_name = NULL_IF_CONFIG_SMALL("Truevision Targa image"),
3986
54c7481b381e Targa image decoder
kostya
parents:
diff changeset
256 };