00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
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
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 };