Extend IFF demuxer to parse PBM/ILBM bitmap chunks

Originally committed as revision 21623 to svn://svn.ffmpeg.org/ffmpeg/trunk
release/0.6
Peter Ross 15 years ago
parent b9e06dddb7
commit 02c4f626a8
  1. 97
      libavformat/iff.c

@ -1,6 +1,7 @@
/* /*
* IFF (.iff) file demuxer * IFF (.iff) file demuxer
* Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net> * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
* *
* This file is part of FFmpeg. * This file is part of FFmpeg.
* *
@ -35,6 +36,10 @@
#define ID_ATAK MKTAG('A','T','A','K') #define ID_ATAK MKTAG('A','T','A','K')
#define ID_RLSE MKTAG('R','L','S','E') #define ID_RLSE MKTAG('R','L','S','E')
#define ID_CHAN MKTAG('C','H','A','N') #define ID_CHAN MKTAG('C','H','A','N')
#define ID_PBM MKTAG('P','B','M',' ')
#define ID_ILBM MKTAG('I','L','B','M')
#define ID_BMHD MKTAG('B','M','H','D')
#define ID_CMAP MKTAG('C','M','A','P')
#define ID_FORM MKTAG('F','O','R','M') #define ID_FORM MKTAG('F','O','R','M')
#define ID_ANNO MKTAG('A','N','N','O') #define ID_ANNO MKTAG('A','N','N','O')
@ -54,6 +59,7 @@
#define PACKET_SIZE 1024 #define PACKET_SIZE 1024
typedef enum {COMP_NONE, COMP_FIB, COMP_EXP} svx8_compression_type; typedef enum {COMP_NONE, COMP_FIB, COMP_EXP} svx8_compression_type;
typedef enum {BITMAP_RAW, BITMAP_BYTERUN1} bitmap_compression_type;
typedef struct { typedef struct {
uint32_t body_size; uint32_t body_size;
@ -79,7 +85,7 @@ static int iff_probe(AVProbeData *p)
const uint8_t *d = p->buf; const uint8_t *d = p->buf;
if ( AV_RL32(d) == ID_FORM && if ( AV_RL32(d) == ID_FORM &&
AV_RL32(d+8) == ID_8SVX) (AV_RL32(d+8) == ID_8SVX || AV_RL32(d+8) == ID_PBM || AV_RL32(d+8) == ID_ILBM) )
return AVPROBE_SCORE_MAX; return AVPROBE_SCORE_MAX;
return 0; return 0;
} }
@ -92,13 +98,16 @@ static int iff_read_header(AVFormatContext *s,
AVStream *st; AVStream *st;
uint32_t chunk_id, data_size; uint32_t chunk_id, data_size;
int padding, done = 0; int padding, done = 0;
int compression = -1;
st = av_new_stream(s, 0); st = av_new_stream(s, 0);
if (!st) if (!st)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
st->codec->channels = 1; st->codec->channels = 1;
url_fskip(pb, 12); url_fskip(pb, 8);
// codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content
st->codec->codec_tag = get_le32(pb);
while(!done && !url_feof(pb)) { while(!done && !url_feof(pb)) {
chunk_id = get_le32(pb); chunk_id = get_le32(pb);
@ -107,10 +116,11 @@ static int iff_read_header(AVFormatContext *s,
switch(chunk_id) { switch(chunk_id) {
case ID_VHDR: case ID_VHDR:
st->codec->codec_type = CODEC_TYPE_AUDIO;
url_fskip(pb, 12); url_fskip(pb, 12);
st->codec->sample_rate = get_be16(pb); st->codec->sample_rate = get_be16(pb);
url_fskip(pb, 1); url_fskip(pb, 1);
st->codec->codec_tag = get_byte(pb); compression = get_byte(pb);
url_fskip(pb, 4); url_fskip(pb, 4);
break; break;
@ -123,19 +133,40 @@ static int iff_read_header(AVFormatContext *s,
st->codec->channels = (get_be32(pb) < 6) ? 1 : 2; st->codec->channels = (get_be32(pb) < 6) ? 1 : 2;
break; break;
case ID_CMAP:
st->codec->extradata_size = data_size;
st->codec->extradata = av_malloc(data_size);
if (!st->codec->extradata)
return AVERROR(ENOMEM);
if (get_buffer(pb, st->codec->extradata, data_size) < 0)
return AVERROR(EIO);
break;
case ID_BMHD:
st->codec->codec_type = CODEC_TYPE_VIDEO;
st->codec->width = get_be16(pb);
st->codec->height = get_be16(pb);
url_fskip(pb, 4); // x, y offset
st->codec->bits_per_coded_sample = get_byte(pb);
url_fskip(pb, 1); // masking
compression = get_byte(pb);
url_fskip(pb, 3); // paddding, transparent
st->sample_aspect_ratio.num = get_byte(pb);
st->sample_aspect_ratio.den = get_byte(pb);
url_fskip(pb, 4); // source page width, height
break;
default: default:
url_fseek(pb, data_size + padding, SEEK_CUR); url_fseek(pb, data_size + padding, SEEK_CUR);
break; break;
} }
} }
if(!st->codec->sample_rate) switch(st->codec->codec_type) {
return AVERROR_INVALIDDATA; case CODEC_TYPE_AUDIO:
av_set_pts_info(st, 32, 1, st->codec->sample_rate); av_set_pts_info(st, 32, 1, st->codec->sample_rate);
st->codec->codec_type = CODEC_TYPE_AUDIO;
switch(st->codec->codec_tag) { switch(compression) {
case COMP_NONE: case COMP_NONE:
st->codec->codec_id = CODEC_ID_PCM_S8; st->codec->codec_id = CODEC_ID_PCM_S8;
break; break;
@ -153,18 +184,45 @@ static int iff_read_header(AVFormatContext *s,
st->codec->bits_per_coded_sample = 8; st->codec->bits_per_coded_sample = 8;
st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample; st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample;
st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
break;
case CODEC_TYPE_VIDEO:
switch (compression) {
case BITMAP_RAW:
if (st->codec->codec_tag == ID_ILBM) {
st->codec->codec_id = CODEC_ID_IFF_ILBM;
} else {
st->codec->codec_id = CODEC_ID_RAWVIDEO;
st->codec->pix_fmt = PIX_FMT_PAL8;
st->codec->codec_tag = 0;
}
break;
case BITMAP_BYTERUN1:
st->codec->codec_id = CODEC_ID_IFF_BYTERUN1;
break;
default:
av_log(s, AV_LOG_ERROR, "unknown compression method\n");
return AVERROR_INVALIDDATA;
}
break;
default:
return -1;
}
return 0; return 0;
} }
int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal);
static int iff_read_packet(AVFormatContext *s, static int iff_read_packet(AVFormatContext *s,
AVPacket *pkt) AVPacket *pkt)
{ {
IffDemuxContext *iff = s->priv_data; IffDemuxContext *iff = s->priv_data;
ByteIOContext *pb = s->pb; ByteIOContext *pb = s->pb;
AVStream *st = s->streams[0];
int ret; int ret;
if(iff->sent_bytes > iff->body_size) if(iff->sent_bytes >= iff->body_size)
return AVERROR(EIO); return AVERROR(EIO);
if(s->streams[0]->codec->channels == 2) { if(s->streams[0]->codec->channels == 2) {
@ -176,18 +234,37 @@ static int iff_read_packet(AVFormatContext *s,
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE); interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE);
} else if (s->streams[0]->codec->codec_id == CODEC_ID_RAWVIDEO) {
if(av_new_packet(pkt, iff->body_size + AVPALETTE_SIZE) < 0) {
return AVERROR(ENOMEM);
} }
else {
ret = ff_cmap_read_palette(st->codec, (uint32_t*)(pkt->data + iff->body_size));
if (ret < 0)
return ret;
av_freep(&st->codec->extradata);
st->codec->extradata_size = 0;
ret = get_buffer(pb, pkt->data, iff->body_size);
} else if (s->streams[0]->codec->codec_type == CODEC_TYPE_VIDEO) {
ret = av_get_packet(pb, pkt, iff->body_size);
} else {
ret = av_get_packet(pb, pkt, PACKET_SIZE); ret = av_get_packet(pb, pkt, PACKET_SIZE);
} }
if(iff->sent_bytes == 0) if(iff->sent_bytes == 0)
pkt->flags |= PKT_FLAG_KEY; pkt->flags |= PKT_FLAG_KEY;
if(s->streams[0]->codec->codec_type == CODEC_TYPE_AUDIO) {
iff->sent_bytes += PACKET_SIZE; iff->sent_bytes += PACKET_SIZE;
} else {
iff->sent_bytes = iff->body_size;
}
pkt->stream_index = 0; pkt->stream_index = 0;
if(s->streams[0]->codec->codec_type == CODEC_TYPE_AUDIO) {
pkt->pts = iff->audio_frame_count; pkt->pts = iff->audio_frame_count;
iff->audio_frame_count += ret / s->streams[0]->codec->channels; iff->audio_frame_count += ret / s->streams[0]->codec->channels;
}
return ret; return ret;
} }

Loading…
Cancel
Save