comparison msrle.c @ 1630:586b5c08863c libavcodec

- Add reget_buffer() function to AVCodecContext - Add default reget_buffer implementation in libavcodec/utils.c - Remove AVCodecContext.cr_available, no longer needed - Remove CODEC_CAP_CR, no longer used - Add img_copy() prototype to avcodec.h (function from imgconvert.c) - Rename img_copy() to jpeg_img_copy() in libavformat/jpeg.c to avoid conflict - Updated msrle, msvideo1, rpza, smc to use reget_buffer
author rtognimp
date Wed, 26 Nov 2003 20:57:15 +0000
parents 7f4d1ab4ac17
children 1514fd5d434b
comparison
equal deleted inserted replaced
1629:74685a0ec851 1630:586b5c08863c
39 #include "dsputil.h" 39 #include "dsputil.h"
40 40
41 typedef struct MsrleContext { 41 typedef struct MsrleContext {
42 AVCodecContext *avctx; 42 AVCodecContext *avctx;
43 AVFrame frame; 43 AVFrame frame;
44 AVFrame prev_frame;
45 44
46 unsigned char *buf; 45 unsigned char *buf;
47 int size; 46 int size;
48 47
49 } MsrleContext; 48 } MsrleContext;
242 241
243 s->avctx = avctx; 242 s->avctx = avctx;
244 243
245 avctx->pix_fmt = PIX_FMT_PAL8; 244 avctx->pix_fmt = PIX_FMT_PAL8;
246 avctx->has_b_frames = 0; 245 avctx->has_b_frames = 0;
247 s->frame.data[0] = s->prev_frame.data[0] = NULL; 246 s->frame.data[0] = NULL;
248 247
249 return 0; 248 return 0;
250 } 249 }
251 250
252 static int msrle_decode_frame(AVCodecContext *avctx, 251 static int msrle_decode_frame(AVCodecContext *avctx,
261 260
262 s->buf = buf; 261 s->buf = buf;
263 s->size = buf_size; 262 s->size = buf_size;
264 263
265 s->frame.reference = 1; 264 s->frame.reference = 1;
266 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE; 265 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
267 if (avctx->cr_available) 266 if (avctx->reget_buffer(avctx, &s->frame)) {
268 s->frame.buffer_hints |= FF_BUFFER_HINTS_REUSABLE; 267 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
269 else
270 s->frame.buffer_hints |= FF_BUFFER_HINTS_READABLE;
271 if (avctx->get_buffer(avctx, &s->frame)) {
272 av_log(avctx, AV_LOG_ERROR, " MS RLE: get_buffer() failed\n");
273 return -1; 268 return -1;
274 } 269 }
275
276 if (s->prev_frame.data[0] && (s->frame.linesize[0] != s->prev_frame.linesize[0]))
277 av_log(avctx, AV_LOG_ERROR, " MS RLE: Buffer linesize changed: current %u, previous %u.\n"
278 " Expect wrong image and/or crash!\n",
279 s->frame.linesize[0], s->prev_frame.linesize[0]);
280
281 /* grossly inefficient, but...oh well */
282 if (s->prev_frame.data[0] != NULL)
283 memcpy(s->frame.data[0], s->prev_frame.data[0],
284 s->frame.linesize[0] * s->avctx->height);
285 270
286 switch (avctx->bits_per_sample) { 271 switch (avctx->bits_per_sample) {
287 case 8: 272 case 8:
288 msrle_decode_pal8(s); 273 msrle_decode_pal8(s);
289 break; 274 break;
293 default: 278 default:
294 av_log(avctx, AV_LOG_ERROR, "Don't know how to decode depth %u.\n", 279 av_log(avctx, AV_LOG_ERROR, "Don't know how to decode depth %u.\n",
295 avctx->bits_per_sample); 280 avctx->bits_per_sample);
296 } 281 }
297 282
298 if (s->prev_frame.data[0])
299 avctx->release_buffer(avctx, &s->prev_frame);
300
301 /* shuffle frames */
302 if (!avctx->cr_available)
303 s->prev_frame = s->frame;
304
305 *data_size = sizeof(AVFrame); 283 *data_size = sizeof(AVFrame);
306 *(AVFrame*)data = s->frame; 284 *(AVFrame*)data = s->frame;
307 285
308 /* report that the buffer was completely consumed */ 286 /* report that the buffer was completely consumed */
309 return buf_size; 287 return buf_size;
312 static int msrle_decode_end(AVCodecContext *avctx) 290 static int msrle_decode_end(AVCodecContext *avctx)
313 { 291 {
314 MsrleContext *s = (MsrleContext *)avctx->priv_data; 292 MsrleContext *s = (MsrleContext *)avctx->priv_data;
315 293
316 /* release the last frame */ 294 /* release the last frame */
317 if (s->prev_frame.data[0]) 295 if (s->frame.data[0])
318 avctx->release_buffer(avctx, &s->prev_frame); 296 avctx->release_buffer(avctx, &s->frame);
319 297
320 return 0; 298 return 0;
321 } 299 }
322 300
323 AVCodec msrle_decoder = { 301 AVCodec msrle_decoder = {
327 sizeof(MsrleContext), 305 sizeof(MsrleContext),
328 msrle_decode_init, 306 msrle_decode_init,
329 NULL, 307 NULL,
330 msrle_decode_end, 308 msrle_decode_end,
331 msrle_decode_frame, 309 msrle_decode_frame,
332 CODEC_CAP_DR1 | CODEC_CAP_CR, 310 CODEC_CAP_DR1,
333 }; 311 };