K2.6 patches and update.
[tomato.git] / release / src / router / ffmpeg / libavcodec / aasc.c
blob82bd2bfd3d8cc40c4dbc4c0058d43a8aba2828bf
1 /*
2 * Autodesk RLE Decoder
3 * Copyright (C) 2005 the ffmpeg project
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 /**
23 * @file
24 * Autodesk RLE Video Decoder by Konstantin Shishkov
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
31 #include "avcodec.h"
32 #include "dsputil.h"
33 #include "msrledec.h"
35 typedef struct AascContext {
36 AVCodecContext *avctx;
37 AVFrame frame;
38 } AascContext;
40 #define FETCH_NEXT_STREAM_BYTE() \
41 if (stream_ptr >= buf_size) \
42 { \
43 av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (fetch)\n"); \
44 break; \
45 } \
46 stream_byte = buf[stream_ptr++];
48 static av_cold int aasc_decode_init(AVCodecContext *avctx)
50 AascContext *s = avctx->priv_data;
52 s->avctx = avctx;
54 avctx->pix_fmt = PIX_FMT_BGR24;
56 return 0;
59 static int aasc_decode_frame(AVCodecContext *avctx,
60 void *data, int *data_size,
61 AVPacket *avpkt)
63 const uint8_t *buf = avpkt->data;
64 int buf_size = avpkt->size;
65 AascContext *s = avctx->priv_data;
66 int compr, i, stride;
68 s->frame.reference = 1;
69 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
70 if (avctx->reget_buffer(avctx, &s->frame)) {
71 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
72 return -1;
75 compr = AV_RL32(buf);
76 buf += 4;
77 buf_size -= 4;
78 switch(compr){
79 case 0:
80 stride = (avctx->width * 3 + 3) & ~3;
81 for(i = avctx->height - 1; i >= 0; i--){
82 memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width*3);
83 buf += stride;
85 break;
86 case 1:
87 ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, buf - 4, buf_size + 4);
88 break;
89 default:
90 av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
91 return -1;
94 *data_size = sizeof(AVFrame);
95 *(AVFrame*)data = s->frame;
97 /* report that the buffer was completely consumed */
98 return buf_size;
101 static av_cold int aasc_decode_end(AVCodecContext *avctx)
103 AascContext *s = avctx->priv_data;
105 /* release the last frame */
106 if (s->frame.data[0])
107 avctx->release_buffer(avctx, &s->frame);
109 return 0;
112 AVCodec aasc_decoder = {
113 "aasc",
114 AVMEDIA_TYPE_VIDEO,
115 CODEC_ID_AASC,
116 sizeof(AascContext),
117 aasc_decode_init,
118 NULL,
119 aasc_decode_end,
120 aasc_decode_frame,
121 CODEC_CAP_DR1,
122 .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),