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;
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 switch (avctx->codec_tag) {
00082 case MKTAG('A', 'A', 'S', '4'):
00083 bytestream2_init(&s->gb, buf - 4, buf_size + 4);
00084 ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb);
00085 break;
00086 case MKTAG('A', 'A', 'S', 'C'):
00087 switch(compr){
00088 case 0:
00089 stride = (avctx->width * 3 + 3) & ~3;
00090 for(i = avctx->height - 1; i >= 0; i--){
00091 if(avctx->width*3 > buf_size){
00092 av_log(avctx, AV_LOG_ERROR, "Next line is beyond buffer bounds\n");
00093 break;
00094 }
00095 memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width*3);
00096 buf += stride;
00097 buf_size -= stride;
00098 }
00099 break;
00100 case 1:
00101 bytestream2_init(&s->gb, buf, buf_size);
00102 ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb);
00103 break;
00104 default:
00105 av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
00106 return -1;
00107 }
00108 break;
00109 default:
00110 av_log(avctx, AV_LOG_ERROR, "Unknown FourCC: %X\n", avctx->codec_tag);
00111 return -1;
00112 }
00113
00114 *data_size = sizeof(AVFrame);
00115 *(AVFrame*)data = s->frame;
00116
00117
00118 return buf_size;
00119 }
00120
00121 static av_cold int aasc_decode_end(AVCodecContext *avctx)
00122 {
00123 AascContext *s = avctx->priv_data;
00124
00125
00126 if (s->frame.data[0])
00127 avctx->release_buffer(avctx, &s->frame);
00128
00129 return 0;
00130 }
00131
00132 AVCodec ff_aasc_decoder = {
00133 .name = "aasc",
00134 .type = AVMEDIA_TYPE_VIDEO,
00135 .id = CODEC_ID_AASC,
00136 .priv_data_size = sizeof(AascContext),
00137 .init = aasc_decode_init,
00138 .close = aasc_decode_end,
00139 .decode = aasc_decode_frame,
00140 .capabilities = CODEC_CAP_DR1,
00141 .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"),
00142 };