00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030
00031 #include "avcodec.h"
00032 #include "dsputil.h"
00033 #include "msrledec.h"
00034
00035 typedef struct AascContext {
00036 AVCodecContext *avctx;
00037 AVFrame frame;
00038 } AascContext;
00039
00040 #define FETCH_NEXT_STREAM_BYTE() \
00041 if (stream_ptr >= buf_size) \
00042 { \
00043 av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (fetch)\n"); \
00044 break; \
00045 } \
00046 stream_byte = buf[stream_ptr++];
00047
00048 static av_cold int aasc_decode_init(AVCodecContext *avctx)
00049 {
00050 AascContext *s = avctx->priv_data;
00051
00052 s->avctx = avctx;
00053 avctx->pix_fmt = PIX_FMT_BGR24;
00054 avcodec_get_frame_defaults(&s->frame);
00055
00056 return 0;
00057 }
00058
00059 static int aasc_decode_frame(AVCodecContext *avctx,
00060 void *data, int *data_size,
00061 AVPacket *avpkt)
00062 {
00063 const uint8_t *buf = avpkt->data;
00064 int buf_size = avpkt->size;
00065 AascContext *s = avctx->priv_data;
00066 int compr, i, stride;
00067
00068 s->frame.reference = 3;
00069 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
00070 if (avctx->reget_buffer(avctx, &s->frame)) {
00071 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
00072 return -1;
00073 }
00074
00075 compr = AV_RL32(buf);
00076 buf += 4;
00077 buf_size -= 4;
00078 switch(compr){
00079 case 0:
00080 stride = (avctx->width * 3 + 3) & ~3;
00081 for(i = avctx->height - 1; i >= 0; i--){
00082 if(avctx->width*3 > buf_size){
00083 av_log(avctx, AV_LOG_ERROR, "Next line is beyond buffer bounds\n");
00084 break;
00085 }
00086 memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width*3);
00087 buf += stride;
00088 buf_size -= stride;
00089 }
00090 break;
00091 case 1:
00092 ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, buf - 4, buf_size + 4);
00093 break;
00094 default:
00095 av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
00096 return -1;
00097 }
00098
00099 *data_size = sizeof(AVFrame);
00100 *(AVFrame*)data = s->frame;
00101
00102
00103 return buf_size;
00104 }
00105
00106 static av_cold int aasc_decode_end(AVCodecContext *avctx)
00107 {
00108 AascContext *s = avctx->priv_data;
00109
00110
00111 if (s->frame.data[0])
00112 avctx->release_buffer(avctx, &s->frame);
00113
00114 return 0;
00115 }
00116
00117 AVCodec ff_aasc_decoder = {
00118 .name = "aasc",
00119 .type = AVMEDIA_TYPE_VIDEO,
00120 .id = CODEC_ID_AASC,
00121 .priv_data_size = sizeof(AascContext),
00122 .init = aasc_decode_init,
00123 .close = aasc_decode_end,
00124 .decode = aasc_decode_frame,
00125 .capabilities = CODEC_CAP_DR1,
00126 .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),
00127 };