Go to the documentation of this file.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 GetByteContext gb;
00038 AVFrame frame;
00039 } AascContext;
00040
00041 static av_cold int aasc_decode_init(AVCodecContext *avctx)
00042 {
00043 AascContext *s = avctx->priv_data;
00044
00045 s->avctx = avctx;
00046
00047 avctx->pix_fmt = PIX_FMT_BGR24;
00048
00049 return 0;
00050 }
00051
00052 static int aasc_decode_frame(AVCodecContext *avctx,
00053 void *data, int *data_size,
00054 AVPacket *avpkt)
00055 {
00056 const uint8_t *buf = avpkt->data;
00057 int buf_size = avpkt->size;
00058 AascContext *s = avctx->priv_data;
00059 int compr, i, stride;
00060
00061 s->frame.reference = 1;
00062 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
00063 if (avctx->reget_buffer(avctx, &s->frame)) {
00064 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
00065 return -1;
00066 }
00067
00068 compr = AV_RL32(buf);
00069 buf += 4;
00070 buf_size -= 4;
00071 switch(compr){
00072 case 0:
00073 stride = (avctx->width * 3 + 3) & ~3;
00074 for(i = avctx->height - 1; i >= 0; i--){
00075 memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width*3);
00076 buf += stride;
00077 }
00078 break;
00079 case 1:
00080 bytestream2_init(&s->gb, buf - 4, buf_size + 4);
00081 ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb);
00082 break;
00083 default:
00084 av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
00085 return -1;
00086 }
00087
00088 *data_size = sizeof(AVFrame);
00089 *(AVFrame*)data = s->frame;
00090
00091
00092 return buf_size;
00093 }
00094
00095 static av_cold int aasc_decode_end(AVCodecContext *avctx)
00096 {
00097 AascContext *s = avctx->priv_data;
00098
00099
00100 if (s->frame.data[0])
00101 avctx->release_buffer(avctx, &s->frame);
00102
00103 return 0;
00104 }
00105
00106 AVCodec ff_aasc_decoder = {
00107 .name = "aasc",
00108 .type = AVMEDIA_TYPE_VIDEO,
00109 .id = CODEC_ID_AASC,
00110 .priv_data_size = sizeof(AascContext),
00111 .init = aasc_decode_init,
00112 .close = aasc_decode_end,
00113 .decode = aasc_decode_frame,
00114 .capabilities = CODEC_CAP_DR1,
00115 .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),
00116 };