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

libavcodec/msrle.c

Go to the documentation of this file.
00001 /*
00002  * Micrsoft RLE Video Decoder
00003  * Copyright (C) 2003 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 
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <string.h>
00037 #include <unistd.h>
00038 
00039 #include "avcodec.h"
00040 #include "dsputil.h"
00041 #include "msrledec.h"
00042 
00043 typedef struct MsrleContext {
00044     AVCodecContext *avctx;
00045     AVFrame frame;
00046 
00047     const unsigned char *buf;
00048     int size;
00049 
00050 } MsrleContext;
00051 
00052 static av_cold int msrle_decode_init(AVCodecContext *avctx)
00053 {
00054     MsrleContext *s = avctx->priv_data;
00055 
00056     s->avctx = avctx;
00057 
00058     avctx->pix_fmt = PIX_FMT_PAL8;
00059     s->frame.data[0] = NULL;
00060 
00061     return 0;
00062 }
00063 
00064 static int msrle_decode_frame(AVCodecContext *avctx,
00065                               void *data, int *data_size,
00066                               const uint8_t *buf, int buf_size)
00067 {
00068     MsrleContext *s = avctx->priv_data;
00069 
00070     s->buf = buf;
00071     s->size = buf_size;
00072 
00073     s->frame.reference = 1;
00074     s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
00075     if (avctx->reget_buffer(avctx, &s->frame)) {
00076         av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
00077         return -1;
00078     }
00079 
00080     /* make the palette available */
00081     memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
00082     if (s->avctx->palctrl->palette_changed) {
00083         s->frame.palette_has_changed = 1;
00084         s->avctx->palctrl->palette_changed = 0;
00085     }
00086 
00087     ff_msrle_decode(avctx, (AVPicture*)&s->frame, avctx->bits_per_coded_sample, buf, buf_size);
00088 
00089     *data_size = sizeof(AVFrame);
00090     *(AVFrame*)data = s->frame;
00091 
00092     /* report that the buffer was completely consumed */
00093     return buf_size;
00094 }
00095 
00096 static av_cold int msrle_decode_end(AVCodecContext *avctx)
00097 {
00098     MsrleContext *s = avctx->priv_data;
00099 
00100     /* release the last frame */
00101     if (s->frame.data[0])
00102         avctx->release_buffer(avctx, &s->frame);
00103 
00104     return 0;
00105 }
00106 
00107 AVCodec msrle_decoder = {
00108     "msrle",
00109     CODEC_TYPE_VIDEO,
00110     CODEC_ID_MSRLE,
00111     sizeof(MsrleContext),
00112     msrle_decode_init,
00113     NULL,
00114     msrle_decode_end,
00115     msrle_decode_frame,
00116     CODEC_CAP_DR1,
00117     .long_name= NULL_IF_CONFIG_SMALL("Microsoft RLE"),
00118 };

Generated on Tue Nov 4 2014 12:59:22 for ffmpeg by  doxygen 1.7.1