• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

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 
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     /* report that the buffer was completely consumed */
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     /* release the last frame */
00106     if (s->frame.data[0])
00107         avctx->release_buffer(avctx, &s->frame);
00108 
00109     return 0;
00110 }
00111 
00112 AVCodec 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 };

Generated on Fri Sep 16 2011 17:17:33 for FFmpeg by  doxygen 1.7.1