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

libavcodec/vcr1.c

Go to the documentation of this file.
00001 /*
00002  * ATI VCR1 codec
00003  * Copyright (c) 2003 Michael Niedermayer
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 
00027 #include "avcodec.h"
00028 #include "dsputil.h"
00029 
00030 //#undef NDEBUG
00031 //#include <assert.h>
00032 
00033 /* Disable the encoder. */
00034 #undef CONFIG_VCR1_ENCODER
00035 #define CONFIG_VCR1_ENCODER 0
00036 
00037 typedef struct VCR1Context{
00038     AVCodecContext *avctx;
00039     AVFrame picture;
00040     int delta[16];
00041     int offset[4];
00042 } VCR1Context;
00043 
00044 static int decode_frame(AVCodecContext *avctx,
00045                         void *data, int *data_size,
00046                         AVPacket *avpkt)
00047 {
00048     const uint8_t *buf = avpkt->data;
00049     int buf_size = avpkt->size;
00050     VCR1Context * const a = avctx->priv_data;
00051     AVFrame *picture = data;
00052     AVFrame * const p= (AVFrame*)&a->picture;
00053     const uint8_t *bytestream= buf;
00054     int i, x, y;
00055 
00056     if(p->data[0])
00057         avctx->release_buffer(avctx, p);
00058 
00059     if(buf_size < 16 + avctx->height + avctx->width*avctx->height*5/8){
00060         av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
00061         return AVERROR(EINVAL);
00062     }
00063 
00064     p->reference= 0;
00065     if(avctx->get_buffer(avctx, p) < 0){
00066         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00067         return -1;
00068     }
00069     p->pict_type= AV_PICTURE_TYPE_I;
00070     p->key_frame= 1;
00071 
00072     for(i=0; i<16; i++){
00073         a->delta[i]= *(bytestream++);
00074         bytestream++;
00075     }
00076 
00077     for(y=0; y<avctx->height; y++){
00078         int offset;
00079         uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
00080 
00081         if((y&3) == 0){
00082             uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
00083             uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
00084 
00085             for(i=0; i<4; i++)
00086                 a->offset[i]= *(bytestream++);
00087 
00088             offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
00089             for(x=0; x<avctx->width; x+=4){
00090                 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
00091                 luma[1]=( offset += a->delta[ bytestream[2]>>4  ]);
00092                 luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
00093                 luma[3]=( offset += a->delta[ bytestream[0]>>4  ]);
00094                 luma += 4;
00095 
00096                 *(cb++) = bytestream[3];
00097                 *(cr++) = bytestream[1];
00098 
00099                 bytestream+= 4;
00100             }
00101         }else{
00102             offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
00103 
00104             for(x=0; x<avctx->width; x+=8){
00105                 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
00106                 luma[1]=( offset += a->delta[ bytestream[2]>>4  ]);
00107                 luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
00108                 luma[3]=( offset += a->delta[ bytestream[3]>>4  ]);
00109                 luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
00110                 luma[5]=( offset += a->delta[ bytestream[0]>>4  ]);
00111                 luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
00112                 luma[7]=( offset += a->delta[ bytestream[1]>>4  ]);
00113                 luma += 8;
00114                 bytestream+= 4;
00115             }
00116         }
00117     }
00118 
00119     *picture= *(AVFrame*)&a->picture;
00120     *data_size = sizeof(AVPicture);
00121 
00122     return buf_size;
00123 }
00124 
00125 #if CONFIG_VCR1_ENCODER
00126 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
00127     VCR1Context * const a = avctx->priv_data;
00128     AVFrame *pict = data;
00129     AVFrame * const p= (AVFrame*)&a->picture;
00130     int size;
00131 
00132     *p = *pict;
00133     p->pict_type= AV_PICTURE_TYPE_I;
00134     p->key_frame= 1;
00135 
00136     avpriv_align_put_bits(&a->pb);
00137     while(get_bit_count(&a->pb)&31)
00138         put_bits(&a->pb, 8, 0);
00139 
00140     size= get_bit_count(&a->pb)/32;
00141 
00142     return size*4;
00143 }
00144 #endif
00145 
00146 static av_cold void common_init(AVCodecContext *avctx){
00147     VCR1Context * const a = avctx->priv_data;
00148 
00149     avctx->coded_frame= (AVFrame*)&a->picture;
00150     avcodec_get_frame_defaults(&a->picture);
00151     a->avctx= avctx;
00152 }
00153 
00154 static av_cold int decode_init(AVCodecContext *avctx){
00155 
00156     common_init(avctx);
00157 
00158     avctx->pix_fmt= PIX_FMT_YUV410P;
00159 
00160     return 0;
00161 }
00162 
00163 static av_cold int decode_end(AVCodecContext *avctx){
00164     VCR1Context *s = avctx->priv_data;
00165 
00166     if (s->picture.data[0])
00167         avctx->release_buffer(avctx, &s->picture);
00168 
00169     return 0;
00170 }
00171 
00172 #if CONFIG_VCR1_ENCODER
00173 static av_cold int encode_init(AVCodecContext *avctx){
00174 
00175     common_init(avctx);
00176 
00177     return 0;
00178 }
00179 #endif
00180 
00181 AVCodec ff_vcr1_decoder = {
00182     .name           = "vcr1",
00183     .type           = AVMEDIA_TYPE_VIDEO,
00184     .id             = CODEC_ID_VCR1,
00185     .priv_data_size = sizeof(VCR1Context),
00186     .init           = decode_init,
00187     .close          = decode_end,
00188     .decode         = decode_frame,
00189     .capabilities   = CODEC_CAP_DR1,
00190     .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
00191 };
00192 
00193 #if CONFIG_VCR1_ENCODER
00194 AVCodec ff_vcr1_encoder = {
00195     .name           = "vcr1",
00196     .type           = AVMEDIA_TYPE_VIDEO,
00197     .id             = CODEC_ID_VCR1,
00198     .priv_data_size = sizeof(VCR1Context),
00199     .init           = encode_init,
00200     .encode         = encode_frame,
00201     .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
00202 };
00203 #endif
Generated on Fri Feb 1 2013 14:34:45 for FFmpeg by doxygen 1.7.1