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 FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* 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 FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2011-07-14 01:46:19 +00:00
|
|
|
* 8088flex TMV video decoder
|
2009-05-06 21:57:20 +00:00
|
|
|
* @author Daniel Verkamp
|
2011-07-14 22:45:23 +00:00
|
|
|
* @see http://www.oldskool.org/pc/8088_Corruption
|
2009-05-06 21:57:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avcodec.h"
|
|
|
|
|
|
|
|
#include "cga_data.h"
|
|
|
|
|
|
|
|
typedef struct TMVContext {
|
|
|
|
AVFrame pic;
|
|
|
|
} TMVContext;
|
|
|
|
|
2011-05-02 00:15:15 +00:00
|
|
|
static av_cold int tmv_decode_init(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
TMVContext *tmv = avctx->priv_data;
|
|
|
|
|
|
|
|
avcodec_get_frame_defaults(&tmv->pic);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-06 21:57:20 +00:00
|
|
|
static int tmv_decode_frame(AVCodecContext *avctx, void *data,
|
|
|
|
int *data_size, AVPacket *avpkt)
|
|
|
|
{
|
|
|
|
TMVContext *tmv = avctx->priv_data;
|
|
|
|
const uint8_t *src = avpkt->data;
|
2010-07-18 07:46:29 +00:00
|
|
|
uint8_t *dst;
|
2009-05-06 21:57:20 +00:00
|
|
|
unsigned char_cols = avctx->width >> 3;
|
|
|
|
unsigned char_rows = avctx->height >> 3;
|
2010-07-18 07:46:29 +00:00
|
|
|
unsigned x, y, fg, bg, c;
|
2009-05-06 21:57:20 +00:00
|
|
|
|
|
|
|
if (tmv->pic.data[0])
|
|
|
|
avctx->release_buffer(avctx, &tmv->pic);
|
|
|
|
|
|
|
|
if (avctx->get_buffer(avctx, &tmv->pic) < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-17 09:48:12 +00:00
|
|
|
if (avpkt->size < 2*char_rows*char_cols) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Input buffer too small, truncated sample?\n");
|
|
|
|
*data_size = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-04-27 23:40:44 +00:00
|
|
|
tmv->pic.pict_type = AV_PICTURE_TYPE_I;
|
2009-05-06 21:57:20 +00:00
|
|
|
tmv->pic.key_frame = 1;
|
|
|
|
dst = tmv->pic.data[0];
|
|
|
|
|
|
|
|
tmv->pic.palette_has_changed = 1;
|
|
|
|
memcpy(tmv->pic.data[1], ff_cga_palette, 16 * 4);
|
|
|
|
|
|
|
|
for (y = 0; y < char_rows; y++) {
|
|
|
|
for (x = 0; x < char_cols; x++) {
|
2010-07-18 07:46:29 +00:00
|
|
|
c = *src++;
|
2009-05-06 21:57:20 +00:00
|
|
|
bg = *src >> 4;
|
|
|
|
fg = *src++ & 0xF;
|
2010-07-18 07:46:29 +00:00
|
|
|
ff_draw_pc_font(dst + x * 8, tmv->pic.linesize[0],
|
|
|
|
ff_cga_font, 8, c, fg, bg);
|
2009-05-06 21:57:20 +00:00
|
|
|
}
|
|
|
|
dst += tmv->pic.linesize[0] * 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
*data_size = sizeof(AVFrame);
|
|
|
|
*(AVFrame *)data = tmv->pic;
|
|
|
|
return avpkt->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold int tmv_decode_close(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
TMVContext *tmv = avctx->priv_data;
|
|
|
|
|
|
|
|
if (tmv->pic.data[0])
|
|
|
|
avctx->release_buffer(avctx, &tmv->pic);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 21:40:11 +00:00
|
|
|
AVCodec ff_tmv_decoder = {
|
2009-05-06 21:57:20 +00:00
|
|
|
.name = "tmv",
|
2010-03-30 23:30:55 +00:00
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2009-05-06 21:57:20 +00:00
|
|
|
.id = CODEC_ID_TMV,
|
|
|
|
.priv_data_size = sizeof(TMVContext),
|
2011-05-02 00:15:15 +00:00
|
|
|
.init = tmv_decode_init,
|
2009-05-06 21:57:20 +00:00
|
|
|
.close = tmv_decode_close,
|
|
|
|
.decode = tmv_decode_frame,
|
2009-06-05 08:47:39 +00:00
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2009-05-06 21:57:20 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("8088flex TMV"),
|
|
|
|
};
|