From 5e79c53b4f390970df08bb892b2b782bfa5aa15d Mon Sep 17 00:00:00 2001 From: melanson Date: Sun, 13 Jan 2002 06:01:04 +0000 Subject: [PATCH] QT demuxer loads palette information from files that transport palettes in their stsd atoms. Also fixed link in MS Video-1 decoder. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4130 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/demux_mov.c | 52 +++++++++++++++++++++++++++++++++++++++--- msvidc.c | 3 +-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/libmpdemux/demux_mov.c b/libmpdemux/demux_mov.c index 826d53242e..a9b8aab585 100644 --- a/libmpdemux/demux_mov.c +++ b/libmpdemux/demux_mov.c @@ -24,6 +24,9 @@ #include +#define BE_16(x) (be2me_16(*(unsigned short *)(x))) +#define BE_32(x) (be2me_32(*(unsigned int *)(x))) + typedef struct { unsigned int pts; // duration unsigned int size; @@ -562,6 +565,10 @@ static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak break; } case MOV_TRAK_VIDEO: { + int i, entry; + int flag, start, count_flag, end, palette_count; + int hdr_ptr = 43+33; // the byte just after depth + unsigned char *palette_map; sh_video_t* sh=new_sh_video(demuxer,priv->track_db); int depth = trak->stdata[43+32]; /* requested by Mike Melanson for Apple RLE decoder -- alex */ sh->format=trak->fourcc; @@ -570,10 +577,49 @@ static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8); sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8); + // palettized? + if ((depth == 2) || (depth == 4) || (depth == 8) || + (depth == 34) || (depth == 36) || (depth == 40)) + palette_count = (1 << (depth & 0x0F)); + else + palette_count = 0; + // emulate BITMAPINFOHEADER: - sh->bih=malloc(sizeof(BITMAPINFOHEADER)); - memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); - sh->bih->biSize=40; + if (palette_count) + { + sh->bih=malloc(sizeof(BITMAPINFOHEADER) + palette_count * 4); + memset(sh->bih,0,sizeof(BITMAPINFOHEADER) + palette_count * 4); + sh->bih->biSize=40 + palette_count * 4; + // fetch the relevant fields + flag = BE_16(&trak->stdata[hdr_ptr]); + hdr_ptr += 2; + start = BE_32(&trak->stdata[hdr_ptr]); + hdr_ptr += 4; + count_flag = BE_16(&trak->stdata[hdr_ptr]); + hdr_ptr += 2; + end = BE_16(&trak->stdata[hdr_ptr]); + hdr_ptr += 2; + palette_map = (unsigned char *)sh->bih + 40; + for (i = start; i <= end; i++) + { + entry = BE_16(&trak->stdata[hdr_ptr]); + hdr_ptr += 2; + // apparently, if count_flag is set, entry is same as i + if (count_flag & 0x8000) + entry = i; + // only care about top 8 bits of 16-bit R, G, or B value + palette_map[entry * 4 + 0] = trak->stdata[hdr_ptr + 0]; + palette_map[entry * 4 + 1] = trak->stdata[hdr_ptr + 2]; + palette_map[entry * 4 + 2] = trak->stdata[hdr_ptr + 4]; + hdr_ptr += 6; + } + } + else + { + sh->bih=malloc(sizeof(BITMAPINFOHEADER)); + memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); + sh->bih->biSize=40; + } sh->bih->biWidth=sh->disp_w; sh->bih->biHeight=sh->disp_h; sh->bih->biPlanes=0; diff --git a/msvidc.c b/msvidc.c index 646927cdd0..b77bceb88d 100644 --- a/msvidc.c +++ b/msvidc.c @@ -4,7 +4,7 @@ (C) 2001 Mike Melanson The description of the algorithm you can read here: - http://www.pcisys.net/~melanson/video1.txt + http://www.pcisys.net/~melanson/codecs/ 32bpp support (c) alex */ @@ -103,7 +103,6 @@ void AVI_Decode_Video1_16( { flags = (byte_b << 8) | byte_a; -// quad[0][0].c1 = LE_16(&encoded[stream_ptr]); quad[0][0].c1 = LE_16(&encoded[stream_ptr]); stream_ptr += 2; quad[0][0].c2 = LE_16(&encoded[stream_ptr]);