00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00029 #include "avcodec.h"
00030
00031 #include "cga_data.h"
00032
00033 typedef struct TMVContext {
00034 AVFrame pic;
00035 } TMVContext;
00036
00037 static int tmv_decode_frame(AVCodecContext *avctx, void *data,
00038 int *data_size, AVPacket *avpkt)
00039 {
00040 TMVContext *tmv = avctx->priv_data;
00041 const uint8_t *src = avpkt->data;
00042 uint8_t *dst;
00043 unsigned char_cols = avctx->width >> 3;
00044 unsigned char_rows = avctx->height >> 3;
00045 unsigned x, y, fg, bg, c;
00046
00047 if (tmv->pic.data[0])
00048 avctx->release_buffer(avctx, &tmv->pic);
00049
00050 if (avctx->get_buffer(avctx, &tmv->pic) < 0) {
00051 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00052 return -1;
00053 }
00054
00055 if (avpkt->size < 2*char_rows*char_cols) {
00056 av_log(avctx, AV_LOG_ERROR,
00057 "Input buffer too small, truncated sample?\n");
00058 *data_size = 0;
00059 return -1;
00060 }
00061
00062 tmv->pic.pict_type = FF_I_TYPE;
00063 tmv->pic.key_frame = 1;
00064 dst = tmv->pic.data[0];
00065
00066 tmv->pic.palette_has_changed = 1;
00067 memcpy(tmv->pic.data[1], ff_cga_palette, 16 * 4);
00068
00069 for (y = 0; y < char_rows; y++) {
00070 for (x = 0; x < char_cols; x++) {
00071 c = *src++;
00072 bg = *src >> 4;
00073 fg = *src++ & 0xF;
00074 ff_draw_pc_font(dst + x * 8, tmv->pic.linesize[0],
00075 ff_cga_font, 8, c, fg, bg);
00076 }
00077 dst += tmv->pic.linesize[0] * 8;
00078 }
00079
00080 *data_size = sizeof(AVFrame);
00081 *(AVFrame *)data = tmv->pic;
00082 return avpkt->size;
00083 }
00084
00085 static av_cold int tmv_decode_close(AVCodecContext *avctx)
00086 {
00087 TMVContext *tmv = avctx->priv_data;
00088
00089 if (tmv->pic.data[0])
00090 avctx->release_buffer(avctx, &tmv->pic);
00091
00092 return 0;
00093 }
00094
00095 AVCodec ff_tmv_decoder = {
00096 .name = "tmv",
00097 .type = AVMEDIA_TYPE_VIDEO,
00098 .id = CODEC_ID_TMV,
00099 .priv_data_size = sizeof(TMVContext),
00100 .close = tmv_decode_close,
00101 .decode = tmv_decode_frame,
00102 .capabilities = CODEC_CAP_DR1,
00103 .long_name = NULL_IF_CONFIG_SMALL("8088flex TMV"),
00104 };