FFmpeg
Data Structures | Macros | Functions | Variables
xan.c File Reference
#include <string.h>
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "decode.h"
#include "get_bits.h"

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
 

Functions

static av_cold int xan_decode_end (AVCodecContext *avctx)
 
static av_cold int xan_decode_init (AVCodecContext *avctx)
 
static int xan_huffman_decode (uint8_t *dest, int dest_len, const uint8_t *src, int src_len)
 
static void xan_unpack (uint8_t *dest, int dest_len, const uint8_t *src, int src_len)
 unpack simple compression More...
 
static void xan_wc3_output_pixel_run (XanContext *s, AVFrame *frame, const uint8_t *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, AVFrame *frame, 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...
 
const FFCodec 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

◆ BITSTREAM_READER_LE

#define BITSTREAM_READER_LE

Definition at line 36 of file xan.c.

◆ RUNTIME_GAMMA

#define RUNTIME_GAMMA   0

Definition at line 43 of file xan.c.

◆ VGA__TAG

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

Definition at line 45 of file xan.c.

◆ PALT_TAG

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

Definition at line 46 of file xan.c.

◆ SHOT_TAG

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

Definition at line 47 of file xan.c.

◆ PALETTE_COUNT

#define PALETTE_COUNT   256

Definition at line 48 of file xan.c.

◆ PALETTE_SIZE

#define PALETTE_SIZE   (PALETTE_COUNT * 3)

Definition at line 49 of file xan.c.

◆ PALETTES_MAX

#define PALETTES_MAX   256

Definition at line 50 of file xan.c.

Function Documentation

◆ xan_decode_end()

static av_cold int xan_decode_end ( AVCodecContext avctx)
static

Definition at line 74 of file xan.c.

◆ xan_decode_init()

static av_cold int xan_decode_init ( AVCodecContext avctx)
static

Definition at line 87 of file xan.c.

◆ xan_huffman_decode()

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

Definition at line 112 of file xan.c.

Referenced by xan_wc3_decode_frame().

◆ xan_unpack()

static void xan_unpack ( uint8_t *  dest,
int  dest_len,
const uint8_t *  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 153 of file xan.c.

Referenced by xan_wc3_decode_frame().

◆ xan_wc3_output_pixel_run()

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

Definition at line 207 of file xan.c.

Referenced by xan_wc3_decode_frame().

◆ xan_wc3_copy_pixel_run()

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 237 of file xan.c.

Referenced by xan_wc3_decode_frame().

◆ xan_wc3_decode_frame()

static int xan_wc3_decode_frame ( XanContext s,
AVFrame frame 
)
static

Definition at line 295 of file xan.c.

Referenced by xan_decode_frame().

◆ xan_decode_frame()

static int xan_decode_frame ( AVCodecContext avctx,
AVFrame frame,
int got_frame,
AVPacket avpkt 
)
static

Definition at line 539 of file xan.c.

Variable Documentation

◆ gamma_lookup

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 503 of file xan.c.

Referenced by xan_decode_frame().

◆ ff_xan_wc3_decoder

const FFCodec ff_xan_wc3_decoder
Initial value:
= {
.p.name = "xan_wc3",
CODEC_LONG_NAME("Wing Commander III / Xan"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(XanContext),
.close = xan_decode_end,
.p.capabilities = AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 635 of file xan.c.

FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
xan_decode_end
static av_cold int xan_decode_end(AVCodecContext *avctx)
Definition: xan.c:74
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
xan_decode_init
static av_cold int xan_decode_init(AVCodecContext *avctx)
Definition: xan.c:87
AV_CODEC_ID_XAN_WC3
@ AV_CODEC_ID_XAN_WC3
Definition: codec_id.h:92
XanContext
Definition: xan.c:52
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
xan_decode_frame
static int xan_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: xan.c:539