diff options
Diffstat (limited to 'libavcodec/cscd.c')
-rw-r--r-- | libavcodec/cscd.c | 128 |
1 files changed, 16 insertions, 112 deletions
diff --git a/libavcodec/cscd.c b/libavcodec/cscd.c index 1a0f22e938..b0b4893ca1 100644 --- a/libavcodec/cscd.c +++ b/libavcodec/cscd.c @@ -2,20 +2,20 @@ * CamStudio decoder * Copyright (c) 2006 Reimar Doeffinger * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdio.h> @@ -35,9 +35,9 @@ typedef struct { unsigned char* decomp_buf; } CamStudioContext; -static void copy_frame_default(AVFrame *f, const uint8_t *src, int src_stride, +static void copy_frame_default(AVFrame *f, const uint8_t *src, int linelen, int height) { - int i; + int i, src_stride = FFALIGN(linelen, 4); uint8_t *dst = f->data[0]; dst += (height - 1) * f->linesize[0]; for (i = height; i; i--) { @@ -47,9 +47,9 @@ static void copy_frame_default(AVFrame *f, const uint8_t *src, int src_stride, } } -static void add_frame_default(AVFrame *f, const uint8_t *src, int src_stride, +static void add_frame_default(AVFrame *f, const uint8_t *src, int linelen, int height) { - int i, j; + int i, j, src_stride = FFALIGN(linelen, 4); uint8_t *dst = f->data[0]; dst += (height - 1) * f->linesize[0]; for (i = height; i; i--) { @@ -60,81 +60,6 @@ static void add_frame_default(AVFrame *f, const uint8_t *src, int src_stride, } } -#if !HAVE_BIGENDIAN -#define copy_frame_16(f, s, l, h) copy_frame_default(f, s, l, l, h) -#define copy_frame_32(f, s, l, h) copy_frame_default(f, s, l, l, h) -#define add_frame_16(f, s, l, h) add_frame_default(f, s, l, l, h) -#define add_frame_32(f, s, l, h) add_frame_default(f, s, l, l, h) -#else -static void copy_frame_16(AVFrame *f, const uint8_t *src, - int linelen, int height) { - int i, j; - uint8_t *dst = f->data[0]; - dst += (height - 1) * f->linesize[0]; - for (i = height; i; i--) { - for (j = linelen / 2; j; j--) { - dst[0] = src[1]; - dst[1] = src[0]; - src += 2; - dst += 2; - } - dst -= f->linesize[0] + linelen; - } -} - -static void copy_frame_32(AVFrame *f, const uint8_t *src, - int linelen, int height) { - int i, j; - uint8_t *dst = f->data[0]; - dst += (height - 1) * f->linesize[0]; - for (i = height; i; i--) { - for (j = linelen / 4; j; j--) { - dst[0] = src[3]; - dst[1] = src[2]; - dst[2] = src[1]; - dst[3] = src[0]; - src += 4; - dst += 4; - } - dst -= f->linesize[0] + linelen; - } -} - -static void add_frame_16(AVFrame *f, const uint8_t *src, - int linelen, int height) { - int i, j; - uint8_t *dst = f->data[0]; - dst += (height - 1) * f->linesize[0]; - for (i = height; i; i--) { - for (j = linelen / 2; j; j--) { - dst[0] += src[1]; - dst[1] += src[0]; - src += 2; - dst += 2; - } - dst -= f->linesize[0] + linelen; - } -} - -static void add_frame_32(AVFrame *f, const uint8_t *src, - int linelen, int height) { - int i, j; - uint8_t *dst = f->data[0]; - dst += (height - 1) * f->linesize[0]; - for (i = height; i; i--) { - for (j = linelen / 4; j; j--) { - dst[0] += src[3]; - dst[1] += src[2]; - dst[2] += src[1]; - dst[3] += src[0]; - src += 4; - dst += 4; - } - dst -= f->linesize[0] + linelen; - } -} -#endif - static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; @@ -147,12 +72,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, return -1; } - if (c->pic.data[0]) - avctx->release_buffer(avctx, &c->pic); - c->pic.reference = 1; + c->pic.reference = 3; c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; - if (avctx->get_buffer(avctx, &c->pic) < 0) { + if (avctx->reget_buffer(avctx, &c->pic) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } @@ -185,31 +108,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, if (buf[0] & 1) { // keyframe c->pic.pict_type = AV_PICTURE_TYPE_I; c->pic.key_frame = 1; - switch (c->bpp) { - case 16: - copy_frame_16(&c->pic, c->decomp_buf, c->linelen, c->height); - break; - case 32: - copy_frame_32(&c->pic, c->decomp_buf, c->linelen, c->height); - break; - default: - copy_frame_default(&c->pic, c->decomp_buf, FFALIGN(c->linelen, 4), + copy_frame_default(&c->pic, c->decomp_buf, c->linelen, c->height); - } } else { c->pic.pict_type = AV_PICTURE_TYPE_P; c->pic.key_frame = 0; - switch (c->bpp) { - case 16: - add_frame_16(&c->pic, c->decomp_buf, c->linelen, c->height); - break; - case 32: - add_frame_32(&c->pic, c->decomp_buf, c->linelen, c->height); - break; - default: - add_frame_default(&c->pic, c->decomp_buf, FFALIGN(c->linelen, 4), + add_frame_default(&c->pic, c->decomp_buf, c->linelen, c->height); - } } *picture = c->pic; @@ -221,9 +126,9 @@ static av_cold int decode_init(AVCodecContext *avctx) { CamStudioContext *c = avctx->priv_data; int stride; switch (avctx->bits_per_coded_sample) { - case 16: avctx->pix_fmt = PIX_FMT_RGB555; break; + case 16: avctx->pix_fmt = PIX_FMT_RGB555LE; break; case 24: avctx->pix_fmt = PIX_FMT_BGR24; break; - case 32: avctx->pix_fmt = PIX_FMT_RGB32; break; + case 32: avctx->pix_fmt = PIX_FMT_BGRA; break; default: av_log(avctx, AV_LOG_ERROR, "CamStudio codec error: invalid depth %i bpp\n", @@ -231,12 +136,11 @@ static av_cold int decode_init(AVCodecContext *avctx) { return AVERROR_INVALIDDATA; } c->bpp = avctx->bits_per_coded_sample; + avcodec_get_frame_defaults(&c->pic); c->pic.data[0] = NULL; c->linelen = avctx->width * avctx->bits_per_coded_sample / 8; c->height = avctx->height; - stride = c->linelen; - if (avctx->bits_per_coded_sample == 24) - stride = FFALIGN(stride, 4); + stride = FFALIGN(c->linelen, 4); c->decomp_size = c->height * stride; c->decomp_buf = av_malloc(c->decomp_size + AV_LZO_OUTPUT_PADDING); if (!c->decomp_buf) { |