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 switch (avctx->bits_per_coded_sample) {
00047 case 16:
00048 avctx->pix_fmt = PIX_FMT_RGB555;
00049 break;
00050 case 24:
00051 avctx->pix_fmt = PIX_FMT_BGR24;
00052 break;
00053 default:
00054 av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", avctx->bits_per_coded_sample);
00055 return -1;
00056 }
00057 avcodec_get_frame_defaults(&s->frame);
00058
00059 return 0;
00060 }
00061
00062 static int aasc_decode_frame(AVCodecContext *avctx,
00063 void *data, int *data_size,
00064 AVPacket *avpkt)
00065 {
00066 const uint8_t *buf = avpkt->data;
00067 int buf_size = avpkt->size;
00068 AascContext *s = avctx->priv_data;
00069 int compr, i, stride, psize;
00070
00071 s->frame.reference = 3;
00072 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
00073 if (avctx->reget_buffer(avctx, &s->frame)) {
00074 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
00075 return -1;
00076 }
00077
00078 compr = AV_RL32(buf);
00079 buf += 4;
00080 buf_size -= 4;
00081 psize = avctx->bits_per_coded_sample / 8;
00082 switch (avctx->codec_tag) {
00083 case MKTAG('A', 'A', 'S', '4'):
00084 bytestream2_init(&s->gb, buf - 4, buf_size + 4);
00085 ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb);
00086 break;
00087 case MKTAG('A', 'A', 'S', 'C'):
00088 switch(compr){
00089 case 0:
00090 stride = (avctx->width * psize + psize) & ~psize;
00091 for(i = avctx->height - 1; i >= 0; i--){
00092 if(avctx->width * psize > buf_size){
00093 av_log(avctx, AV_LOG_ERROR, "Next line is beyond buffer bounds\n");
00094 break;
00095 }
00096 memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width * psize);
00097 buf += stride;
00098 buf_size -= stride;
00099 }
00100 break;
00101 case 1:
00102 bytestream2_init(&s->gb, buf, buf_size);
00103 ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb);
00104 break;
00105 default:
00106 av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
00107 return -1;
00108 }
00109 break;
00110 default:
00111 av_log(avctx, AV_LOG_ERROR, "Unknown FourCC: %X\n", avctx->codec_tag);
00112 return -1;
00113 }
00114
00115 *data_size = sizeof(AVFrame);
00116 *(AVFrame*)data = s->frame;
00117
00118
00119 return buf_size;
00120 }
00121
00122 static av_cold int aasc_decode_end(AVCodecContext *avctx)
00123 {
00124 AascContext *s = avctx->priv_data;
00125
00126
00127 if (s->frame.data[0])
00128 avctx->release_buffer(avctx, &s->frame);
00129
00130 return 0;
00131 }
00132
00133 AVCodec ff_aasc_decoder = {
00134 .name = "aasc",
00135 .type = AVMEDIA_TYPE_VIDEO,
00136 .id = CODEC_ID_AASC,
00137 .priv_data_size = sizeof(AascContext),
00138 .init = aasc_decode_init,
00139 .close = aasc_decode_end,
00140 .decode = aasc_decode_frame,
00141 .capabilities = CODEC_CAP_DR1,
00142 .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),
00143 };