diff options
Diffstat (limited to 'libavcodec/kgv1dec.c')
-rw-r--r-- | libavcodec/kgv1dec.c | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/libavcodec/kgv1dec.c b/libavcodec/kgv1dec.c index d58e775..b81ba75 100644 --- a/libavcodec/kgv1dec.c +++ b/libavcodec/kgv1dec.c @@ -2,20 +2,20 @@ * Kega Game Video (KGV1) decoder * Copyright (c) 2010 Daniel Verkamp * - * 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 */ @@ -31,7 +31,6 @@ #include "internal.h" typedef struct { - AVCodecContext *avctx; uint16_t *frame_buffer; uint16_t *last_frame_buffer; } KgvContext; @@ -52,7 +51,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf_end = buf + avpkt->size; KgvContext * const c = avctx->priv_data; int offsets[8]; - uint16_t *out, *prev; + uint8_t *out, *prev; int outcnt = 0, maxcnt; int w, h, i, res; @@ -83,22 +82,21 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if ((res = ff_get_buffer(avctx, frame, 0)) < 0) return res; - out = c->frame_buffer; - prev = c->last_frame_buffer; + out = (uint8_t*)c->frame_buffer; + prev = (uint8_t*)c->last_frame_buffer; for (i = 0; i < 8; i++) offsets[i] = -1; - while (outcnt < maxcnt && buf_end - 2 > buf) { + while (outcnt < maxcnt && buf_end - 2 >= buf) { int code = AV_RL16(buf); buf += 2; if (!(code & 0x8000)) { - out[outcnt++] = code; // rgb555 pixel coded directly + AV_WN16A(&out[2 * outcnt], code); // rgb555 pixel coded directly + outcnt++; } else { int count; - int inp_off; - uint16_t *inp; if ((code & 0x6000) == 0x6000) { // copy from previous frame @@ -116,7 +114,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, start = (outcnt + offsets[oidx]) % maxcnt; - if (maxcnt - start < count) + if (maxcnt - start < count || maxcnt - outcnt < count) break; if (!prev) { @@ -125,8 +123,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, break; } - inp = prev; - inp_off = start; + memcpy(out + 2 * outcnt, prev + 2 * start, 2 * count); } else { // copy from earlier in this frame int offset = (code & 0x1FFF) + 1; @@ -141,19 +138,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, count = 4 + *buf++; } - if (outcnt < offset) + if (outcnt < offset || maxcnt - outcnt < count) break; - inp = out; - inp_off = outcnt - offset; - } - - if (maxcnt - outcnt < count) - break; - - for (i = inp_off; i < count + inp_off; i++) { - out[outcnt++] = inp[i]; + av_memcpy_backptr(out + 2 * outcnt, 2 * offset, 2 * count); } + outcnt += count; } } @@ -172,9 +162,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, static av_cold int decode_init(AVCodecContext *avctx) { - KgvContext * const c = avctx->priv_data; - - c->avctx = avctx; avctx->pix_fmt = AV_PIX_FMT_RGB555; return 0; |