Mercurial > libavcodec.hg
comparison lcldec.c @ 5297:fc46b3f5de1a libavcodec
indent
author | mru |
---|---|
date | Thu, 12 Jul 2007 22:55:35 +0000 |
parents | 01e09790f4e6 |
children | dfdff1ca78a7 |
comparison
equal
deleted
inserted
replaced
5296:01e09790f4e6 | 5297:fc46b3f5de1a |
---|---|
51 | 51 |
52 /* | 52 /* |
53 * Decoder context | 53 * Decoder context |
54 */ | 54 */ |
55 typedef struct LclDecContext { | 55 typedef struct LclDecContext { |
56 AVFrame pic; | 56 AVFrame pic; |
57 | 57 |
58 // Image type | 58 // Image type |
59 int imgtype; | 59 int imgtype; |
60 // Compression type | 60 // Compression type |
61 int compression; | 61 int compression; |
161 * Decode a frame | 161 * Decode a frame |
162 * | 162 * |
163 */ | 163 */ |
164 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) | 164 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) |
165 { | 165 { |
166 LclDecContext * const c = avctx->priv_data; | 166 LclDecContext * const c = avctx->priv_data; |
167 unsigned char *encoded = (unsigned char *)buf; | 167 unsigned char *encoded = (unsigned char *)buf; |
168 unsigned int pixel_ptr; | 168 unsigned int pixel_ptr; |
169 int row, col; | 169 int row, col; |
170 unsigned char *outptr; | 170 unsigned char *outptr; |
171 unsigned int width = avctx->width; // Real image width | 171 unsigned int width = avctx->width; // Real image width |
172 unsigned int height = avctx->height; // Real image height | 172 unsigned int height = avctx->height; // Real image height |
177 #ifdef CONFIG_ZLIB | 177 #ifdef CONFIG_ZLIB |
178 int zret; // Zlib return code | 178 int zret; // Zlib return code |
179 #endif | 179 #endif |
180 unsigned int len = buf_size; | 180 unsigned int len = buf_size; |
181 | 181 |
182 if(c->pic.data[0]) | 182 if(c->pic.data[0]) |
183 avctx->release_buffer(avctx, &c->pic); | 183 avctx->release_buffer(avctx, &c->pic); |
184 | 184 |
185 c->pic.reference = 0; | 185 c->pic.reference = 0; |
186 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; | 186 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; |
187 if(avctx->get_buffer(avctx, &c->pic) < 0){ | 187 if(avctx->get_buffer(avctx, &c->pic) < 0){ |
188 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | 188 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
189 return -1; | 189 return -1; |
190 } | 190 } |
191 | 191 |
192 outptr = c->pic.data[0]; // Output image pointer | 192 outptr = c->pic.data[0]; // Output image pointer |
193 | 193 |
194 /* Decompress frame */ | 194 /* Decompress frame */ |
195 switch (avctx->codec_id) { | 195 switch (avctx->codec_id) { |
196 case CODEC_ID_MSZH: | 196 case CODEC_ID_MSZH: |
197 switch (c->compression) { | 197 switch (c->compression) { |
198 case COMP_MSZH: | 198 case COMP_MSZH: |
199 if (c->flags & FLAG_MULTITHREAD) { | |
200 mthread_inlen = *((unsigned int*)encoded); | |
201 mthread_outlen = *((unsigned int*)(encoded+4)); | |
202 if (mthread_outlen > c->decomp_size) // this should not happen | |
203 mthread_outlen = c->decomp_size; | |
204 mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size); | |
205 if (mthread_outlen != mszh_dlen) { | |
206 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", | |
207 mthread_outlen, mszh_dlen); | |
208 return -1; | |
209 } | |
210 mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen, | |
211 c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); | |
212 if (mthread_outlen != mszh_dlen) { | |
213 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", | |
214 mthread_outlen, mszh_dlen); | |
215 return -1; | |
216 } | |
217 encoded = c->decomp_buf; | |
218 len = c->decomp_size; | |
219 } else { | |
220 mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size); | |
221 if (c->decomp_size != mszh_dlen) { | |
222 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", | |
223 c->decomp_size, mszh_dlen); | |
224 return -1; | |
225 } | |
226 encoded = c->decomp_buf; | |
227 len = mszh_dlen; | |
228 } | |
229 break; | |
230 case COMP_MSZH_NOCOMP: | |
231 break; | |
232 default: | |
233 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); | |
234 return -1; | |
235 } | |
236 break; | |
237 case CODEC_ID_ZLIB: | |
238 #ifdef CONFIG_ZLIB | |
239 /* Using the original dll with normal compression (-1) and RGB format | |
240 * gives a file with ZLIB fourcc, but frame is really uncompressed. | |
241 * To be sure that's true check also frame size */ | |
242 if ((c->compression == COMP_ZLIB_NORMAL) && (c->imgtype == IMGTYPE_RGB24) && | |
243 (len == width * height * 3)) | |
244 break; | |
245 zret = inflateReset(&(c->zstream)); | |
246 if (zret != Z_OK) { | |
247 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); | |
248 return -1; | |
249 } | |
250 if (c->flags & FLAG_MULTITHREAD) { | 199 if (c->flags & FLAG_MULTITHREAD) { |
251 mthread_inlen = *((unsigned int*)encoded); | 200 mthread_inlen = *((unsigned int*)encoded); |
252 mthread_outlen = *((unsigned int*)(encoded+4)); | 201 mthread_outlen = *((unsigned int*)(encoded+4)); |
253 if (mthread_outlen > c->decomp_size) | 202 if (mthread_outlen > c->decomp_size) // this should not happen |
254 mthread_outlen = c->decomp_size; | 203 mthread_outlen = c->decomp_size; |
255 c->zstream.next_in = encoded + 8; | 204 mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size); |
256 c->zstream.avail_in = mthread_inlen; | 205 if (mthread_outlen != mszh_dlen) { |
257 c->zstream.next_out = c->decomp_buf; | 206 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", |
258 c->zstream.avail_out = c->decomp_size; | 207 mthread_outlen, mszh_dlen); |
259 zret = inflate(&(c->zstream), Z_FINISH); | |
260 if ((zret != Z_OK) && (zret != Z_STREAM_END)) { | |
261 av_log(avctx, AV_LOG_ERROR, "Mthread1 inflate error: %d\n", zret); | |
262 return -1; | 208 return -1; |
263 } | 209 } |
264 if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { | 210 mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen, |
265 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%u != %lu)\n", | 211 c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); |
266 mthread_outlen, c->zstream.total_out); | 212 if (mthread_outlen != mszh_dlen) { |
213 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", | |
214 mthread_outlen, mszh_dlen); | |
267 return -1; | 215 return -1; |
268 } | 216 } |
269 zret = inflateReset(&(c->zstream)); | 217 encoded = c->decomp_buf; |
270 if (zret != Z_OK) { | 218 len = c->decomp_size; |
271 av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate reset error: %d\n", zret); | 219 } else { |
220 mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size); | |
221 if (c->decomp_size != mszh_dlen) { | |
222 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", | |
223 c->decomp_size, mszh_dlen); | |
272 return -1; | 224 return -1; |
273 } | 225 } |
274 c->zstream.next_in = encoded + 8 + mthread_inlen; | 226 encoded = c->decomp_buf; |
275 c->zstream.avail_in = len - mthread_inlen; | 227 len = mszh_dlen; |
276 c->zstream.next_out = c->decomp_buf + mthread_outlen; | 228 } |
277 c->zstream.avail_out = c->decomp_size - mthread_outlen; | 229 break; |
278 zret = inflate(&(c->zstream), Z_FINISH); | 230 case COMP_MSZH_NOCOMP: |
279 if ((zret != Z_OK) && (zret != Z_STREAM_END)) { | 231 break; |
280 av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate error: %d\n", zret); | 232 default: |
281 return -1; | 233 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); |
282 } | 234 return -1; |
283 if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { | 235 } |
284 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %lu)\n", | 236 break; |
285 mthread_outlen, c->zstream.total_out); | 237 case CODEC_ID_ZLIB: |
286 return -1; | 238 #ifdef CONFIG_ZLIB |
287 } | 239 /* Using the original dll with normal compression (-1) and RGB format |
288 } else { | 240 * gives a file with ZLIB fourcc, but frame is really uncompressed. |
289 c->zstream.next_in = encoded; | 241 * To be sure that's true check also frame size */ |
290 c->zstream.avail_in = len; | 242 if ((c->compression == COMP_ZLIB_NORMAL) && (c->imgtype == IMGTYPE_RGB24) && |
291 c->zstream.next_out = c->decomp_buf; | 243 (len == width * height * 3)) |
292 c->zstream.avail_out = c->decomp_size; | 244 break; |
293 zret = inflate(&(c->zstream), Z_FINISH); | 245 zret = inflateReset(&(c->zstream)); |
294 if ((zret != Z_OK) && (zret != Z_STREAM_END)) { | 246 if (zret != Z_OK) { |
295 av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); | 247 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); |
296 return -1; | 248 return -1; |
297 } | 249 } |
298 if (c->decomp_size != (unsigned int)(c->zstream.total_out)) { | 250 if (c->flags & FLAG_MULTITHREAD) { |
299 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", | 251 mthread_inlen = *((unsigned int*)encoded); |
300 c->decomp_size, c->zstream.total_out); | 252 mthread_outlen = *((unsigned int*)(encoded+4)); |
301 return -1; | 253 if (mthread_outlen > c->decomp_size) |
302 } | 254 mthread_outlen = c->decomp_size; |
303 } | 255 c->zstream.next_in = encoded + 8; |
304 encoded = c->decomp_buf; | 256 c->zstream.avail_in = mthread_inlen; |
305 len = c->decomp_size;; | 257 c->zstream.next_out = c->decomp_buf; |
258 c->zstream.avail_out = c->decomp_size; | |
259 zret = inflate(&(c->zstream), Z_FINISH); | |
260 if ((zret != Z_OK) && (zret != Z_STREAM_END)) { | |
261 av_log(avctx, AV_LOG_ERROR, "Mthread1 inflate error: %d\n", zret); | |
262 return -1; | |
263 } | |
264 if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { | |
265 av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%u != %lu)\n", | |
266 mthread_outlen, c->zstream.total_out); | |
267 return -1; | |
268 } | |
269 zret = inflateReset(&(c->zstream)); | |
270 if (zret != Z_OK) { | |
271 av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate reset error: %d\n", zret); | |
272 return -1; | |
273 } | |
274 c->zstream.next_in = encoded + 8 + mthread_inlen; | |
275 c->zstream.avail_in = len - mthread_inlen; | |
276 c->zstream.next_out = c->decomp_buf + mthread_outlen; | |
277 c->zstream.avail_out = c->decomp_size - mthread_outlen; | |
278 zret = inflate(&(c->zstream), Z_FINISH); | |
279 if ((zret != Z_OK) && (zret != Z_STREAM_END)) { | |
280 av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate error: %d\n", zret); | |
281 return -1; | |
282 } | |
283 if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { | |
284 av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %lu)\n", | |
285 mthread_outlen, c->zstream.total_out); | |
286 return -1; | |
287 } | |
288 } else { | |
289 c->zstream.next_in = encoded; | |
290 c->zstream.avail_in = len; | |
291 c->zstream.next_out = c->decomp_buf; | |
292 c->zstream.avail_out = c->decomp_size; | |
293 zret = inflate(&(c->zstream), Z_FINISH); | |
294 if ((zret != Z_OK) && (zret != Z_STREAM_END)) { | |
295 av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); | |
296 return -1; | |
297 } | |
298 if (c->decomp_size != (unsigned int)(c->zstream.total_out)) { | |
299 av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", | |
300 c->decomp_size, c->zstream.total_out); | |
301 return -1; | |
302 } | |
303 } | |
304 encoded = c->decomp_buf; | |
305 len = c->decomp_size;; | |
306 #else | 306 #else |
307 av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n"); | 307 av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n"); |
308 return -1; | 308 return -1; |
309 #endif | 309 #endif |
310 break; | 310 break; |
311 default: | 311 default: |
312 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); | 312 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); |
313 return -1; | 313 return -1; |
314 } | 314 } |
315 | 315 |
316 | 316 |
317 /* Apply PNG filter */ | 317 /* Apply PNG filter */ |
318 if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) { | 318 if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) { |
319 switch (c->imgtype) { | 319 switch (c->imgtype) { |
320 case IMGTYPE_YUV111: | 320 case IMGTYPE_YUV111: |
321 case IMGTYPE_RGB24: | 321 case IMGTYPE_RGB24: |
322 for (row = 0; row < height; row++) { | 322 for (row = 0; row < height; row++) { |
323 pixel_ptr = row * width * 3; | 323 pixel_ptr = row * width * 3; |
324 yq = encoded[pixel_ptr++]; | 324 yq = encoded[pixel_ptr++]; |
325 uqvq = AV_RL16(encoded+pixel_ptr); | 325 uqvq = AV_RL16(encoded+pixel_ptr); |
326 pixel_ptr += 2; | 326 pixel_ptr += 2; |
327 for (col = 1; col < width; col++) { | 327 for (col = 1; col < width; col++) { |
328 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | 328 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; |
329 uqvq -= AV_RL16(encoded+pixel_ptr+1); | 329 uqvq -= AV_RL16(encoded+pixel_ptr+1); |
330 AV_WL16(encoded+pixel_ptr+1, uqvq); | 330 AV_WL16(encoded+pixel_ptr+1, uqvq); |
331 pixel_ptr += 3; | 331 pixel_ptr += 3; |
332 } | |
333 } | 332 } |
334 break; | 333 } |
335 case IMGTYPE_YUV422: | 334 break; |
336 for (row = 0; row < height; row++) { | 335 case IMGTYPE_YUV422: |
337 pixel_ptr = row * width * 2; | 336 for (row = 0; row < height; row++) { |
338 yq = uq = vq =0; | 337 pixel_ptr = row * width * 2; |
339 for (col = 0; col < width/4; col++) { | 338 yq = uq = vq =0; |
340 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | 339 for (col = 0; col < width/4; col++) { |
341 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | 340 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; |
342 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; | 341 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; |
343 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; | 342 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; |
344 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | 343 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; |
345 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5]; | 344 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; |
346 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6]; | 345 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5]; |
347 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7]; | 346 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6]; |
348 pixel_ptr += 8; | 347 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7]; |
349 } | 348 pixel_ptr += 8; |
350 } | 349 } |
351 break; | 350 } |
352 case IMGTYPE_YUV411: | 351 break; |
353 for (row = 0; row < height; row++) { | 352 case IMGTYPE_YUV411: |
354 pixel_ptr = row * width / 2 * 3; | 353 for (row = 0; row < height; row++) { |
355 yq = uq = vq =0; | 354 pixel_ptr = row * width / 2 * 3; |
356 for (col = 0; col < width/4; col++) { | 355 yq = uq = vq =0; |
357 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | 356 for (col = 0; col < width/4; col++) { |
358 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | 357 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; |
359 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; | 358 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; |
360 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; | 359 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; |
361 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | 360 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; |
362 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; | 361 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; |
363 pixel_ptr += 6; | 362 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; |
364 } | 363 pixel_ptr += 6; |
365 } | 364 } |
366 break; | 365 } |
367 case IMGTYPE_YUV211: | 366 break; |
368 for (row = 0; row < height; row++) { | 367 case IMGTYPE_YUV211: |
369 pixel_ptr = row * width * 2; | 368 for (row = 0; row < height; row++) { |
370 yq = uq = vq =0; | 369 pixel_ptr = row * width * 2; |
371 for (col = 0; col < width/2; col++) { | 370 yq = uq = vq =0; |
372 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | 371 for (col = 0; col < width/2; col++) { |
373 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | 372 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; |
374 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2]; | 373 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; |
375 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3]; | 374 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2]; |
376 pixel_ptr += 4; | 375 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3]; |
377 } | 376 pixel_ptr += 4; |
378 } | 377 } |
379 break; | 378 } |
380 case IMGTYPE_YUV420: | 379 break; |
381 for (row = 0; row < height/2; row++) { | 380 case IMGTYPE_YUV420: |
382 pixel_ptr = row * width * 3; | 381 for (row = 0; row < height/2; row++) { |
383 yq = y1q = uq = vq =0; | 382 pixel_ptr = row * width * 3; |
384 for (col = 0; col < width/2; col++) { | 383 yq = y1q = uq = vq =0; |
385 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; | 384 for (col = 0; col < width/2; col++) { |
386 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; | 385 encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; |
387 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2]; | 386 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; |
388 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3]; | 387 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2]; |
389 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; | 388 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3]; |
390 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; | 389 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; |
391 pixel_ptr += 6; | 390 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; |
392 } | 391 pixel_ptr += 6; |
393 } | 392 } |
394 break; | 393 } |
395 default: | 394 break; |
396 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); | 395 default: |
397 return -1; | 396 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); |
397 return -1; | |
398 } | 398 } |
399 } | 399 } |
400 | 400 |
401 /* Convert colorspace */ | 401 /* Convert colorspace */ |
402 switch (c->imgtype) { | 402 switch (c->imgtype) { |
403 case IMGTYPE_YUV111: | 403 case IMGTYPE_YUV111: |
404 for (row = height - 1; row >= 0; row--) { | 404 for (row = height - 1; row >= 0; row--) { |
405 pixel_ptr = row * c->pic.linesize[0]; | 405 pixel_ptr = row * c->pic.linesize[0]; |
406 for (col = 0; col < width; col++) { | 406 for (col = 0; col < width; col++) { |
407 outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]); | 407 outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]); |
408 outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]); | 408 outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]); |
409 outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]); | 409 outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]); |
410 encoded += 3; | 410 encoded += 3; |
411 } | 411 } |
412 } | 412 } |
413 break; | 413 break; |
414 case IMGTYPE_YUV422: | 414 case IMGTYPE_YUV422: |
415 for (row = height - 1; row >= 0; row--) { | 415 for (row = height - 1; row >= 0; row--) { |
416 pixel_ptr = row * c->pic.linesize[0]; | 416 pixel_ptr = row * c->pic.linesize[0]; |
417 for (col = 0; col < width/4; col++) { | 417 for (col = 0; col < width/4; col++) { |
418 outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); | 418 outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); |
419 outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]); | 419 outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]); |
420 outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]); | 420 outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]); |
421 outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); | 421 outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); |
422 outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]); | 422 outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]); |
423 outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]); | 423 outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]); |
424 outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]); | 424 outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]); |
425 outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]); | 425 outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]); |
426 outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]); | 426 outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]); |
427 outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]); | 427 outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]); |
428 outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]); | 428 outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]); |
429 outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]); | 429 outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]); |
430 encoded += 8; | 430 encoded += 8; |
431 } | 431 } |
432 } | 432 } |
433 break; | 433 break; |
434 case IMGTYPE_RGB24: | 434 case IMGTYPE_RGB24: |
435 for (row = height - 1; row >= 0; row--) { | 435 for (row = height - 1; row >= 0; row--) { |
436 pixel_ptr = row * c->pic.linesize[0]; | 436 pixel_ptr = row * c->pic.linesize[0]; |
437 for (col = 0; col < width; col++) { | 437 for (col = 0; col < width; col++) { |
438 outptr[pixel_ptr++] = encoded[0]; | 438 outptr[pixel_ptr++] = encoded[0]; |
439 outptr[pixel_ptr++] = encoded[1]; | 439 outptr[pixel_ptr++] = encoded[1]; |
440 outptr[pixel_ptr++] = encoded[2]; | 440 outptr[pixel_ptr++] = encoded[2]; |
441 encoded += 3; | 441 encoded += 3; |
442 } | 442 } |
443 } | 443 } |
444 break; | 444 break; |
445 case IMGTYPE_YUV411: | 445 case IMGTYPE_YUV411: |
446 for (row = height - 1; row >= 0; row--) { | 446 for (row = height - 1; row >= 0; row--) { |
447 pixel_ptr = row * c->pic.linesize[0]; | 447 pixel_ptr = row * c->pic.linesize[0]; |
448 for (col = 0; col < width/4; col++) { | 448 for (col = 0; col < width/4; col++) { |
449 outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); | 449 outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); |
450 outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]); | 450 outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]); |
451 outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]); | 451 outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]); |
452 outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); | 452 outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); |
453 outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]); | 453 outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]); |
454 outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]); | 454 outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]); |
455 outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]); | 455 outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]); |
456 outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]); | 456 outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]); |
457 outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]); | 457 outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]); |
458 outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]); | 458 outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]); |
459 outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]); | 459 outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]); |
460 outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]); | 460 outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]); |
461 encoded += 6; | 461 encoded += 6; |
462 } | 462 } |
463 } | 463 } |
464 break; | 464 break; |
465 case IMGTYPE_YUV211: | 465 case IMGTYPE_YUV211: |
466 for (row = height - 1; row >= 0; row--) { | 466 for (row = height - 1; row >= 0; row--) { |
467 pixel_ptr = row * c->pic.linesize[0]; | 467 pixel_ptr = row * c->pic.linesize[0]; |
468 for (col = 0; col < width/2; col++) { | 468 for (col = 0; col < width/2; col++) { |
469 outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]); | 469 outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]); |
470 outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]); | 470 outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]); |
471 outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]); | 471 outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]); |
472 outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]); | 472 outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]); |
473 outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]); | 473 outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]); |
474 outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]); | 474 outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]); |
475 encoded += 4; | 475 encoded += 4; |
476 } | 476 } |
477 } | 477 } |
478 break; | 478 break; |
479 case IMGTYPE_YUV420: | 479 case IMGTYPE_YUV420: |
480 for (row = height / 2 - 1; row >= 0; row--) { | 480 for (row = height / 2 - 1; row >= 0; row--) { |
481 pixel_ptr = 2 * row * c->pic.linesize[0]; | 481 pixel_ptr = 2 * row * c->pic.linesize[0]; |
482 for (col = 0; col < width/2; col++) { | 482 for (col = 0; col < width/2; col++) { |
483 outptr[pixel_ptr] = get_b(encoded[0], encoded[4]); | 483 outptr[pixel_ptr] = get_b(encoded[0], encoded[4]); |
484 outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]); | 484 outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]); |
485 outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]); | 485 outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]); |
486 outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]); | 486 outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]); |
487 outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]); | 487 outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]); |
488 outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]); | 488 outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]); |
489 outptr[pixel_ptr-c->pic.linesize[0]] = get_b(encoded[2], encoded[4]); | 489 outptr[pixel_ptr-c->pic.linesize[0]] = get_b(encoded[2], encoded[4]); |
490 outptr[pixel_ptr-c->pic.linesize[0]+1] = get_g(encoded[2], encoded[4], encoded[5]); | 490 outptr[pixel_ptr-c->pic.linesize[0]+1] = get_g(encoded[2], encoded[4], encoded[5]); |
491 outptr[pixel_ptr-c->pic.linesize[0]+2] = get_r(encoded[2], encoded[5]); | 491 outptr[pixel_ptr-c->pic.linesize[0]+2] = get_r(encoded[2], encoded[5]); |
492 outptr[pixel_ptr-c->pic.linesize[0]+3] = get_b(encoded[3], encoded[4]); | 492 outptr[pixel_ptr-c->pic.linesize[0]+3] = get_b(encoded[3], encoded[4]); |
493 outptr[pixel_ptr-c->pic.linesize[0]+4] = get_g(encoded[3], encoded[4], encoded[5]); | 493 outptr[pixel_ptr-c->pic.linesize[0]+4] = get_g(encoded[3], encoded[4], encoded[5]); |
494 outptr[pixel_ptr-c->pic.linesize[0]+5] = get_r(encoded[3], encoded[5]); | 494 outptr[pixel_ptr-c->pic.linesize[0]+5] = get_r(encoded[3], encoded[5]); |
495 pixel_ptr += 6; | 495 pixel_ptr += 6; |
496 encoded += 6; | 496 encoded += 6; |
497 } | 497 } |
498 } | 498 } |
499 break; | 499 break; |
500 default: | 500 default: |
501 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); | 501 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); |
502 return -1; | 502 return -1; |
503 } | 503 } |
504 | 504 |
505 *data_size = sizeof(AVFrame); | 505 *data_size = sizeof(AVFrame); |
506 *(AVFrame*)data = c->pic; | 506 *(AVFrame*)data = c->pic; |
507 | 507 |
544 av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n"); | 544 av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n"); |
545 } | 545 } |
546 | 546 |
547 /* Detect image type */ | 547 /* Detect image type */ |
548 switch (c->imgtype = *((char *)avctx->extradata + 4)) { | 548 switch (c->imgtype = *((char *)avctx->extradata + 4)) { |
549 case IMGTYPE_YUV111: | 549 case IMGTYPE_YUV111: |
550 c->decomp_size = basesize * 3; | 550 c->decomp_size = basesize * 3; |
551 max_decomp_size = max_basesize * 3; | 551 max_decomp_size = max_basesize * 3; |
552 av_log(avctx, AV_LOG_INFO, "Image type is YUV 1:1:1.\n"); | 552 av_log(avctx, AV_LOG_INFO, "Image type is YUV 1:1:1.\n"); |
553 break; | 553 break; |
554 case IMGTYPE_YUV422: | 554 case IMGTYPE_YUV422: |
555 c->decomp_size = basesize * 2; | 555 c->decomp_size = basesize * 2; |
556 max_decomp_size = max_basesize * 2; | 556 max_decomp_size = max_basesize * 2; |
557 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:2.\n"); | 557 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:2.\n"); |
558 break; | 558 break; |
559 case IMGTYPE_RGB24: | 559 case IMGTYPE_RGB24: |
560 c->decomp_size = basesize * 3; | 560 c->decomp_size = basesize * 3; |
561 max_decomp_size = max_basesize * 3; | 561 max_decomp_size = max_basesize * 3; |
562 av_log(avctx, AV_LOG_INFO, "Image type is RGB 24.\n"); | 562 av_log(avctx, AV_LOG_INFO, "Image type is RGB 24.\n"); |
563 break; | 563 break; |
564 case IMGTYPE_YUV411: | 564 case IMGTYPE_YUV411: |
565 c->decomp_size = basesize / 2 * 3; | 565 c->decomp_size = basesize / 2 * 3; |
566 max_decomp_size = max_basesize / 2 * 3; | 566 max_decomp_size = max_basesize / 2 * 3; |
567 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:1:1.\n"); | 567 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:1:1.\n"); |
568 break; | 568 break; |
569 case IMGTYPE_YUV211: | 569 case IMGTYPE_YUV211: |
570 c->decomp_size = basesize * 2; | 570 c->decomp_size = basesize * 2; |
571 max_decomp_size = max_basesize * 2; | 571 max_decomp_size = max_basesize * 2; |
572 av_log(avctx, AV_LOG_INFO, "Image type is YUV 2:1:1.\n"); | 572 av_log(avctx, AV_LOG_INFO, "Image type is YUV 2:1:1.\n"); |
573 break; | 573 break; |
574 case IMGTYPE_YUV420: | 574 case IMGTYPE_YUV420: |
575 c->decomp_size = basesize / 2 * 3; | 575 c->decomp_size = basesize / 2 * 3; |
576 max_decomp_size = max_basesize / 2 * 3; | 576 max_decomp_size = max_basesize / 2 * 3; |
577 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:0.\n"); | 577 av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:0.\n"); |
578 break; | 578 break; |
579 default: | 579 default: |
580 av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype); | 580 av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype); |
581 return 1; | 581 return 1; |
582 } | 582 } |
583 | 583 |
584 /* Detect compression method */ | 584 /* Detect compression method */ |
585 c->compression = *((char *)avctx->extradata + 5); | 585 c->compression = *((char *)avctx->extradata + 5); |
586 switch (avctx->codec_id) { | 586 switch (avctx->codec_id) { |
587 case CODEC_ID_MSZH: | 587 case CODEC_ID_MSZH: |
588 switch (c->compression) { | 588 switch (c->compression) { |
589 case COMP_MSZH: | 589 case COMP_MSZH: |
590 av_log(avctx, AV_LOG_INFO, "Compression enabled.\n"); | 590 av_log(avctx, AV_LOG_INFO, "Compression enabled.\n"); |
591 break; | 591 break; |
592 case COMP_MSZH_NOCOMP: | 592 case COMP_MSZH_NOCOMP: |
593 c->decomp_size = 0; | 593 c->decomp_size = 0; |
594 av_log(avctx, AV_LOG_INFO, "No compression.\n"); | 594 av_log(avctx, AV_LOG_INFO, "No compression.\n"); |
595 break; | 595 break; |
596 default: | 596 default: |
597 av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression); | 597 av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression); |
598 return 1; | 598 return 1; |
599 } | 599 } |
600 break; | 600 break; |
601 case CODEC_ID_ZLIB: | 601 case CODEC_ID_ZLIB: |
602 #ifdef CONFIG_ZLIB | 602 #ifdef CONFIG_ZLIB |
603 switch (c->compression) { | 603 switch (c->compression) { |
604 case COMP_ZLIB_HISPEED: | 604 case COMP_ZLIB_HISPEED: |
605 av_log(avctx, AV_LOG_INFO, "High speed compression.\n"); | 605 av_log(avctx, AV_LOG_INFO, "High speed compression.\n"); |
606 break; | 606 break; |
607 case COMP_ZLIB_HICOMP: | 607 case COMP_ZLIB_HICOMP: |
608 av_log(avctx, AV_LOG_INFO, "High compression.\n"); | 608 av_log(avctx, AV_LOG_INFO, "High compression.\n"); |
609 break; | 609 break; |
610 case COMP_ZLIB_NORMAL: | 610 case COMP_ZLIB_NORMAL: |
611 av_log(avctx, AV_LOG_INFO, "Normal compression.\n"); | 611 av_log(avctx, AV_LOG_INFO, "Normal compression.\n"); |
612 break; | 612 break; |
613 default: | 613 default: |
614 if ((c->compression < Z_NO_COMPRESSION) || (c->compression > Z_BEST_COMPRESSION)) { | 614 if ((c->compression < Z_NO_COMPRESSION) || (c->compression > Z_BEST_COMPRESSION)) { |
615 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); | 615 av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); |
616 return 1; | 616 return 1; |
617 } | 617 } |
618 av_log(avctx, AV_LOG_INFO, "Compression level for ZLIB: (%d).\n", c->compression); | 618 av_log(avctx, AV_LOG_INFO, "Compression level for ZLIB: (%d).\n", c->compression); |
619 } | 619 } |
620 #else | 620 #else |
621 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); | 621 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); |
622 return 1; | 622 return 1; |
623 #endif | 623 #endif |
624 break; | 624 break; |
625 default: | 625 default: |
626 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n"); | 626 av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n"); |
627 return 1; | 627 return 1; |
628 } | 628 } |
629 | 629 |
630 /* Allocate decompression buffer */ | 630 /* Allocate decompression buffer */ |
631 if (c->decomp_size) { | 631 if (c->decomp_size) { |
632 if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) { | 632 if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) { |
656 if (zret != Z_OK) { | 656 if (zret != Z_OK) { |
657 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); | 657 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); |
658 return 1; | 658 return 1; |
659 } | 659 } |
660 #else | 660 #else |
661 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); | 661 av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); |
662 return 1; | 662 return 1; |
663 #endif | 663 #endif |
664 } | 664 } |
665 | 665 |
666 avctx->pix_fmt = PIX_FMT_BGR24; | 666 avctx->pix_fmt = PIX_FMT_BGR24; |
667 | 667 |
673 * Uninit lcl decoder | 673 * Uninit lcl decoder |
674 * | 674 * |
675 */ | 675 */ |
676 static int decode_end(AVCodecContext *avctx) | 676 static int decode_end(AVCodecContext *avctx) |
677 { | 677 { |
678 LclDecContext * const c = avctx->priv_data; | 678 LclDecContext * const c = avctx->priv_data; |
679 | 679 |
680 if (c->pic.data[0]) | 680 if (c->pic.data[0]) |
681 avctx->release_buffer(avctx, &c->pic); | 681 avctx->release_buffer(avctx, &c->pic); |
682 #ifdef CONFIG_ZLIB | 682 #ifdef CONFIG_ZLIB |
683 inflateEnd(&(c->zstream)); | 683 inflateEnd(&(c->zstream)); |
684 #endif | 684 #endif |
685 | 685 |
686 return 0; | 686 return 0; |
687 } | 687 } |
688 | 688 |
689 #ifdef CONFIG_MSZH_DECODER | 689 #ifdef CONFIG_MSZH_DECODER |
690 AVCodec mszh_decoder = { | 690 AVCodec mszh_decoder = { |
691 "mszh", | 691 "mszh", |
692 CODEC_TYPE_VIDEO, | 692 CODEC_TYPE_VIDEO, |
693 CODEC_ID_MSZH, | 693 CODEC_ID_MSZH, |
694 sizeof(LclDecContext), | 694 sizeof(LclDecContext), |
695 decode_init, | 695 decode_init, |
696 NULL, | 696 NULL, |
697 decode_end, | 697 decode_end, |
698 decode_frame, | 698 decode_frame, |
699 CODEC_CAP_DR1, | 699 CODEC_CAP_DR1, |
700 }; | 700 }; |
701 #endif | 701 #endif |
702 | 702 |
703 #ifdef CONFIG_ZLIB_DECODER | 703 #ifdef CONFIG_ZLIB_DECODER |
704 AVCodec zlib_decoder = { | 704 AVCodec zlib_decoder = { |
705 "zlib", | 705 "zlib", |
706 CODEC_TYPE_VIDEO, | 706 CODEC_TYPE_VIDEO, |
707 CODEC_ID_ZLIB, | 707 CODEC_ID_ZLIB, |
708 sizeof(LclDecContext), | 708 sizeof(LclDecContext), |
709 decode_init, | 709 decode_init, |
710 NULL, | 710 NULL, |
711 decode_end, | 711 decode_end, |
712 decode_frame, | 712 decode_frame, |
713 CODEC_CAP_DR1, | 713 CODEC_CAP_DR1, |
714 }; | 714 }; |
715 #endif | 715 #endif |