2009-05-07 00:57:20 +03: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 17:45:34 +03:00
|
|
|
* @file
|
2011-07-14 04:46:19 +03:00
|
|
|
* 8088flex TMV video decoder
|
2009-05-07 00:57:20 +03:00
|
|
|
* @author Daniel Verkamp
|
2011-07-15 01:45:23 +03:00
|
|
|
* @see http://www.oldskool.org/pc/8088_Corruption
|
2009-05-07 00:57:20 +03:00
|
|
|
*/
|
|
|
|
|
2012-08-06 16:49:32 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
2009-05-07 00:57:20 +03:00
|
|
|
#include "avcodec.h"
|
2022-03-16 19:18:28 +02:00
|
|
|
#include "codec_internal.h"
|
2022-08-24 21:28:16 +02:00
|
|
|
#include "decode.h"
|
2012-08-06 16:49:32 +03:00
|
|
|
#include "libavutil/internal.h"
|
2012-09-22 10:56:33 +03:00
|
|
|
#include "libavutil/xga_font_data.h"
|
2009-05-07 00:57:20 +03:00
|
|
|
|
|
|
|
#include "cga_data.h"
|
|
|
|
|
2022-03-30 21:33:24 +02:00
|
|
|
static int tmv_decode_frame(AVCodecContext *avctx, AVFrame *frame,
|
2012-11-13 21:35:22 +03:00
|
|
|
int *got_frame, AVPacket *avpkt)
|
2009-05-07 00:57:20 +03:00
|
|
|
{
|
|
|
|
const uint8_t *src = avpkt->data;
|
2010-07-18 10:46:29 +03:00
|
|
|
uint8_t *dst;
|
2009-05-07 00:57:20 +03:00
|
|
|
unsigned char_cols = avctx->width >> 3;
|
|
|
|
unsigned char_rows = avctx->height >> 3;
|
2010-07-18 10:46:29 +03:00
|
|
|
unsigned x, y, fg, bg, c;
|
2012-11-17 19:52:52 +03:00
|
|
|
int ret;
|
2009-05-07 00:57:20 +03:00
|
|
|
|
lavc: factorize ff_{thread_,re,}get_buffer error messages.
Coccinelle profile used:
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_get_buffer(ctx, f, flags)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str;
@@
-if ((r = ff_reget_buffer(ctx, f)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_reget_buffer(ctx, f)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0)
+ return r;
...along with some manual patches for the remaining ones.
2013-03-12 10:41:53 +03:00
|
|
|
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
2012-11-17 19:52:52 +03:00
|
|
|
return ret;
|
2009-05-07 00:57:20 +03:00
|
|
|
|
2009-05-17 12:48:12 +03:00
|
|
|
if (avpkt->size < 2*char_rows*char_cols) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Input buffer too small, truncated sample?\n");
|
2012-11-13 21:35:22 +03:00
|
|
|
*got_frame = 0;
|
2012-11-17 19:52:52 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2009-05-17 12:48:12 +03:00
|
|
|
}
|
|
|
|
|
2012-11-21 23:34:46 +03:00
|
|
|
dst = frame->data[0];
|
2009-05-07 00:57:20 +03:00
|
|
|
|
2023-05-18 03:39:57 +02:00
|
|
|
#if FF_API_PALETTE_HAS_CHANGED
|
|
|
|
FF_DISABLE_DEPRECATION_WARNINGS
|
2012-11-21 23:34:46 +03:00
|
|
|
frame->palette_has_changed = 1;
|
2023-05-18 03:39:57 +02:00
|
|
|
FF_ENABLE_DEPRECATION_WARNINGS
|
|
|
|
#endif
|
2012-11-21 23:34:46 +03:00
|
|
|
memcpy(frame->data[1], ff_cga_palette, 16 * 4);
|
2013-03-12 05:20:18 +03:00
|
|
|
memset(frame->data[1] + 16 * 4, 0, AVPALETTE_SIZE - 16 * 4);
|
2009-05-07 00:57:20 +03:00
|
|
|
|
|
|
|
for (y = 0; y < char_rows; y++) {
|
|
|
|
for (x = 0; x < char_cols; x++) {
|
2010-07-18 10:46:29 +03:00
|
|
|
c = *src++;
|
2009-05-07 00:57:20 +03:00
|
|
|
bg = *src >> 4;
|
|
|
|
fg = *src++ & 0xF;
|
2012-11-21 23:34:46 +03:00
|
|
|
ff_draw_pc_font(dst + x * 8, frame->linesize[0],
|
2012-09-22 10:56:33 +03:00
|
|
|
avpriv_cga_font, 8, c, fg, bg);
|
2009-05-07 00:57:20 +03:00
|
|
|
}
|
2012-11-21 23:34:46 +03:00
|
|
|
dst += frame->linesize[0] * 8;
|
2009-05-07 00:57:20 +03:00
|
|
|
}
|
|
|
|
|
2012-11-13 21:35:22 +03:00
|
|
|
*got_frame = 1;
|
2012-11-21 23:34:46 +03:00
|
|
|
|
2009-05-07 00:57:20 +03:00
|
|
|
return avpkt->size;
|
|
|
|
}
|
|
|
|
|
2011-12-18 17:17:07 +03:00
|
|
|
static av_cold int tmv_decode_init(AVCodecContext *avctx)
|
|
|
|
{
|
2012-10-06 13:10:34 +03:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_PAL8;
|
2009-05-07 00:57:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_tmv_decoder = {
|
|
|
|
.p.name = "tmv",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("8088flex TMV"),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.p.id = AV_CODEC_ID_TMV,
|
2011-05-02 03:15:15 +03:00
|
|
|
.init = tmv_decode_init,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(tmv_decode_frame),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_DR1,
|
2009-05-07 00:57:20 +03:00
|
|
|
};
|