• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/avs.c

Go to the documentation of this file.
00001 /*
00002  * AVS video decoder.
00003  * Copyright (c) 2006  Aurelien Jacobs <aurel@gnuage.org>
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "avcodec.h"
00023 #include "get_bits.h"
00024 
00025 
00026 typedef struct {
00027     AVFrame picture;
00028 } AvsContext;
00029 
00030 typedef enum {
00031     AVS_VIDEO     = 0x01,
00032     AVS_AUDIO     = 0x02,
00033     AVS_PALETTE   = 0x03,
00034     AVS_GAME_DATA = 0x04,
00035 } AvsBlockType;
00036 
00037 typedef enum {
00038     AVS_I_FRAME     = 0x00,
00039     AVS_P_FRAME_3X3 = 0x01,
00040     AVS_P_FRAME_2X2 = 0x02,
00041     AVS_P_FRAME_2X3 = 0x03,
00042 } AvsVideoSubType;
00043 
00044 
00045 static int
00046 avs_decode_frame(AVCodecContext * avctx,
00047                  void *data, int *data_size, AVPacket *avpkt)
00048 {
00049     const uint8_t *buf = avpkt->data;
00050     int buf_size = avpkt->size;
00051     AvsContext *const avs = avctx->priv_data;
00052     AVFrame *picture = data;
00053     AVFrame *const p = (AVFrame *) & avs->picture;
00054     const uint8_t *table, *vect;
00055     uint8_t *out;
00056     int i, j, x, y, stride, vect_w = 3, vect_h = 3;
00057     AvsVideoSubType sub_type;
00058     AvsBlockType type;
00059     GetBitContext change_map;
00060 
00061     if (avctx->reget_buffer(avctx, p)) {
00062         av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
00063         return -1;
00064     }
00065     p->reference = 1;
00066     p->pict_type = FF_P_TYPE;
00067     p->key_frame = 0;
00068 
00069     out = avs->picture.data[0];
00070     stride = avs->picture.linesize[0];
00071 
00072     sub_type = buf[0];
00073     type = buf[1];
00074     buf += 4;
00075 
00076     if (type == AVS_PALETTE) {
00077         int first, last;
00078         uint32_t *pal = (uint32_t *) avs->picture.data[1];
00079 
00080         first = AV_RL16(buf);
00081         last = first + AV_RL16(buf + 2);
00082         buf += 4;
00083         for (i=first; i<last; i++, buf+=3)
00084             pal[i] = (buf[0] << 18) | (buf[1] << 10) | (buf[2] << 2);
00085 
00086         sub_type = buf[0];
00087         type = buf[1];
00088         buf += 4;
00089     }
00090 
00091     if (type != AVS_VIDEO)
00092         return -1;
00093 
00094     switch (sub_type) {
00095     case AVS_I_FRAME:
00096         p->pict_type = FF_I_TYPE;
00097         p->key_frame = 1;
00098     case AVS_P_FRAME_3X3:
00099         vect_w = 3;
00100         vect_h = 3;
00101         break;
00102 
00103     case AVS_P_FRAME_2X2:
00104         vect_w = 2;
00105         vect_h = 2;
00106         break;
00107 
00108     case AVS_P_FRAME_2X3:
00109         vect_w = 2;
00110         vect_h = 3;
00111         break;
00112 
00113     default:
00114       return -1;
00115     }
00116 
00117     table = buf + (256 * vect_w * vect_h);
00118     if (sub_type != AVS_I_FRAME) {
00119         int map_size = ((318 / vect_w + 7) / 8) * (198 / vect_h);
00120         init_get_bits(&change_map, table, map_size);
00121         table += map_size;
00122     }
00123 
00124     for (y=0; y<198; y+=vect_h) {
00125         for (x=0; x<318; x+=vect_w) {
00126             if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) {
00127                 vect = &buf[*table++ * (vect_w * vect_h)];
00128                 for (j=0; j<vect_w; j++) {
00129                     out[(y + 0) * stride + x + j] = vect[(0 * vect_w) + j];
00130                     out[(y + 1) * stride + x + j] = vect[(1 * vect_w) + j];
00131                     if (vect_h == 3)
00132                         out[(y + 2) * stride + x + j] =
00133                             vect[(2 * vect_w) + j];
00134                 }
00135             }
00136         }
00137         if (sub_type != AVS_I_FRAME)
00138             align_get_bits(&change_map);
00139     }
00140 
00141     *picture = *(AVFrame *) & avs->picture;
00142     *data_size = sizeof(AVPicture);
00143 
00144     return buf_size;
00145 }
00146 
00147 static av_cold int avs_decode_init(AVCodecContext * avctx)
00148 {
00149     avctx->pix_fmt = PIX_FMT_PAL8;
00150     return 0;
00151 }
00152 
00153 AVCodec avs_decoder = {
00154     "avs",
00155     AVMEDIA_TYPE_VIDEO,
00156     CODEC_ID_AVS,
00157     sizeof(AvsContext),
00158     avs_decode_init,
00159     NULL,
00160     NULL,
00161     avs_decode_frame,
00162     CODEC_CAP_DR1,
00163     .long_name = NULL_IF_CONFIG_SMALL("AVS (Audio Video Standard) video"),
00164 };

Generated on Fri Sep 16 2011 17:17:34 for FFmpeg by  doxygen 1.7.1