1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2026-05-04 21:08:03 +02:00
Files
FFmpeg/libavcodec/tmv.c
T

98 lines
2.7 KiB
C
Raw Normal View History

2009-05-06 21:57:20 +00:00
/*
* 8088flex TMV video decoder
* Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
*
* This file is part of Libav.
2009-05-06 21:57:20 +00:00
*
* Libav is free software; you can redistribute it and/or
2009-05-06 21:57:20 +00:00
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Libav is distributed in the hope that it will be useful,
2009-05-06 21:57:20 +00:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Libav; if not, write to the Free Software
2009-05-06 21:57:20 +00:00
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* 8088flex TMV video decoder
2009-05-06 21:57:20 +00:00
* @author Daniel Verkamp
* @see http://www.oldskool.org/pc/8088_Corruption
2009-05-06 21:57:20 +00:00
*/
2012-08-06 16:49:32 +03:00
#include <string.h>
2009-05-06 21:57:20 +00:00
#include "avcodec.h"
#include "internal.h"
2012-08-06 16:49:32 +03:00
#include "libavutil/internal.h"
2009-05-06 21:57:20 +00:00
#include "cga_data.h"
static int tmv_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
2009-05-06 21:57:20 +00:00
{
2012-11-21 21:34:46 +01:00
AVFrame *frame = data;
2009-05-06 21:57:20 +00:00
const uint8_t *src = avpkt->data;
uint8_t *dst;
2009-05-06 21:57:20 +00:00
unsigned char_cols = avctx->width >> 3;
unsigned char_rows = avctx->height >> 3;
unsigned x, y, fg, bg, c;
2012-11-17 17:52:52 +01:00
int ret;
2009-05-06 21:57:20 +00:00
2012-11-21 21:34:46 +01:00
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
2009-05-06 21:57:20 +00:00
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
2012-11-17 17:52:52 +01:00
return ret;
2009-05-06 21:57:20 +00:00
}
if (avpkt->size < 2*char_rows*char_cols) {
av_log(avctx, AV_LOG_ERROR,
"Input buffer too small, truncated sample?\n");
*got_frame = 0;
2012-11-17 17:52:52 +01:00
return AVERROR_INVALIDDATA;
}
2012-11-21 21:34:46 +01:00
frame->pict_type = AV_PICTURE_TYPE_I;
frame->key_frame = 1;
dst = frame->data[0];
2009-05-06 21:57:20 +00:00
2012-11-21 21:34:46 +01:00
frame->palette_has_changed = 1;
memcpy(frame->data[1], ff_cga_palette, 16 * 4);
2009-05-06 21:57:20 +00:00
for (y = 0; y < char_rows; y++) {
for (x = 0; x < char_cols; x++) {
c = *src++;
2009-05-06 21:57:20 +00:00
bg = *src >> 4;
fg = *src++ & 0xF;
2012-11-21 21:34:46 +01:00
ff_draw_pc_font(dst + x * 8, frame->linesize[0],
ff_cga_font, 8, c, fg, bg);
2009-05-06 21:57:20 +00:00
}
2012-11-21 21:34:46 +01:00
dst += frame->linesize[0] * 8;
2009-05-06 21:57:20 +00:00
}
*got_frame = 1;
2012-11-21 21:34:46 +01:00
2009-05-06 21:57:20 +00:00
return avpkt->size;
}
2011-12-18 16:17:07 +02:00
static av_cold int tmv_decode_init(AVCodecContext *avctx)
{
avctx->pix_fmt = AV_PIX_FMT_PAL8;
2011-12-18 16:17:07 +02:00
return 0;
}
AVCodec ff_tmv_decoder = {
2009-05-06 21:57:20 +00:00
.name = "tmv",
.type = AVMEDIA_TYPE_VIDEO,
2012-08-05 11:11:04 +02:00
.id = AV_CODEC_ID_TMV,
2011-12-18 16:17:07 +02:00
.init = tmv_decode_init,
2009-05-06 21:57:20 +00:00
.decode = tmv_decode_frame,
.capabilities = CODEC_CAP_DR1,
2009-05-06 21:57:20 +00:00
.long_name = NULL_IF_CONFIG_SMALL("8088flex TMV"),
};