# HG changeset patch # User pross # Date 1265190976 0 # Node ID 9fe3b0dcd33d2e7fe1702c18b3d2d62c245077f1 # Parent 67b3d3174b41ecb63c899eb0bad2084e09739879 IFF PBM/ILBM bitmap decoder diff -r 67b3d3174b41 -r 9fe3b0dcd33d Makefile --- a/Makefile Wed Feb 03 04:40:42 2010 +0000 +++ b/Makefile Wed Feb 03 09:56:16 2010 +0000 @@ -144,6 +144,8 @@ OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o OBJS-$(CONFIG_IDCIN_DECODER) += idcinvideo.o +OBJS-$(CONFIG_IFF_BYTERUN1_DECODER) += iff.o +OBJS-$(CONFIG_IFF_ILBM_DECODER) += iff.o OBJS-$(CONFIG_IMC_DECODER) += imc.o OBJS-$(CONFIG_INDEO2_DECODER) += indeo2.o OBJS-$(CONFIG_INDEO3_DECODER) += indeo3.o diff -r 67b3d3174b41 -r 9fe3b0dcd33d allcodecs.c --- a/allcodecs.c Wed Feb 03 04:40:42 2010 +0000 +++ b/allcodecs.c Wed Feb 03 09:56:16 2010 +0000 @@ -114,6 +114,8 @@ REGISTER_DECODER (H264_VDPAU, h264_vdpau); REGISTER_ENCDEC (HUFFYUV, huffyuv); REGISTER_DECODER (IDCIN, idcin); + REGISTER_DECODER (IFF_BYTERUN1, iff_byterun1); + REGISTER_DECODER (IFF_ILBM, iff_ilbm); REGISTER_DECODER (INDEO2, indeo2); REGISTER_DECODER (INDEO3, indeo3); REGISTER_DECODER (INTERPLAY_VIDEO, interplay_video); diff -r 67b3d3174b41 -r 9fe3b0dcd33d avcodec.h --- a/avcodec.h Wed Feb 03 04:40:42 2010 +0000 +++ b/avcodec.h Wed Feb 03 09:56:16 2010 +0000 @@ -30,7 +30,7 @@ #include "libavutil/avutil.h" #define LIBAVCODEC_VERSION_MAJOR 52 -#define LIBAVCODEC_VERSION_MINOR 51 +#define LIBAVCODEC_VERSION_MINOR 52 #define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ @@ -204,6 +204,8 @@ CODEC_ID_R210, CODEC_ID_ANM, CODEC_ID_BINKVIDEO, + CODEC_ID_IFF_ILBM, + CODEC_ID_IFF_BYTERUN1, /* various PCM "codecs" */ CODEC_ID_PCM_S16LE= 0x10000, diff -r 67b3d3174b41 -r 9fe3b0dcd33d iff.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/iff.c Wed Feb 03 09:56:16 2010 +0000 @@ -0,0 +1,223 @@ +/* + * IFF PBM/ILBM bitmap decoder + * Copyright (c) 2010 Peter Ross + * + * This file is part of FFmpeg. + * + * 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. + * + * 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file libavcodec/iff.c + * IFF PBM/ILBM bitmap decoder + */ + +#include "bytestream.h" +#include "avcodec.h" + +/** + * Convert CMAP buffer (stored in extradata) to lavc palette format + */ +int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal) +{ + int count, i; + + if (avctx->bits_per_coded_sample > 8) { + av_log(avctx, AV_LOG_ERROR, "bit_per_coded_sample > 8 not supported\n"); + return AVERROR_INVALIDDATA; + } + + count = 1 << avctx->bits_per_coded_sample; + if (avctx->extradata_size < count * 3) { + av_log(avctx, AV_LOG_ERROR, "palette data underflow\n"); + return AVERROR_INVALIDDATA; + } + for (i=0; i < count; i++) { + pal[i] = AV_RB24( avctx->extradata + i*3 ); + } + return 0; +} + +static av_cold int decode_init(AVCodecContext *avctx) +{ + AVFrame *frame = avctx->priv_data; + + avctx->pix_fmt = PIX_FMT_PAL8; + frame->reference = 1; + + if (avctx->get_buffer(avctx, frame) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return AVERROR_UNKNOWN; + } + return ff_cmap_read_palette(avctx, (uint32_t*)frame->data[1]); +} + +/** + * Interleaved memcpy + */ +static void imemcpy(uint8_t *dst, const uint8_t const *buf, int x, int bps, int plane, int length) +{ + int i, b; + for(i = 0; i < length; i++) { + int value = buf[i]; + for (b = 0; b < bps; b++) { + if (value & (1<priv_data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + int planewidth = avctx->width / avctx->bits_per_coded_sample; + int y, plane; + + if (avctx->reget_buffer(avctx, frame) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + if (buf_size < avctx->width * avctx->height) { + av_log(avctx, AV_LOG_ERROR, "buffer underflow\n"); + return -1; + } + + for(y = 0; y < avctx->height; y++ ) { + uint8_t *row = &frame->data[0][ y*frame->linesize[0] ]; + memset(row, 0, avctx->width); + for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) { + imemcpy(row, buf, 0, avctx->bits_per_coded_sample, plane, planewidth); + buf += planewidth; + } + } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = *frame; + return buf_size; +} + +static int decode_frame_byterun1(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt) +{ + AVFrame *frame = avctx->priv_data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + const uint8_t *buf_end = buf+buf_size; + int planewidth = avctx->width / avctx->bits_per_coded_sample; + int y, plane, x; + + if (avctx->reget_buffer(avctx, frame) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + for(y = 0; y < avctx->height ; y++ ) { + uint8_t *row = &frame->data[0][ y*frame->linesize[0] ]; + if (avctx->codec_tag == MKTAG('I','L','B','M')) { //interleaved + memset(row, 0, avctx->width); + for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) { + for(x = 0; x < planewidth && buf < buf_end; ) { + char value = *buf++; + int length; + if (value >= 0) { + length = value + 1; + imemcpy(row, buf, x, avctx->bits_per_coded_sample, plane, FFMIN3(length, buf_end - buf, planewidth - x)); + buf += length; + } else if (value > -128) { + length = -value + 1; + imemset(row, *buf++, x, avctx->bits_per_coded_sample, plane, FFMIN(length, planewidth - x)); + } else { //noop + continue; + } + x += length; + } + } + } else { + for(x = 0; x < avctx->width && buf < buf_end; ) { + char value = *buf++; + int length; + if (value >= 0) { + length = value + 1; + memcpy(row + x, buf, FFMIN3(length, buf_end - buf, avctx->width - x)); + buf += length; + } else if (value > -128) { + length = -value + 1; + memset(row + x, *buf++, FFMIN(length, avctx->width - x)); + } else { //noop + continue; + } + x += length; + } + } + } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = *frame; + return buf_size; +} + +static av_cold int decode_end(AVCodecContext *avctx) +{ + AVFrame *frame = avctx->priv_data; + if (frame->data[0]) + avctx->release_buffer(avctx, frame); + return 0; +} + +AVCodec iff_ilbm_decoder = { + "iff_ilbm", + CODEC_TYPE_VIDEO, + CODEC_ID_IFF_ILBM, + sizeof(AVFrame), + decode_init, + NULL, + decode_end, + decode_frame_ilbm, + CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("IFF ILBM"), +}; + +AVCodec iff_byterun1_decoder = { + "iff_byterun1", + CODEC_TYPE_VIDEO, + CODEC_ID_IFF_BYTERUN1, + sizeof(AVFrame), + decode_init, + NULL, + decode_end, + decode_frame_byterun1, + CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("IFF ByteRun1"), +};