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
00054 avctx->pix_fmt = PIX_FMT_BGR24;
00055 s->frame.data[0] = NULL;
00056
00057 return 0;
00058 }
00059
00060 static int aasc_decode_frame(AVCodecContext *avctx,
00061 void *data, int *data_size,
00062 const uint8_t *buf, int buf_size)
00063 {
00064 AascContext *s = avctx->priv_data;
00065 int compr, i, stride;
00066
00067 s->frame.reference = 1;
00068 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
00069 if (avctx->reget_buffer(avctx, &s->frame)) {
00070 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
00071 return -1;
00072 }
00073
00074 compr = AV_RL32(buf);
00075 buf += 4;
00076 buf_size -= 4;
00077 switch(compr){
00078 case 0:
00079 stride = (avctx->width * 3 + 3) & ~3;
00080 for(i = avctx->height - 1; i >= 0; i--){
00081 memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width*3);
00082 buf += stride;
00083 }
00084 break;
00085 case 1:
00086 ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, buf - 4, buf_size + 4);
00087 break;
00088 default:
00089 av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
00090 return -1;
00091 }
00092
00093 *data_size = sizeof(AVFrame);
00094 *(AVFrame*)data = s->frame;
00095
00096
00097 return buf_size;
00098 }
00099
00100 static av_cold int aasc_decode_end(AVCodecContext *avctx)
00101 {
00102 AascContext *s = avctx->priv_data;
00103
00104
00105 if (s->frame.data[0])
00106 avctx->release_buffer(avctx, &s->frame);
00107
00108 return 0;
00109 }
00110
00111 AVCodec aasc_decoder = {
00112 "aasc",
00113 CODEC_TYPE_VIDEO,
00114 CODEC_ID_AASC,
00115 sizeof(AascContext),
00116 aasc_decode_init,
00117 NULL,
00118 aasc_decode_end,
00119 aasc_decode_frame,
00120 CODEC_CAP_DR1,
00121 .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),
00122 };