annotate ansi.c @ 12481:e9a1e1ba768f libavcodec

Allow the lowres option to affect audio codecs, too
author mstorsjo
date Fri, 10 Sep 2010 06:19:31 +0000
parents 601fbb943758
children 34beb0af8204
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12186
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
1 /*
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
2 * ASCII/ANSI art decoder
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
3 * Copyright (c) 2010 Peter Ross <pross@xvid.org>
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
4 *
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
5 * This file is part of FFmpeg.
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
6 *
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
11 *
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
15 * Lesser General Public License for more details.
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
16 *
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
20 */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
21
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
22 /**
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
23 * @file
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
24 * ASCII/ANSI art decoder
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
25 */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
26
12448
601fbb943758 Use quotes instead of angle brackets for local #includes.
diego
parents: 12283
diff changeset
27 #include "libavutil/lfg.h"
12186
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
28 #include "avcodec.h"
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
29 #include "cga_data.h"
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
30
12283
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
31 #define ATTR_BOLD 0x01 /**< Bold/Bright-foreground (mode 1) */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
32 #define ATTR_FAINT 0x02 /**< Faint (mode 2) */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
33 #define ATTR_UNDERLINE 0x08 /**< Underline (mode 4) */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
34 #define ATTR_BLINK 0x10 /**< Blink/Bright-background (mode 5) */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
35 #define ATTR_REVERSE 0x40 /**< Reverse (mode 7) */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
36 #define ATTR_CONCEALED 0x80 /**< Concealed (mode 8) */
12186
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
37
12283
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
38 #define DEFAULT_FG_COLOR 7 /**< CGA color index */
12186
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
39 #define DEFAULT_BG_COLOR 0
12283
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
40 #define DEFAULT_SCREEN_MODE 3 /**< 80x25 */
12186
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
41
12283
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
42 #define FONT_WIDTH 8 /**< Font width */
12186
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
43
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
44 /** map ansi color index to cga palette index */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
45 static const uint8_t ansi_to_cga[16] = {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
46 0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
47 };
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
48
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
49 typedef struct {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
50 AVFrame frame;
12283
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
51 int x; /**< x cursor position (pixels) */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
52 int y; /**< y cursor position (pixels) */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
53 int sx; /**< saved x cursor position (pixels) */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
54 int sy; /**< saved y cursor position (pixels) */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
55 const uint8_t* font; /**< font */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
56 int font_height; /**< font height */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
57 int attributes; /**< attribute flags */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
58 int fg; /**< foreground color */
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
59 int bg; /**< background color */
12186
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
60
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
61 /* ansi parser state machine */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
62 enum {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
63 STATE_NORMAL = 0,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
64 STATE_ESCAPE,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
65 STATE_CODE,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
66 STATE_MUSIC_PREAMBLE
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
67 } state;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
68 #define MAX_NB_ARGS 4
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
69 int args[MAX_NB_ARGS];
12283
a08f20066719 Fix doxy that refers to the wrong variable.
michael
parents: 12186
diff changeset
70 int nb_args; /**< number of arguments (may exceed MAX_NB_ARGS) */
12186
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
71 } AnsiContext;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
72
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
73 static av_cold int decode_init(AVCodecContext *avctx)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
74 {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
75 AnsiContext *s = avctx->priv_data;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
76 avctx->pix_fmt = PIX_FMT_PAL8;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
77
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
78 /* defaults */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
79 s->font = ff_vga16_font;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
80 s->font_height = 16;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
81 s->fg = DEFAULT_FG_COLOR;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
82 s->bg = DEFAULT_BG_COLOR;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
83
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
84 if (!avctx->width || !avctx->height)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
85 avcodec_set_dimensions(avctx, 80<<3, 25<<4);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
86
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
87 return 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
88 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
89
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
90 static void hscroll(AVCodecContext *avctx)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
91 {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
92 AnsiContext *s = avctx->priv_data;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
93 int i;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
94
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
95 if (s->y < avctx->height - s->font_height) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
96 s->y += s->font_height;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
97 return;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
98 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
99
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
100 i = 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
101 for (; i < avctx->height - s->font_height; i++)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
102 memcpy(s->frame.data[0] + i * s->frame.linesize[0],
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
103 s->frame.data[0] + (i + s->font_height) * s->frame.linesize[0],
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
104 avctx->width);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
105 for (; i < avctx->height; i++)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
106 memset(s->frame.data[0] + i * s->frame.linesize[0],
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
107 DEFAULT_BG_COLOR, avctx->width);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
108 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
109
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
110 static void erase_line(AVCodecContext * avctx, int xoffset, int xlength)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
111 {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
112 AnsiContext *s = avctx->priv_data;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
113 int i;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
114 for (i = 0; i < s->font_height; i++)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
115 memset(s->frame.data[0] + (s->y + i)*s->frame.linesize[0] + xoffset,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
116 DEFAULT_BG_COLOR, xlength);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
117 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
118
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
119 static void erase_screen(AVCodecContext *avctx)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
120 {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
121 AnsiContext *s = avctx->priv_data;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
122 int i;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
123 for (i = 0; i < avctx->height; i++)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
124 memset(s->frame.data[0] + i * s->frame.linesize[0], DEFAULT_BG_COLOR, avctx->width);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
125 s->x = s->y = 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
126 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
127
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
128 /**
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
129 * Draw character to screen
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
130 */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
131 static void draw_char(AVCodecContext *avctx, int c)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
132 {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
133 AnsiContext *s = avctx->priv_data;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
134 int fg = s->fg;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
135 int bg = s->bg;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
136
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
137 if ((s->attributes & ATTR_BOLD))
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
138 fg += 8;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
139 if ((s->attributes & ATTR_BLINK))
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
140 bg += 8;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
141 if ((s->attributes & ATTR_REVERSE))
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
142 FFSWAP(int, fg, bg);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
143 if ((s->attributes & ATTR_CONCEALED))
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
144 fg = bg;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
145 ff_draw_pc_font(s->frame.data[0] + s->y * s->frame.linesize[0] + s->x,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
146 s->frame.linesize[0], s->font, s->font_height, c, fg, bg);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
147 s->x += FONT_WIDTH;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
148 if (s->x >= avctx->width) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
149 s->x = 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
150 hscroll(avctx);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
151 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
152 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
153
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
154 /**
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
155 * Execute ANSI escape code
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
156 * @param <0 error
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
157 */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
158 static int execute_code(AVCodecContext * avctx, int c)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
159 {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
160 AnsiContext *s = avctx->priv_data;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
161 int ret, i, width, height;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
162 switch(c) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
163 case 'A': //Cursor Up
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
164 s->y = FFMAX(s->y - (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), 0);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
165 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
166 case 'B': //Cursor Down
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
167 s->y = FFMIN(s->y + (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), avctx->height - s->font_height);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
168 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
169 case 'C': //Cursor Right
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
170 s->x = FFMIN(s->x + (s->nb_args > 0 ? s->args[0]*FONT_WIDTH : FONT_WIDTH), avctx->width - FONT_WIDTH);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
171 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
172 case 'D': //Cursor Left
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
173 s->x = FFMAX(s->x - (s->nb_args > 0 ? s->args[0]*FONT_WIDTH : FONT_WIDTH), 0);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
174 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
175 case 'H': //Cursor Position
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
176 case 'f': //Horizontal and Vertical Position
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
177 s->y = s->nb_args > 0 ? av_clip((s->args[0] - 1)*s->font_height, 0, avctx->height - s->font_height) : 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
178 s->x = s->nb_args > 1 ? av_clip((s->args[1] - 1)*FONT_WIDTH, 0, avctx->width - FONT_WIDTH) : 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
179 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
180 case 'h': //set creen mode
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
181 case 'l': //reset screen mode
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
182 if (s->nb_args < 2)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
183 s->args[0] = DEFAULT_SCREEN_MODE;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
184 switch(s->args[0]) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
185 case 0: case 1: case 4: case 5: case 13: case 19: //320x200 (25 rows)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
186 s->font = ff_cga_font;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
187 s->font_height = 8;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
188 width = 40<<3;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
189 height = 25<<3;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
190 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
191 case 2: case 3: //640x400 (25 rows)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
192 s->font = ff_vga16_font;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
193 s->font_height = 16;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
194 width = 80<<3;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
195 height = 25<<4;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
196 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
197 case 6: case 14: //640x200 (25 rows)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
198 s->font = ff_cga_font;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
199 s->font_height = 8;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
200 width = 80<<3;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
201 height = 25<<3;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
202 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
203 case 7: //set line wrapping
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
204 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
205 case 15: case 16: //640x350 (43 rows)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
206 s->font = ff_cga_font;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
207 s->font_height = 8;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
208 width = 80<<3;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
209 height = 43<<3;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
210 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
211 case 17: case 18: //640x480 (60 rows)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
212 s->font = ff_cga_font;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
213 s->font_height = 8;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
214 width = 80<<3;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
215 height = 60<<4;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
216 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
217 default:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
218 av_log_ask_for_sample(avctx, "unsupported screen mode\n");
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
219 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
220 if (width != avctx->width || height != avctx->height) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
221 if (s->frame.data[0])
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
222 avctx->release_buffer(avctx, &s->frame);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
223 avcodec_set_dimensions(avctx, width, height);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
224 ret = avctx->get_buffer(avctx, &s->frame);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
225 if (ret < 0) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
226 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
227 return ret;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
228 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
229 s->frame.pict_type = FF_I_TYPE;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
230 s->frame.palette_has_changed = 1;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
231 memcpy(s->frame.data[1], ff_cga_palette, 16 * 4);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
232 erase_screen(avctx);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
233 } else if (c == 'l') {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
234 erase_screen(avctx);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
235 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
236 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
237 case 'J': //Erase in Page
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
238 switch (s->args[0]) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
239 case 0:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
240 erase_line(avctx, s->x, avctx->width - s->x);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
241 if (s->y < avctx->height - s->font_height)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
242 memset(s->frame.data[0] + (s->y + s->font_height)*s->frame.linesize[0],
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
243 DEFAULT_BG_COLOR, (avctx->height - s->y - s->font_height)*s->frame.linesize[0]);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
244 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
245 case 1:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
246 erase_line(avctx, 0, s->x);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
247 if (s->y > 0)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
248 memset(s->frame.data[0], DEFAULT_BG_COLOR, s->y * s->frame.linesize[0]);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
249 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
250 case 2:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
251 erase_screen(avctx);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
252 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
253 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
254 case 'K': //Erase in Line
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
255 switch(s->args[0]) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
256 case 0:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
257 erase_line(avctx, s->x, avctx->width - s->x);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
258 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
259 case 1:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
260 erase_line(avctx, 0, s->x);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
261 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
262 case 2:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
263 erase_line(avctx, 0, avctx->width);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
264 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
265 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
266 case 'm': //Select Graphics Rendition
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
267 if (s->nb_args == 0) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
268 s->nb_args = 1;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
269 s->args[0] = 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
270 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
271 for (i = 0; i < FFMIN(s->nb_args, MAX_NB_ARGS); i++) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
272 int m = s->args[i];
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
273 if (m == 0) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
274 s->attributes = 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
275 s->fg = DEFAULT_FG_COLOR;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
276 s->bg = DEFAULT_BG_COLOR;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
277 } else if (m == 1 || m == 2 || m == 4 || m == 5 || m == 7 || m == 8) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
278 s->attributes |= 1 << (m - 1);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
279 } else if (m >= 30 && m <= 38) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
280 s->fg = ansi_to_cga[m - 30];
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
281 } else if (m == 39) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
282 s->fg = ansi_to_cga[DEFAULT_FG_COLOR];
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
283 } else if (m >= 40 && m <= 47) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
284 s->bg = ansi_to_cga[m - 40];
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
285 } else if (m == 49) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
286 s->fg = ansi_to_cga[DEFAULT_BG_COLOR];
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
287 } else {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
288 av_log_ask_for_sample(avctx, "unsupported rendition parameter\n");
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
289 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
290 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
291 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
292 case 'n': //Device Status Report
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
293 case 'R': //report current line and column
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
294 /* ignore */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
295 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
296 case 's': //Save Cursor Position
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
297 s->sx = s->x;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
298 s->sy = s->y;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
299 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
300 case 'u': //Restore Cursor Position
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
301 s->x = av_clip(s->sx, 0, avctx->width - FONT_WIDTH);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
302 s->y = av_clip(s->sy, 0, avctx->height - s->font_height);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
303 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
304 default:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
305 av_log_ask_for_sample(avctx, "unsupported escape code\n");
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
306 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
307 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
308 return 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
309 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
310
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
311 static int decode_frame(AVCodecContext *avctx,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
312 void *data, int *data_size,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
313 AVPacket *avpkt)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
314 {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
315 AnsiContext *s = avctx->priv_data;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
316 uint8_t *buf = avpkt->data;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
317 int buf_size = avpkt->size;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
318 const uint8_t *buf_end = buf+buf_size;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
319 int ret, i, count;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
320
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
321 ret = avctx->reget_buffer(avctx, &s->frame);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
322 if (ret < 0){
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
323 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
324 return ret;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
325 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
326 s->frame.pict_type = FF_I_TYPE;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
327 s->frame.palette_has_changed = 1;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
328 memcpy(s->frame.data[1], ff_cga_palette, 16 * 4);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
329
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
330 while(buf < buf_end) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
331 switch(s->state) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
332 case STATE_NORMAL:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
333 switch (buf[0]) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
334 case 0x00: //NUL
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
335 case 0x07: //BEL
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
336 case 0x1A: //SUB
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
337 /* ignore */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
338 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
339 case 0x08: //BS
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
340 s->x = FFMAX(s->x - 1, 0);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
341 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
342 case 0x09: //HT
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
343 i = s->x / FONT_WIDTH;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
344 count = ((i + 8) & ~7) - i;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
345 for (i = 0; i < count; i++)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
346 draw_char(avctx, ' ');
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
347 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
348 case 0x0A: //LF
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
349 hscroll(avctx);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
350 case 0x0D: //CR
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
351 s->x = 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
352 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
353 case 0x0C: //FF
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
354 erase_screen(avctx);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
355 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
356 case 0x1B: //ESC
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
357 s->state = STATE_ESCAPE;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
358 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
359 default:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
360 draw_char(avctx, buf[0]);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
361 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
362 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
363 case STATE_ESCAPE:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
364 if (buf[0] == '[') {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
365 s->state = STATE_CODE;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
366 s->nb_args = 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
367 s->args[0] = 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
368 } else {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
369 s->state = STATE_NORMAL;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
370 draw_char(avctx, 0x1B);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
371 return -1;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
372 continue;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
373 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
374 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
375 case STATE_CODE:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
376 switch(buf[0]) {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
377 case '0': case '1': case '2': case '3': case '4':
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
378 case '5': case '6': case '7': case '8': case '9':
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
379 if (s->nb_args < MAX_NB_ARGS)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
380 s->args[s->nb_args] = s->args[s->nb_args] * 10 + buf[0] - '0';
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
381 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
382 case ';':
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
383 s->nb_args++;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
384 if (s->nb_args < MAX_NB_ARGS)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
385 s->args[s->nb_args] = 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
386 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
387 case 'M':
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
388 s->state = STATE_MUSIC_PREAMBLE;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
389 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
390 case '=': case '?':
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
391 /* ignore */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
392 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
393 default:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
394 if (s->nb_args > MAX_NB_ARGS)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
395 av_log(avctx, AV_LOG_WARNING, "args overflow (%i)\n", s->nb_args);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
396 if (s->nb_args < MAX_NB_ARGS && s->args[s->nb_args])
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
397 s->nb_args++;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
398 if (execute_code(avctx, buf[0]) < 0)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
399 return -1;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
400 s->state = STATE_NORMAL;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
401 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
402 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
403 case STATE_MUSIC_PREAMBLE:
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
404 if (buf[0] == 0x0E || buf[0] == 0x1B)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
405 s->state = STATE_NORMAL;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
406 /* ignore music data */
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
407 break;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
408 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
409 buf++;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
410 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
411
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
412 *data_size = sizeof(AVFrame);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
413 *(AVFrame*)data = s->frame;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
414 return buf_size;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
415 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
416
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
417 static av_cold int decode_close(AVCodecContext *avctx)
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
418 {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
419 AnsiContext *s = avctx->priv_data;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
420 if (s->frame.data[0])
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
421 avctx->release_buffer(avctx, &s->frame);
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
422 return 0;
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
423 }
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
424
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
425 AVCodec ansi_decoder = {
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
426 .name = "ansi",
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
427 .type = CODEC_TYPE_VIDEO,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
428 .id = CODEC_ID_ANSI,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
429 .priv_data_size = sizeof(AnsiContext),
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
430 .init = decode_init,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
431 .close = decode_close,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
432 .decode = decode_frame,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
433 .capabilities = CODEC_CAP_DR1,
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
434 .long_name = NULL_IF_CONFIG_SMALL("ASCII/ANSI art"),
fb2f04f70afe ASCII/ANSI art decoder
pross
parents:
diff changeset
435 };