FFmpeg
tmv.c
Go to the documentation of this file.
1 /*
2  * 8088flex TMV video decoder
3  * Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * 8088flex TMV video decoder
25  * @author Daniel Verkamp
26  * @see http://www.oldskool.org/pc/8088_Corruption
27  */
28 
29 #include <string.h>
30 
31 #include "avcodec.h"
32 #include "codec_internal.h"
33 #include "decode.h"
34 #include "libavutil/internal.h"
36 
37 #include "cga_data.h"
38 
40  int *got_frame, AVPacket *avpkt)
41 {
42  const uint8_t *src = avpkt->data;
43  uint8_t *dst;
44  unsigned char_cols = avctx->width >> 3;
45  unsigned char_rows = avctx->height >> 3;
46  unsigned x, y, fg, bg, c;
47  int ret;
48 
49  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
50  return ret;
51 
52  if (avpkt->size < 2*char_rows*char_cols) {
53  av_log(avctx, AV_LOG_ERROR,
54  "Input buffer too small, truncated sample?\n");
55  *got_frame = 0;
56  return AVERROR_INVALIDDATA;
57  }
58 
61  dst = frame->data[0];
62 
63 #if FF_API_PALETTE_HAS_CHANGED
67 #endif
68  memcpy(frame->data[1], ff_cga_palette, 16 * 4);
69  memset(frame->data[1] + 16 * 4, 0, AVPALETTE_SIZE - 16 * 4);
70 
71  for (y = 0; y < char_rows; y++) {
72  for (x = 0; x < char_cols; x++) {
73  c = *src++;
74  bg = *src >> 4;
75  fg = *src++ & 0xF;
76  ff_draw_pc_font(dst + x * 8, frame->linesize[0],
77  avpriv_cga_font, 8, c, fg, bg);
78  }
79  dst += frame->linesize[0] * 8;
80  }
81 
82  *got_frame = 1;
83 
84  return avpkt->size;
85 }
86 
88 {
89  avctx->pix_fmt = AV_PIX_FMT_PAL8;
90  return 0;
91 }
92 
94  .p.name = "tmv",
95  CODEC_LONG_NAME("8088flex TMV"),
96  .p.type = AVMEDIA_TYPE_VIDEO,
97  .p.id = AV_CODEC_ID_TMV,
98  .init = tmv_decode_init,
100  .p.capabilities = AV_CODEC_CAP_DR1,
101 };
tmv_decode_init
static av_cold int tmv_decode_init(AVCodecContext *avctx)
Definition: tmv.c:87
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
AVFrame::palette_has_changed
attribute_deprecated int palette_has_changed
Tell user application that palette has changed from previous frame.
Definition: frame.h:546
ff_cga_palette
const uint32_t ff_cga_palette[16]
Definition: cga_data.c:30
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVPacket::data
uint8_t * data
Definition: packet.h:522
FFCodec
Definition: codec_internal.h:127
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:649
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
tmv_decode_frame
static int tmv_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: tmv.c:39
ff_draw_pc_font
void ff_draw_pc_font(uint8_t *dst, int linesize, const uint8_t *font, int font_height, int ch, int fg, int bg)
Draw CGA/EGA/VGA font to 8-bit pixel buffer.
Definition: cga_data.c:46
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:628
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
decode.h
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:442
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1618
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:523
codec_internal.h
cga_data.h
xga_font_data.h
internal.h
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVCodecContext::height
int height
Definition: avcodec.h:625
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:662
avcodec.h
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:84
ret
ret
Definition: filter_design.txt:187
AVCodecContext
main external API structure.
Definition: avcodec.h:445
ff_tmv_decoder
const FFCodec ff_tmv_decoder
Definition: tmv.c:93
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avpriv_cga_font
const uint8_t avpriv_cga_font[2048]
Definition: xga_font_data.c:29
AVPacket
This structure stores compressed data.
Definition: packet.h:499
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:625
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:385
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AV_CODEC_ID_TMV
@ AV_CODEC_ID_TMV
Definition: codec_id.h:178