FFmpeg
Loading...
Searching...
No Matches
ansi.c File Reference

ASCII/ANSI art decoder. More...

#include "libavutil/attributes.h"
#include "libavutil/common.h"
#include "libavutil/frame.h"
#include "libavutil/xga_font_data.h"
#include "avcodec.h"
#include "cga_data.h"
#include "codec_internal.h"
#include "decode.h"

Go to the source code of this file.

Data Structures

struct  AnsiContext
 

Macros

#define ATTR_BOLD   0x01
 Bold/Bright-foreground (mode 1)
 
#define ATTR_FAINT   0x02
 Faint (mode 2)
 
#define ATTR_ITALICS   0x04
 Italics (mode 3)
 
#define ATTR_UNDERLINE   0x08
 Underline (mode 4)
 
#define ATTR_BLINK   0x10
 Blink/Bright-background (mode 5)
 
#define ATTR_REVERSE   0x40
 Reverse (mode 7)
 
#define ATTR_CONCEALED   0x80
 Concealed (mode 8)
 
#define DEFAULT_FG_COLOR   7
 CGA color index.
 
#define DEFAULT_BG_COLOR   0
 
#define DEFAULT_SCREEN_MODE   3
 80x25
 
#define FONT_WIDTH   8
 Font width.
 
#define MAX_NB_ARGS   4
 
#define COLOR(x)
 
#define GRAY(x)
 

Functions

static av_cold int decode_init (AVCodecContext *avctx)
 
static void set_palette (uint32_t *pal)
 
static void hscroll (AVCodecContext *avctx)
 
static void erase_line (AVCodecContext *avctx, int xoffset, int xlength)
 
static void erase_screen (AVCodecContext *avctx)
 
static void draw_char (AVCodecContext *avctx, int c)
 Draw character to screen.
 
static int execute_code (AVCodecContext *avctx, int c)
 Execute ANSI escape code.
 
static int decode_frame (AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
 
static av_cold int decode_close (AVCodecContext *avctx)
 

Variables

static const uint8_t ansi_to_cga [16]
 map ansi color index to cga palette index
 
static const FFCodecDefault ansi_defaults []
 
const FFCodec ff_ansi_decoder
 

Detailed Description

ASCII/ANSI art decoder.

Definition in file ansi.c.

Macro Definition Documentation

◆ ATTR_BOLD

#define ATTR_BOLD   0x01

Bold/Bright-foreground (mode 1)

Definition at line 36 of file ansi.c.

Referenced by draw_char().

◆ ATTR_FAINT

#define ATTR_FAINT   0x02

Faint (mode 2)

Definition at line 37 of file ansi.c.

◆ ATTR_ITALICS

#define ATTR_ITALICS   0x04

Italics (mode 3)

Definition at line 38 of file ansi.c.

◆ ATTR_UNDERLINE

#define ATTR_UNDERLINE   0x08

Underline (mode 4)

Definition at line 39 of file ansi.c.

◆ ATTR_BLINK

#define ATTR_BLINK   0x10

Blink/Bright-background (mode 5)

Definition at line 40 of file ansi.c.

Referenced by draw_char().

◆ ATTR_REVERSE

#define ATTR_REVERSE   0x40

Reverse (mode 7)

Definition at line 41 of file ansi.c.

Referenced by draw_char().

◆ ATTR_CONCEALED

#define ATTR_CONCEALED   0x80

Concealed (mode 8)

Definition at line 42 of file ansi.c.

Referenced by draw_char().

◆ DEFAULT_FG_COLOR

#define DEFAULT_FG_COLOR   7

CGA color index.

Definition at line 44 of file ansi.c.

Referenced by decode_init(), and execute_code().

◆ DEFAULT_BG_COLOR

#define DEFAULT_BG_COLOR   0

Definition at line 45 of file ansi.c.

Referenced by decode_init(), erase_line(), erase_screen(), execute_code(), hscroll(), and hscroll().

◆ DEFAULT_SCREEN_MODE

#define DEFAULT_SCREEN_MODE   3

80x25

Definition at line 46 of file ansi.c.

Referenced by execute_code().

◆ FONT_WIDTH

#define FONT_WIDTH   8

Font width.

Definition at line 48 of file ansi.c.

Referenced by decode_frame(), decode_frame(), decode_init(), decode_init(), draw_char(), draw_char(), and execute_code().

◆ MAX_NB_ARGS

#define MAX_NB_ARGS   4

Definition at line 75 of file ansi.c.

Referenced by decode_frame(), and execute_code().

◆ COLOR

◆ GRAY

#define GRAY ( x)
Value:
((x) * 10 + 8)

Referenced by set_palette().

Function Documentation

◆ decode_init()

static av_cold int decode_init ( AVCodecContext * avctx)
static

Definition at line 80 of file ansi.c.

◆ set_palette()

static void set_palette ( uint32_t * pal)
static

Definition at line 107 of file ansi.c.

Referenced by decode_frame(), and execute_code().

◆ hscroll()

static void hscroll ( AVCodecContext * avctx)
static

Definition at line 122 of file ansi.c.

Referenced by decode_frame(), and draw_char().

◆ erase_line()

static void erase_line ( AVCodecContext * avctx,
int xoffset,
int xlength )
static

Definition at line 142 of file ansi.c.

Referenced by execute_code().

◆ erase_screen()

static void erase_screen ( AVCodecContext * avctx)
static

Definition at line 151 of file ansi.c.

Referenced by decode_frame(), and execute_code().

◆ draw_char()

static void draw_char ( AVCodecContext * avctx,
int c )
static

Draw character to screen.

Definition at line 163 of file ansi.c.

Referenced by decode_frame().

◆ execute_code()

static int execute_code ( AVCodecContext * avctx,
int c )
static

Execute ANSI escape code.

Returns
0 on success, negative on error

Definition at line 190 of file ansi.c.

Referenced by decode_frame().

◆ decode_frame()

static int decode_frame ( AVCodecContext * avctx,
AVFrame * rframe,
int * got_frame,
AVPacket * avpkt )
static

Definition at line 356 of file ansi.c.

◆ decode_close()

static av_cold int decode_close ( AVCodecContext * avctx)
static

Definition at line 469 of file ansi.c.

Variable Documentation

◆ ansi_to_cga

const uint8_t ansi_to_cga[16]
static
Initial value:
= {
0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15
}

map ansi color index to cga palette index

Definition at line 51 of file ansi.c.

Referenced by execute_code().

◆ ansi_defaults

const FFCodecDefault ansi_defaults[]
static
Initial value:
= {
{ "max_pixels", "640*480" },
{ NULL },
}
#define NULL
Definition coverity.c:32

Definition at line 477 of file ansi.c.

◆ ff_ansi_decoder

const FFCodec ff_ansi_decoder
Initial value:
= {
.p.name = "ansi",
CODEC_LONG_NAME("ASCII/ANSI art"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(AnsiContext),
.p.capabilities = AV_CODEC_CAP_DR1,
.defaults = ansi_defaults,
}
static const FFCodecDefault ansi_defaults[]
Definition ansi.c:477
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_ANSI
Definition codec_id.h:192
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static av_cold int decode_init(AVCodecContext *avctx)
Definition 4xm.c:998
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Definition 4xm.c:837
static av_cold int decode_close(AVCodecContext *avctx)
Definition aacdec.c:1220

Definition at line 482 of file ansi.c.