libavcodec/aasc.c

Go to the documentation of this file.
00001 /*
00002  * Autodesk RLE Decoder
00003  * Copyright (C) 2005 the ffmpeg project
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 /* report that the buffer was completely consumed */
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 /* release the last frame */
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 };

Generated on Fri Oct 26 02:35:35 2012 for FFmpeg by doxygen 1.5.8

AltStyle によって変換されたページ (->オリジナル) /