annotate bmp.c @ 5695:6b8daf48b82f libavcodec

HDYC fourcc, sample hdyc/Test2.avi
author bcoudurier
date Fri, 21 Sep 2007 18:23:46 +0000
parents de0e893ef264
children abe584ca935c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
1 /*
4415
f792b146869b Segregate code common to BMP decoder and future encoder
diego
parents: 4394
diff changeset
2 * BMP image format decoder
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
3 * Copyright (c) 2005 Mans Rullgard
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
15 * Lesser General Public License for more details.
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
16 *
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
20 */
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
21
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
22 #include "avcodec.h"
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
23 #include "bytestream.h"
4415
f792b146869b Segregate code common to BMP decoder and future encoder
diego
parents: 4394
diff changeset
24 #include "bmp.h"
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
25
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
26 static int bmp_decode_init(AVCodecContext *avctx){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
27 BMPContext *s = avctx->priv_data;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
28
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
29 avcodec_get_frame_defaults((AVFrame*)&s->picture);
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
30 avctx->coded_frame = (AVFrame*)&s->picture;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
31
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
32 return 0;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
33 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
34
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2949
diff changeset
35 static int bmp_decode_frame(AVCodecContext *avctx,
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
36 void *data, int *data_size,
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
37 uint8_t *buf, int buf_size)
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
38 {
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
39 BMPContext *s = avctx->priv_data;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
40 AVFrame *picture = data;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
41 AVFrame *p = &s->picture;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
42 unsigned int fsize, hsize;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
43 int width, height;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
44 unsigned int depth;
4393
michael
parents: 4109
diff changeset
45 BiCompression comp;
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
46 unsigned int ihsize;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
47 int i, j, n, linesize;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
48 uint32_t rgb[3];
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
49 uint8_t *ptr;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
50 int dsize;
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
51 uint8_t *buf0 = buf;
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
52
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
53 if(buf_size < 14){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
54 av_log(avctx, AV_LOG_ERROR, "buf size too small (%d)\n", buf_size);
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
55 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
56 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
57
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
58 if(bytestream_get_byte(&buf) != 'B' ||
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
59 bytestream_get_byte(&buf) != 'M') {
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
60 av_log(avctx, AV_LOG_ERROR, "bad magic number\n");
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
61 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
62 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
63
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
64 fsize = bytestream_get_le32(&buf);
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
65 if(buf_size < fsize){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
66 av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n",
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
67 buf_size, fsize);
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
68 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
69 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
70
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
71 buf += 2; /* reserved1 */
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
72 buf += 2; /* reserved2 */
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
73
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
74 hsize = bytestream_get_le32(&buf); /* header size */
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
75 if(fsize <= hsize){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
76 av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n",
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
77 fsize, hsize);
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
78 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
79 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
80
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
81 ihsize = bytestream_get_le32(&buf); /* more header size */
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
82 if(ihsize + 14 > hsize){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
83 av_log(avctx, AV_LOG_ERROR, "invalid header size %d\n", hsize);
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
84 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
85 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
86
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
87 width = bytestream_get_le32(&buf);
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
88 height = bytestream_get_le32(&buf);
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
89
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
90 if(bytestream_get_le16(&buf) != 1){ /* planes */
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
91 av_log(avctx, AV_LOG_ERROR, "invalid BMP header\n");
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
92 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
93 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
94
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
95 depth = bytestream_get_le16(&buf);
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
96
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
97 if(ihsize > 16)
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
98 comp = bytestream_get_le32(&buf);
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
99 else
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
100 comp = BMP_RGB;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
101
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
102 if(comp != BMP_RGB && comp != BMP_BITFIELDS){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
103 av_log(avctx, AV_LOG_ERROR, "BMP coding %d not supported\n", comp);
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
104 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
105 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
106
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
107 if(comp == BMP_BITFIELDS){
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
108 buf += 20;
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
109 rgb[0] = bytestream_get_le32(&buf);
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
110 rgb[1] = bytestream_get_le32(&buf);
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
111 rgb[2] = bytestream_get_le32(&buf);
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
112 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
113
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
114 avctx->width = width;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
115 avctx->height = height > 0? height: -height;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
116
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
117 avctx->pix_fmt = PIX_FMT_NONE;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
118
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
119 switch(depth){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
120 case 32:
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
121 if(comp == BMP_BITFIELDS){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
122 rgb[0] = (rgb[0] >> 15) & 3;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
123 rgb[1] = (rgb[1] >> 15) & 3;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
124 rgb[2] = (rgb[2] >> 15) & 3;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
125
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
126 if(rgb[0] + rgb[1] + rgb[2] != 3 ||
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
127 rgb[0] == rgb[1] || rgb[0] == rgb[2] || rgb[1] == rgb[2]){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
128 break;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
129 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
130 } else {
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
131 rgb[0] = 2;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
132 rgb[1] = 1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
133 rgb[2] = 0;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
134 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
135
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
136 avctx->pix_fmt = PIX_FMT_BGR24;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
137 break;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
138 case 24:
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
139 avctx->pix_fmt = PIX_FMT_BGR24;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
140 break;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
141 case 16:
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
142 if(comp == BMP_RGB)
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
143 avctx->pix_fmt = PIX_FMT_RGB555;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
144 break;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
145 default:
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
146 av_log(avctx, AV_LOG_ERROR, "depth %d not supported\n", depth);
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
147 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
148 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
149
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
150 if(avctx->pix_fmt == PIX_FMT_NONE){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
151 av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
152 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
153 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
154
4432
a848b652f0ac Fix segfault in bmp decoder. Patch by Michel Bardiaux mbardiaux mediaxim dot be.
takis
parents: 4415
diff changeset
155 if(p->data[0])
a848b652f0ac Fix segfault in bmp decoder. Patch by Michel Bardiaux mbardiaux mediaxim dot be.
takis
parents: 4415
diff changeset
156 avctx->release_buffer(avctx, p);
a848b652f0ac Fix segfault in bmp decoder. Patch by Michel Bardiaux mbardiaux mediaxim dot be.
takis
parents: 4415
diff changeset
157
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
158 p->reference = 0;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
159 if(avctx->get_buffer(avctx, p) < 0){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
160 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
161 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
162 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
163 p->pict_type = FF_I_TYPE;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
164 p->key_frame = 1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
165
4439
3af19e140d67 Make BMP decoder use bytestream. Patch by Michel Bardiaux
takis
parents: 4432
diff changeset
166 buf = buf0 + hsize;
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
167 dsize = buf_size - hsize;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
168
4109
a90490a13ac4 coded line size is a multiple of 4
mru
parents: 3947
diff changeset
169 /* Line size in file multiple of 4 */
a90490a13ac4 coded line size is a multiple of 4
mru
parents: 3947
diff changeset
170 n = (avctx->width * (depth / 8) + 3) & ~3;
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
171
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
172 if(n * avctx->height > dsize){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
173 av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n",
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
174 dsize, n * avctx->height);
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
175 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
176 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
177
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
178 if(height > 0){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
179 ptr = p->data[0] + (avctx->height - 1) * p->linesize[0];
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
180 linesize = -p->linesize[0];
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
181 } else {
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
182 ptr = p->data[0];
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
183 linesize = p->linesize[0];
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
184 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
185
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
186 switch(depth){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
187 case 24:
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
188 for(i = 0; i < avctx->height; i++){
4445
fc9a42d0e848 Fix memcpy out-of-bounds.
diego
parents: 4439
diff changeset
189 memcpy(ptr, buf, avctx->width*(depth>>3));
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
190 buf += n;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
191 ptr += linesize;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
192 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
193 break;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
194 case 16:
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
195 for(i = 0; i < avctx->height; i++){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
196 uint16_t *src = (uint16_t *) buf;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
197 uint16_t *dst = (uint16_t *) ptr;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
198
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
199 for(j = 0; j < avctx->width; j++)
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
200 *dst++ = le2me_16(*src++);
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
201
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
202 buf += n;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
203 ptr += linesize;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
204 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
205 break;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
206 case 32:
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
207 for(i = 0; i < avctx->height; i++){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
208 uint8_t *src = buf;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
209 uint8_t *dst = ptr;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
210
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
211 for(j = 0; j < avctx->width; j++){
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
212 dst[0] = src[rgb[2]];
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
213 dst[1] = src[rgb[1]];
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
214 dst[2] = src[rgb[0]];
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
215 dst += 3;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
216 src += 4;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
217 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
218
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
219 buf += n;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
220 ptr += linesize;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
221 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
222 break;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
223 default:
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
224 av_log(avctx, AV_LOG_ERROR, "BMP decoder is broken\n");
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
225 return -1;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
226 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
227
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
228 *picture = s->picture;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
229 *data_size = sizeof(AVPicture);
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
230
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
231 return buf_size;
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
232 }
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
233
4455
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
234 static int bmp_decode_end(AVCodecContext *avctx)
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
235 {
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
236 BMPContext* c = avctx->priv_data;
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
237
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
238 if (c->picture.data[0])
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
239 avctx->release_buffer(avctx, &c->picture);
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
240
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
241 return 0;
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
242 }
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
243
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
244 AVCodec bmp_decoder = {
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
245 "bmp",
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
246 CODEC_TYPE_VIDEO,
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
247 CODEC_ID_BMP,
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
248 sizeof(BMPContext),
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
249 bmp_decode_init,
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
250 NULL,
4455
8ecfb7ecbb53 Add decode_end method to bmp decoder. Patch by Michel Bardiaux,
takis
parents: 4445
diff changeset
251 bmp_decode_end,
2949
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
252 bmp_decode_frame
e5a10ae14ffb BMP image decoder
mru
parents:
diff changeset
253 };