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 = 1;
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 memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width*3);
00083 buf += stride;
00084 }
00085 break;
00086 case 1:
00087 ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, buf - 4, buf_size + 4);
00088 break;
00089 default:
00090 av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
00091 return -1;
00092 }
00093
00094 *data_size = sizeof(AVFrame);
00095 *(AVFrame*)data = s->frame;
00096
00097
00098 return buf_size;
00099 }
00100
00101 static av_cold int aasc_decode_end(AVCodecContext *avctx)
00102 {
00103 AascContext *s = avctx->priv_data;
00104
00105
00106 if (s->frame.data[0])
00107 avctx->release_buffer(avctx, &s->frame);
00108
00109 return 0;
00110 }
00111
00112 AVCodec ff_aasc_decoder = {
00113 "aasc",
00114 AVMEDIA_TYPE_VIDEO,
00115 CODEC_ID_AASC,
00116 sizeof(AascContext),
00117 aasc_decode_init,
00118 NULL,
00119 aasc_decode_end,
00120 aasc_decode_frame,
00121 CODEC_CAP_DR1,
00122 .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),
00123 };