summaryrefslogtreecommitdiff
path: root/ffmpeg/libavcodec/ansi.c
diff options
context:
space:
mode:
Diffstat (limited to 'ffmpeg/libavcodec/ansi.c')
-rw-r--r--ffmpeg/libavcodec/ansi.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/ffmpeg/libavcodec/ansi.c b/ffmpeg/libavcodec/ansi.c
index 93915f8..143b0aa 100644
--- a/ffmpeg/libavcodec/ansi.c
+++ b/ffmpeg/libavcodec/ansi.c
@@ -91,7 +91,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
s->bg = DEFAULT_BG_COLOR;
if (!avctx->width || !avctx->height)
- avcodec_set_dimensions(avctx, 80<<3, 25<<4);
+ ff_set_dimensions(avctx, 80 << 3, 25 << 4);
return 0;
}
@@ -116,7 +116,7 @@ static void hscroll(AVCodecContext *avctx)
AnsiContext *s = avctx->priv_data;
int i;
- if (s->y < avctx->height - s->font_height) {
+ if (s->y <= avctx->height - 2*s->font_height) {
s->y += s->font_height;
return;
}
@@ -169,7 +169,7 @@ static void draw_char(AVCodecContext *avctx, int c)
ff_draw_pc_font(s->frame->data[0] + s->y * s->frame->linesize[0] + s->x,
s->frame->linesize[0], s->font, s->font_height, c, fg, bg);
s->x += FONT_WIDTH;
- if (s->x >= avctx->width) {
+ if (s->x > avctx->width - FONT_WIDTH) {
s->x = 0;
hscroll(avctx);
}
@@ -182,7 +182,10 @@ static void draw_char(AVCodecContext *avctx, int c)
static int execute_code(AVCodecContext * avctx, int c)
{
AnsiContext *s = avctx->priv_data;
- int ret, i, width, height;
+ int ret, i;
+ int width = avctx->width;
+ int height = avctx->height;
+
switch(c) {
case 'A': //Cursor Up
s->y = FFMAX(s->y - (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), 0);
@@ -205,8 +208,6 @@ static int execute_code(AVCodecContext * avctx, int c)
case 'l': //reset screen mode
if (s->nb_args < 2)
s->args[0] = DEFAULT_SCREEN_MODE;
- width = avctx->width;
- height = avctx->height;
switch(s->args[0]) {
case 0: case 1: case 4: case 5: case 13: case 19: //320x200 (25 rows)
s->font = avpriv_cga_font;
@@ -243,9 +244,13 @@ static int execute_code(AVCodecContext * avctx, int c)
default:
avpriv_request_sample(avctx, "Unsupported screen mode");
}
+ s->x = av_clip(s->x, 0, width - FONT_WIDTH);
+ s->y = av_clip(s->y, 0, height - s->font_height);
if (width != avctx->width || height != avctx->height) {
av_frame_unref(s->frame);
- avcodec_set_dimensions(avctx, width, height);
+ ret = ff_set_dimensions(avctx, width, height);
+ if (ret < 0)
+ return ret;
if ((ret = ff_get_buffer(avctx, s->frame,
AV_GET_BUFFER_FLAG_REF)) < 0)
return ret;
@@ -336,6 +341,8 @@ static int execute_code(AVCodecContext * avctx, int c)
avpriv_request_sample(avctx, "Unknown escape code");
break;
}
+ s->x = av_clip(s->x, 0, avctx->width - FONT_WIDTH);
+ s->y = av_clip(s->y, 0, avctx->height - s->font_height);
return 0;
}
@@ -462,6 +469,7 @@ static av_cold int decode_close(AVCodecContext *avctx)
AVCodec ff_ansi_decoder = {
.name = "ansi",
+ .long_name = NULL_IF_CONFIG_SMALL("ASCII/ANSI art"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_ANSI,
.priv_data_size = sizeof(AnsiContext),
@@ -469,5 +477,4 @@ AVCodec ff_ansi_decoder = {
.close = decode_close,
.decode = decode_frame,
.capabilities = CODEC_CAP_DR1,
- .long_name = NULL_IF_CONFIG_SMALL("ASCII/ANSI art"),
};