Revision e40f5d3c

View differences:

libavcodec/flicvideo.c
1 1
/*
2 2
 * FLI/FLC Animation Video Decoder
3
 * Copyright (C) 2003 the ffmpeg project
3
 * Copyright (C) 2003, 2004 the ffmpeg project
4 4
 *
5 5
 * This library is free software; you can redistribute it and/or
6 6
 * modify it under the terms of the GNU Lesser General Public
......
60 60
typedef struct FlicDecodeContext {
61 61
    AVCodecContext *avctx;
62 62
    AVFrame frame;
63
    AVFrame prev_frame;
64 63

  
65 64
    unsigned int palette[256];
66 65
    int new_palette;
......
82 81
    } else if (s->avctx->extradata_size == 128) {
83 82
        s->fli_type = LE_16(&fli_header[4]);
84 83
    } else {
85
        printf (" FLI video: expected extradata of 12 or 128 bytes\n");
84
        av_log(avctx, AV_LOG_ERROR, "Expected extradata of 12 or 128 bytes\n");
86 85
        return -1;
87 86
    }
88 87

  
89
    s->frame.data[0] = s->prev_frame.data[0] = NULL;
88
    s->frame.data[0] = NULL;
90 89
    s->new_palette = 0;
91 90

  
92 91
    return 0;
......
126 125
    signed char byte_run;
127 126
    int pixel_skip;
128 127
    int pixel_countdown;
129
    int height_countdown;
130 128
    unsigned char *pixels;
131
    unsigned char *prev_pixels;
132 129

  
133 130
    s->frame.reference = 1;
134
    if (avctx->get_buffer(avctx, &s->frame) < 0) {
135
        fprintf(stderr, "  FLI: get_buffer() failed\n");
131
    s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
132
    if (avctx->reget_buffer(avctx, &s->frame) < 0) {
133
        av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
136 134
        return -1;
137 135
    }
138 136

  
139 137
    pixels = s->frame.data[0];
140
    prev_pixels = s->prev_frame.data[0];
141 138

  
142 139
    frame_size = LE_32(&buf[stream_ptr]);
143 140
    stream_ptr += 6;  /* skip the magic number */
......
146 143

  
147 144
    frame_size -= 16;
148 145

  
149
    /* if there is no data, copy previous frame */
150
    if (frame_size == 0) {
151
        memcpy(pixels, prev_pixels, s->frame.linesize[0] * s->avctx->height);
152
    }
153

  
154 146
    /* iterate through the chunks */
155 147
    while ((frame_size > 0) && (num_chunks > 0)) {
156 148
        chunk_size = LE_32(&buf[stream_ptr]);
......
210 202

  
211 203
        case FLI_DELTA:
212 204
            y_ptr = 0;
213
            height_countdown = s->avctx->height;
214 205
            compressed_lines = LE_16(&buf[stream_ptr]);
215 206
            stream_ptr += 2;
216 207
            while (compressed_lines > 0) {
......
218 209
                stream_ptr += 2;
219 210
                if (line_packets < 0) {
220 211
                    line_packets = -line_packets;
221
                    /* height_countdown was already decremented once on
222
                     * this iteration */
223
                    height_countdown -= line_packets;
224
                    /* copy the skipped lines from the previous frame */
225
                    while (line_packets--) {
226
                        memcpy(&pixels[y_ptr], &prev_pixels[y_ptr], 
227
                            s->avctx->width);
228
                        y_ptr += s->frame.linesize[0];
229
                    }
212
                    y_ptr += line_packets * s->frame.linesize[0];
230 213
                } else {
231
                    height_countdown--;
232 214
                    compressed_lines--;
233 215
                    pixel_ptr = y_ptr;
234 216
                    pixel_countdown = s->avctx->width;
235 217
                    for (i = 0; i < line_packets; i++) {
236 218
                        /* account for the skip bytes */
237 219
                        pixel_skip = buf[stream_ptr++];
238
                        memcpy(&pixels[pixel_ptr], &prev_pixels[pixel_ptr],
239
                            pixel_skip);
240 220
                        pixel_ptr += pixel_skip;
241 221
                        pixel_countdown -= pixel_skip;
242 222
                        byte_run = buf[stream_ptr++];
......
256 236
                        }
257 237
                    }
258 238

  
259
                    /* copy the remaining pixels in the line from the
260
                     * previous frame */
261
                    memcpy(&pixels[pixel_ptr], &prev_pixels[pixel_ptr],
262
                        pixel_countdown);
263

  
264 239
                    y_ptr += s->frame.linesize[0];
265 240
                }
266 241
            }
267

  
268
            /* copy the remainder of the lines from the previous frame */
269
            while (height_countdown--) {
270
                memcpy(&pixels[y_ptr], &prev_pixels[y_ptr], s->avctx->width);
271
                y_ptr += s->frame.linesize[0];
272
            }
273 242
            break;
274 243

  
275 244
        case FLI_LC:
276 245
            /* line compressed */
277
            height_countdown = s->avctx->height;
