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, *dst_char;
00043 unsigned char_cols = avctx->width >> 3;
00044 unsigned char_rows = avctx->height >> 3;
00045 unsigned x, y, mask, char_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++ * 8;
00072 bg = *src >> 4;
00073 fg = *src++ & 0xF;
00074
00075 dst_char = dst + x * 8;
00076 for (char_y = 0; char_y < 8; char_y++) {
00077 for (mask = 0x80; mask; mask >>= 1) {
00078 *dst_char++ = ff_cga_font[c + char_y] & mask ? fg : bg;
00079 }
00080 dst_char += tmv->pic.linesize[0] - 8;
00081 }
00082 }
00083 dst += tmv->pic.linesize[0] * 8;
00084 }
00085
00086 *data_size = sizeof(AVFrame);
00087 *(AVFrame *)data = tmv->pic;
00088 return avpkt->size;
00089 }
00090
00091 static av_cold int tmv_decode_close(AVCodecContext *avctx)
00092 {
00093 TMVContext *tmv = avctx->priv_data;
00094
00095 if (tmv->pic.data[0])
00096 avctx->release_buffer(avctx, &tmv->pic);
00097
00098 return 0;
00099 }
00100
00101 AVCodec tmv_decoder = {
00102 .name = "tmv",
00103 .type = AVMEDIA_TYPE_VIDEO,
00104 .id = CODEC_ID_TMV,
00105 .priv_data_size = sizeof(TMVContext),
00106 .close = tmv_decode_close,
00107 .decode = tmv_decode_frame,
00108 .capabilities = CODEC_CAP_DR1,
00109 .long_name = NULL_IF_CONFIG_SMALL("8088flex TMV"),
00110 };