8bps.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include "avcodec.h"

Go to the source code of this file.

Data Structures

struct  EightBpsContext

Functions

static int decode_frame (AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size)
static av_cold int decode_init (AVCodecContext *avctx)
static av_cold int decode_end (AVCodecContext *avctx)

Variables

static enum PixelFormat pixfmt_rgb24 [] = {PIX_FMT_BGR24, PIX_FMT_RGB32, PIX_FMT_NONE}
AVCodec eightbps_decoder


Detailed Description

QT 8BPS Video Decoder by Roberto Togni For more information about the 8BPS format, visit: http://www.pcisys.net/~melanson/codecs/

Supports: PAL8 (RGB 8bpp, paletted) : BGR24 (RGB 24bpp) (can also output it as RGB32) : RGB32 (RGB 32bpp, 4th plane is probably alpha and it's ignored)

Definition in file 8bps.c.


Function Documentation

static av_cold int decode_end ( AVCodecContext avctx  )  [static]

Definition at line 211 of file 8bps.c.

References c, AVCodecContext::priv_data, and AVCodecContext::release_buffer.

00212 {
00213         EightBpsContext * const c = avctx->priv_data;
00214 
00215         if (c->pic.data[0])
00216                 avctx->release_buffer(avctx, &c->pic);
00217 
00218         return 0;
00219 }

static int decode_frame ( AVCodecContext avctx,
void *  data,
int *  data_size,
const uint8_t *  buf,
int  buf_size 
) [static]

Definition at line 60 of file 8bps.c.

References av_log(), AV_LOG_ERROR, AVPALETTE_SIZE, be2me_16, c, FF_BUFFER_HINTS_VALID, AVCodecContext::get_buffer, AVCodecContext::height, height, AVCodecContext::palctrl, AVPaletteControl::palette, AVPaletteControl::palette_changed, AVCodecContext::pix_fmt, PIX_FMT_RGB32, AVCodecContext::priv_data, and AVCodecContext::release_buffer.

00061 {
00062         EightBpsContext * const c = avctx->priv_data;
00063         const unsigned char *encoded = buf;
00064         unsigned char *pixptr, *pixptr_end;
00065         unsigned int height = avctx->height; // Real image height
00066         unsigned int dlen, p, row;
00067         const unsigned char *lp, *dp;
00068         unsigned char count;
00069         unsigned int px_inc;
00070         unsigned int planes = c->planes;
00071         unsigned char *planemap = c->planemap;
00072 
00073         if(c->pic.data[0])
00074                 avctx->release_buffer(avctx, &c->pic);
00075 
00076         c->pic.reference = 0;
00077         c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
00078         if(avctx->get_buffer(avctx, &c->pic) < 0){
00079                 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00080                 return -1;
00081         }
00082 
00083         /* Set data pointer after line lengths */
00084         dp = encoded + planes * (height << 1);
00085 
00086         /* Ignore alpha plane, don't know what to do with it */
00087         if (planes == 4)
00088                 planes--;
00089 
00090         px_inc = planes + (avctx->pix_fmt == PIX_FMT_RGB32);
00091 
00092         for (p = 0; p < planes; p++) {
00093                 /* Lines length pointer for this plane */
00094                 lp = encoded + p * (height << 1);
00095 
00096                 /* Decode a plane */
00097                 for(row = 0; row < height; row++) {
00098                         pixptr = c->pic.data[0] + row * c->pic.linesize[0] + planemap[p];
00099                         pixptr_end = pixptr + c->pic.linesize[0];
00100                         dlen = be2me_16(*(const unsigned short *)(lp+row*2));
00101                         /* Decode a row of this plane */
00102                         while(dlen > 0) {
00103                                 if(dp + 1 >= buf+buf_size) return -1;
00104                                 if ((count = *dp++) <= 127) {
00105                                         count++;
00106                                         dlen -= count + 1;
00107                                         if (pixptr + count * px_inc > pixptr_end)
00108                                             break;
00109                                         if(dp + count > buf+buf_size) return -1;
00110                                         while(count--) {
00111                                                 *pixptr = *dp++;
00112                                                 pixptr += px_inc;
00113                                         }
00114                                 } else {
00115                                         count = 257 - count;
00116                                         if (pixptr + count * px_inc > pixptr_end)
00117                                             break;
00118                                         while(count--) {
00119                                                 *pixptr = *dp;
00120                                                 pixptr += px_inc;
00121                                         }
00122                                         dp++;
00123                                         dlen -= 2;
00124                                 }
00125                         }
00126                 }
00127         }
00128 
00129         if (avctx->palctrl) {
00130                 memcpy (c->pic.data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
00131                 if (avctx->palctrl->palette_changed) {
00132                         c->pic.palette_has_changed = 1;
00133                         avctx->palctrl->palette_changed = 0;
00134                 } else
00135                         c->pic.palette_has_changed = 0;
00136         }
00137 
00138         *data_size = sizeof(AVFrame);
00139         *(AVFrame*)data = c->pic;
00140 
00141         /* always report that the buffer was completely consumed */
00142         return buf_size;
00143 }

static av_cold int decode_init ( AVCodecContext avctx  )  [static]

Definition at line 151 of file 8bps.c.

References av_log(), AV_LOG_ERROR, avcodec_check_dimensions(), AVCodecContext::bits_per_sample, c, AVCodecContext::get_format, AVCodecContext::height, NULL, AVCodecContext::palctrl, AVCodecContext::pix_fmt, PIX_FMT_PAL8, PIX_FMT_RGB32, pixfmt_rgb24, AVCodecContext::priv_data, and AVCodecContext::width.

00152 {
00153         EightBpsContext * const c = avctx->priv_data;
00154 
00155         c->avctx = avctx;
00156 
00157         c->pic.data[0] = NULL;
00158 
00159     if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
00160         return 1;
00161     }
00162 
00163         switch (avctx->bits_per_sample) {
00164                 case 8:
00165                         avctx->pix_fmt = PIX_FMT_PAL8;
00166                         c->planes = 1;
00167                         c->planemap[0] = 0; // 1st plane is palette indexes
00168                         if (avctx->palctrl == NULL) {
00169                                 av_log(avctx, AV_LOG_ERROR, "Error: PAL8 format but no palette from demuxer.\n");
00170                                 return -1;
00171                         }
00172                         break;
00173                 case 24:
00174                         avctx->pix_fmt = avctx->get_format(avctx, pixfmt_rgb24);
00175                         c->planes = 3;
00176                         c->planemap[0] = 2; // 1st plane is red
00177                         c->planemap[1] = 1; // 2nd plane is green
00178                         c->planemap[2] = 0; // 3rd plane is blue
00179                         break;
00180                 case 32:
00181                         avctx->pix_fmt = PIX_FMT_RGB32;
00182                         c->planes = 4;
00183 #ifdef WORDS_BIGENDIAN
00184                         c->planemap[0] = 1; // 1st plane is red
00185                         c->planemap[1] = 2; // 2nd plane is green
00186                         c->planemap[2] = 3; // 3rd plane is blue
00187                         c->planemap[3] = 0; // 4th plane is alpha???
00188 #else
00189                         c->planemap[0] = 2; // 1st plane is red
00190                         c->planemap[1] = 1; // 2nd plane is green
00191                         c->planemap[2] = 0; // 3rd plane is blue
00192                         c->planemap[3] = 3; // 4th plane is alpha???
00193 #endif
00194                         break;
00195                 default:
00196                         av_log(avctx, AV_LOG_ERROR, "Error: Unsupported color depth: %u.\n", avctx->bits_per_sample);
00197                         return -1;
00198         }
00199 
00200   return 0;
00201 }


Variable Documentation

AVCodec eightbps_decoder

Initial value:

 {
        "8bps",
        CODEC_TYPE_VIDEO,
        CODEC_ID_8BPS,
        sizeof(EightBpsContext),
        decode_init,
        NULL,
        decode_end,
        decode_frame,
        CODEC_CAP_DR1,
        .long_name = NULL_IF_CONFIG_SMALL("QuickTime 8BPS video"),
}

Definition at line 223 of file 8bps.c.

enum PixelFormat pixfmt_rgb24[] = {PIX_FMT_BGR24, PIX_FMT_RGB32, PIX_FMT_NONE} [static]

Definition at line 40 of file 8bps.c.

Referenced by decode_init().


Generated on Thu Aug 28 16:44:29 2008 for libextractor by  doxygen 1.5.1