Commit 18313287 authored by Sebastian Vater's avatar Sebastian Vater Committed by Michael Niedermayer

HAM6/HAM8 support for IFF demuxer/decoder

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent c2a8f125
This diff is collapsed.
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
* http://wiki.multimedia.cx/index.php?title=IFF * http://wiki.multimedia.cx/index.php?title=IFF
*/ */
#include "libavcodec/bytestream.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "avformat.h" #include "avformat.h"
...@@ -40,6 +41,7 @@ ...@@ -40,6 +41,7 @@
#define ID_PBM MKTAG('P','B','M',' ') #define ID_PBM MKTAG('P','B','M',' ')
#define ID_ILBM MKTAG('I','L','B','M') #define ID_ILBM MKTAG('I','L','B','M')
#define ID_BMHD MKTAG('B','M','H','D') #define ID_BMHD MKTAG('B','M','H','D')
#define ID_CAMG MKTAG('C','A','M','G')
#define ID_CMAP MKTAG('C','M','A','P') #define ID_CMAP MKTAG('C','M','A','P')
#define ID_FORM MKTAG('F','O','R','M') #define ID_FORM MKTAG('F','O','R','M')
...@@ -60,6 +62,16 @@ ...@@ -60,6 +62,16 @@
#define PACKET_SIZE 1024 #define PACKET_SIZE 1024
/**
* This number of bytes if added at the beginning of each AVPacket
* which contain additional information about video properties
* which has to be shared between demuxer and decoder.
* This number may change between frames, e.g. the demuxer might
* set it to smallest possible size of 2 to indicate that there's
* no extradata changing in this frame.
*/
#define IFF_EXTRA_VIDEO_SIZE 9
typedef enum { typedef enum {
COMP_NONE, COMP_NONE,
COMP_FIB, COMP_FIB,
...@@ -76,6 +88,12 @@ typedef struct { ...@@ -76,6 +88,12 @@ typedef struct {
uint32_t body_size; uint32_t body_size;
uint32_t sent_bytes; uint32_t sent_bytes;
uint32_t audio_frame_count; uint32_t audio_frame_count;
unsigned compression; ///< delta compression method used
unsigned bpp; ///< bits per plane to decode (differs from bits_per_coded_sample if HAM)
unsigned ham; ///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
unsigned flags; ///< 1 for EHB, 0 is no extra half darkening
unsigned transparency; ///< transparency color index in palette
unsigned masking; ///< masking method used
} IffDemuxContext; } IffDemuxContext;
...@@ -126,8 +144,12 @@ static int iff_read_header(AVFormatContext *s, ...@@ -126,8 +144,12 @@ static int iff_read_header(AVFormatContext *s,
IffDemuxContext *iff = s->priv_data; IffDemuxContext *iff = s->priv_data;
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
AVStream *st; AVStream *st;
uint8_t *buf;
uint32_t chunk_id, data_size; uint32_t chunk_id, data_size;
int compression = -1; int compression = -1;
uint32_t screenmode = 0;
unsigned transparency = 0;
unsigned masking = 0; // no mask
st = av_new_stream(s, 0); st = av_new_stream(s, 0);
if (!st) if (!st)
...@@ -171,12 +193,18 @@ static int iff_read_header(AVFormatContext *s, ...@@ -171,12 +193,18 @@ static int iff_read_header(AVFormatContext *s,
st->codec->channels = (avio_rb32(pb) < 6) ? 1 : 2; st->codec->channels = (avio_rb32(pb) < 6) ? 1 : 2;
break; break;
case ID_CAMG:
if (data_size < 4)
return AVERROR_INVALIDDATA;
screenmode = avio_rb32(pb);
break;
case ID_CMAP: case ID_CMAP:
st->codec->extradata_size = data_size; st->codec->extradata_size = data_size + IFF_EXTRA_VIDEO_SIZE;
st->codec->extradata = av_malloc(data_size); st->codec->extradata = av_malloc(data_size + IFF_EXTRA_VIDEO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
if (!st->codec->extradata) if (!st->codec->extradata)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if (avio_read(pb, st->codec->extradata, data_size) < 0) if (avio_read(pb, st->codec->extradata + IFF_EXTRA_VIDEO_SIZE, data_size) < 0)
return AVERROR(EIO); return AVERROR(EIO);
break; break;
...@@ -188,12 +216,15 @@ static int iff_read_header(AVFormatContext *s, ...@@ -188,12 +216,15 @@ static int iff_read_header(AVFormatContext *s,
st->codec->height = avio_rb16(pb); st->codec->height = avio_rb16(pb);
avio_skip(pb, 4); // x, y offset avio_skip(pb, 4); // x, y offset
st->codec->bits_per_coded_sample = avio_r8(pb); st->codec->bits_per_coded_sample = avio_r8(pb);
if (data_size >= 11) { if (data_size >= 10)
avio_skip(pb, 1); // masking masking = avio_r8(pb);
if (data_size >= 11)
compression = avio_r8(pb); compression = avio_r8(pb);
if (data_size >= 14) {
avio_skip(pb, 1); // padding
transparency = avio_rb16(pb);
} }
if (data_size >= 16) { if (data_size >= 16) {
avio_skip(pb, 3); // paddding, transparent
st->sample_aspect_ratio.num = avio_r8(pb); st->sample_aspect_ratio.num = avio_r8(pb);
st->sample_aspect_ratio.den = avio_r8(pb); st->sample_aspect_ratio.den = avio_r8(pb);
} }
...@@ -253,6 +284,31 @@ static int iff_read_header(AVFormatContext *s, ...@@ -253,6 +284,31 @@ static int iff_read_header(AVFormatContext *s,
break; break;
case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_VIDEO:
iff->compression = compression;
iff->bpp = st->codec->bits_per_coded_sample;
if ((screenmode & 0x800 /* Hold And Modify */) && iff->bpp <= 8) {
iff->ham = iff->bpp > 6 ? 6 : 4;
st->codec->bits_per_coded_sample = 24;
}
iff->flags = (screenmode & 0x80 /* Extra HalfBrite */) && iff->bpp <= 8;
iff->masking = masking;
iff->transparency = transparency;
if (!st->codec->extradata) {
st->codec->extradata_size = IFF_EXTRA_VIDEO_SIZE;
st->codec->extradata = av_malloc(IFF_EXTRA_VIDEO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
if (!st->codec->extradata)
return AVERROR(ENOMEM);
}
buf = st->codec->extradata;
bytestream_put_be16(&buf, IFF_EXTRA_VIDEO_SIZE);
bytestream_put_byte(&buf, iff->compression);
bytestream_put_byte(&buf, iff->bpp);
bytestream_put_byte(&buf, iff->ham);
bytestream_put_byte(&buf, iff->flags);
bytestream_put_be16(&buf, iff->transparency);
bytestream_put_byte(&buf, iff->masking);
switch (compression) { switch (compression) {
case BITMAP_RAW: case BITMAP_RAW:
st->codec->codec_id = CODEC_ID_IFF_ILBM; st->codec->codec_id = CODEC_ID_IFF_ILBM;
...@@ -293,7 +349,15 @@ static int iff_read_packet(AVFormatContext *s, ...@@ -293,7 +349,15 @@ static int iff_read_packet(AVFormatContext *s,
} }
interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE); interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE);
} else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
ret = av_get_packet(pb, pkt, iff->body_size); uint8_t *buf;
if (av_new_packet(pkt, iff->body_size + 2) < 0) {
return AVERROR(ENOMEM);
}
buf = pkt->data;
bytestream_put_be16(&buf, 2);
ret = avio_read(pb, buf, iff->body_size);
} else { } else {
ret = av_get_packet(pb, pkt, PACKET_SIZE); ret = av_get_packet(pb, pkt, PACKET_SIZE);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment