Libav 0.7.1
|
00001 /* 00002 * 8088flex TMV video decoder 00003 * Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu> 00004 * 00005 * This file is part of Libav. 00006 * 00007 * Libav is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * Libav is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with Libav; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 = AV_PICTURE_TYPE_I; 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 };