278 246
            starting_line = LE_16(&buf[stream_ptr]);
279 247
            stream_ptr += 2;
280

  
281
            /* copy from the previous frame all of the lines prior to the
282
             * starting line */
283 248
            y_ptr = 0;
284
            height_countdown -= starting_line;
285
            while (starting_line--) {
286
                memcpy(&pixels[y_ptr], &prev_pixels[y_ptr], s->avctx->width);
287
                y_ptr += s->frame.linesize[0];
288
            }
249
            y_ptr += starting_line * s->frame.linesize[0];
289 250

  
290 251
            compressed_lines = LE_16(&buf[stream_ptr]);
291 252
            stream_ptr += 2;
......
297 258
                    for (i = 0; i < line_packets; i++) {
298 259
                        /* account for the skip bytes */
299 260
                        pixel_skip = buf[stream_ptr++];
300
                        memcpy(&pixels[pixel_ptr],
301
                            &prev_pixels[pixel_ptr], pixel_skip);
302 261
                        pixel_ptr += pixel_skip;
303 262
                        pixel_countdown -= pixel_skip;
304 263
                        byte_run = buf[stream_ptr++];
......
317 276
                    }
318 277
                }
319 278

  
320
                /* copy the remainder of the line from the previous frame */
321
                memcpy(&pixels[pixel_ptr], &prev_pixels[pixel_ptr],
322
                    pixel_countdown);
323

  
324 279
                y_ptr += s->frame.linesize[0];
325 280
                compressed_lines--;
326
                height_countdown--;
327
            }
328

  
329
            /* copy the remainder of the lines from the previous frame */
330
            while (height_countdown--) {
331
                memcpy(&pixels[y_ptr], &prev_pixels[y_ptr], s->avctx->width);
332
                y_ptr += s->frame.linesize[0];
333 281
            }
334 282
            break;
335 283

  
......
357 305
                            pixels[pixel_ptr++] = palette_idx1;
358 306
                            pixel_countdown--;
359 307
                            if (pixel_countdown < 0)
360
                                printf ("fli warning: pixel_countdown < 0 (%d)\n",
361
                                    pixel_countdown);
308
                                av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
309
                                       pixel_countdown);
362 310
                        }
363 311
                    } else {  /* copy bytes if byte_run < 0 */
364 312
                        byte_run = -byte_run;
......
367 315
                            pixels[pixel_ptr++] = palette_idx1;
368 316
                            pixel_countdown--;
369 317
                            if (pixel_countdown < 0)
370
                                printf ("fli warning: pixel_countdown < 0 (%d)\n",
371
                                    pixel_countdown);
318
                                av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n",
319
                                       pixel_countdown);
372 320
                        }
373 321
                    }
374 322
                }
......
378 326
            break;
379 327

  
380 328
        case FLI_COPY:
381
            /* copy the chunk (uncompressed frame) to the ghost image and
382
             * schedule the whole frame to be updated */
329
            /* copy the chunk (uncompressed frame) */
383 330
            if (chunk_size - 6 > s->avctx->width * s->avctx->height) {
384
                printf(
385
                "FLI: in chunk FLI_COPY : source data (%d bytes) bigger than" \
386
                " image, skipping chunk\n",
387
                chunk_size - 6);
331
                av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \
332
                       "bigger than image, skipping chunk\n", chunk_size - 6);
388 333
                stream_ptr += chunk_size - 6;
389 334
            } else {
390 335
                for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;
......
402 347
            break;
403 348

  
404 349
        default:
405
            printf ("FLI: Unrecognized chunk type: %d\n", chunk_type);
350
            av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type);
406 351
            break;
407 352
        }
408 353

  
......
413 358
    /* by the end of the chunk, the stream ptr should equal the frame
414 359
     * size (minus 1, possibly); if it doesn't, issue a warning */
415 360
    if ((stream_ptr != buf_size) && (stream_ptr != buf_size - 1))
416
        printf ("  warning: processed FLI chunk where chunk size = %d\n" \
417
                "    and final chunk ptr = %d\n",
418
            buf_size, stream_ptr);
361
        av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
362
               "and final chunk ptr = %d\n", buf_size, stream_ptr);
419 363

  
420 364
    /* make the palette available on the way out */
421 365
//    if (s->new_palette) {
......
425 369
        s->new_palette = 0;
426 370
    }
427 371

  
428
    if (s->prev_frame.data[0])
429
        avctx->release_buffer(avctx, &s->prev_frame);
430

  
431
    /* shuffle frames */
432
    s->prev_frame = s->frame;
433

  
434 372
    *data_size=sizeof(AVFrame);
435 373
    *(AVFrame*)data = s->frame;
436 374

  
......
441 379
{
442 380
    FlicDecodeContext *s = avctx->priv_data;
443 381

  
444
    if (s->prev_frame.data[0])
445
        avctx->release_buffer(avctx, &s->prev_frame);
382
    if (s->frame.data[0])
383
        avctx->release_buffer(avctx, &s->frame);
446 384

  
447 385
    return 0;
448 386
}

Also available in: Unified diff