xan.c File Reference

Xan video decoder for Wing Commander III computer game by Mario Brito (mbrit.nosp@m.o@st.nosp@m.udent.nosp@m..dei.nosp@m..uc.p.nosp@m.t) and Mike Melanson (melan.nosp@m.son@.nosp@m.pcisy.nosp@m.s.ne.nosp@m.t) More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "avcodec.h"
#include "bytestream.h"
#include "get_bits.h"
#include "internal.h"
Include dependency graph for xan.c:

Go to the source code of this file.

Data Structures

struct  XanContext
 

Macros

#define BITSTREAM_READER_LE
 
#define RUNTIME_GAMMA   0
 
#define VGA__TAG   MKTAG('V', 'G', 'A', ' ')
 
#define PALT_TAG   MKTAG('P', 'A', 'L', 'T')
 
#define SHOT_TAG   MKTAG('S', 'H', 'O', 'T')
 
#define PALETTE_COUNT   256
 
#define PALETTE_SIZE   (PALETTE_COUNT * 3)
 
#define PALETTES_MAX   256
 

Typedefs

typedef struct XanContext XanContext
 

Functions

static av_cold int xan_decode_end (AVCodecContext *avctx)
 
static av_cold int xan_decode_init (AVCodecContext *avctx)
 
static int xan_huffman_decode (unsigned char *dest, int dest_len, const unsigned char *src, int src_len)
 
static void xan_unpack (unsigned char *dest, int dest_len, const unsigned char *src, int src_len)
 unpack simple compression More...
 
static void xan_wc3_output_pixel_run (XanContext *s, AVFrame *frame, const unsigned char *pixel_buffer, int x, int y, int pixel_count)
 
static void xan_wc3_copy_pixel_run (XanContext *s, AVFrame *frame, int x, int y, int pixel_count, int motion_x, int motion_y)
 
static int xan_wc3_decode_frame (XanContext *s, AVFrame *frame)
 
static int xan_decode_frame (AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
 

Variables

static const uint8_t gamma_lookup [256]
 This is a gamma correction that xan3 applies to all palette entries. More...
 
AVCodec ff_xan_wc3_decoder
 

Detailed Description

Xan video decoder for Wing Commander III computer game by Mario Brito (mbrit.nosp@m.o@st.nosp@m.udent.nosp@m..dei.nosp@m..uc.p.nosp@m.t) and Mike Melanson (melan.nosp@m.son@.nosp@m.pcisy.nosp@m.s.ne.nosp@m.t)

The xan_wc3 decoder outputs PAL8 data.

Definition in file xan.c.

Macro Definition Documentation

#define BITSTREAM_READER_LE

Definition at line 39 of file xan.c.

#define PALETTE_COUNT   256

Definition at line 48 of file xan.c.

Referenced by xan_decode_frame().

#define PALETTE_SIZE   (PALETTE_COUNT * 3)

Definition at line 49 of file xan.c.

Referenced by xan_decode_frame().

#define PALETTES_MAX   256

Definition at line 50 of file xan.c.

Referenced by xan_decode_frame().

#define PALT_TAG   MKTAG('P', 'A', 'L', 'T')

Definition at line 46 of file xan.c.

Referenced by xan_decode_frame().

#define RUNTIME_GAMMA   0

Definition at line 43 of file xan.c.

#define SHOT_TAG   MKTAG('S', 'H', 'O', 'T')

Definition at line 47 of file xan.c.

Referenced by xan_decode_frame().

#define VGA__TAG   MKTAG('V', 'G', 'A', ' ')

Definition at line 45 of file xan.c.

Referenced by xan_decode_frame().

Typedef Documentation

typedef struct XanContext XanContext

Function Documentation

static av_cold int xan_decode_end ( AVCodecContext avctx)
static

Definition at line 627 of file xan.c.

Referenced by xan_decode_init().

static int xan_decode_frame ( AVCodecContext avctx,
void data,
int *  got_frame,
AVPacket avpkt 
)
static

Definition at line 529 of file xan.c.

static av_cold int xan_decode_init ( AVCodecContext avctx)
static

Definition at line 76 of file xan.c.

static int xan_huffman_decode ( unsigned char *  dest,
int  dest_len,
const unsigned char *  src,
int  src_len 
)
static

Definition at line 104 of file xan.c.

Referenced by xan_wc3_decode_frame().

static void xan_unpack ( unsigned char *  dest,
int  dest_len,
const unsigned char *  src,
int  src_len 
)
static

unpack simple compression

Parameters
destdestination buffer of dest_len, must be padded with at least 130 bytes

Definition at line 142 of file xan.c.

Referenced by xan_wc3_decode_frame().

static void xan_wc3_copy_pixel_run ( XanContext s,
AVFrame frame,
int  x,
int  y,
int  pixel_count,
int  motion_x,
int  motion_y 
)
inlinestatic

Definition at line 226 of file xan.c.

Referenced by xan_wc3_decode_frame().

static int xan_wc3_decode_frame ( XanContext s,
AVFrame frame 
)
static

Definition at line 284 of file xan.c.

Referenced by xan_decode_frame().

static void xan_wc3_output_pixel_run ( XanContext s,
AVFrame frame,
const unsigned char *  pixel_buffer,
int  x,
int  y,
int  pixel_count 
)
inlinestatic

Definition at line 196 of file xan.c.

Referenced by xan_wc3_decode_frame().

Variable Documentation

AVCodec ff_xan_wc3_decoder
Initial value:
= {
.name = "xan_wc3",
.priv_data_size = sizeof(XanContext),
.capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Wing Commander III / Xan"),
}
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static av_cold int xan_decode_init(AVCodecContext *avctx)
Definition: xan.c:76
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
struct XanContext XanContext
static av_cold int xan_decode_end(AVCodecContext *avctx)
Definition: xan.c:627
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
static int xan_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: xan.c:529
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868

Definition at line 640 of file xan.c.

const uint8_t gamma_lookup[256]
static

This is a gamma correction that xan3 applies to all palette entries.

There is a peculiarity, namely that the values are clamped to 253 - it seems likely that this table was calculated by a buggy fixed-point implementation, the one above under RUNTIME_GAMMA behaves like this for example. The exponent value of 0.8 can be explained by this as well, since 0.8 = 4/5 and thus pow(x, 0.8) is still easy to calculate. Also, the input values are first rotated to the left by 2.

Definition at line 493 of file xan.c.

Referenced by xan_decode_frame().