• 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                         const uint8_t *buf, int buf_size)
00047 {
00048     VCR1Context * const a = avctx->priv_data;
00049     AVFrame *picture = data;
00050     AVFrame * const p= (AVFrame*)&a->picture;
00051     const uint8_t *bytestream= buf;
00052     int i, x, y;
00053 
00054     if(p->data[0])
00055         avctx->release_buffer(avctx, p);
00056 
00057     p->reference= 0;
00058     if(avctx->get_buffer(avctx, p) < 0){
00059         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00060         return -1;
00061     }
00062     p->pict_type= FF_I_TYPE;
00063     p->key_frame= 1;
00064 
00065     for(i=0; i<16; i++){
00066         a->delta[i]= *(bytestream++);
00067         bytestream++;
00068     }
00069 
00070     for(y=0; y<avctx->height; y++){
00071         int offset;
00072         uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
00073 
00074         if((y&3) == 0){
00075             uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
00076             uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
00077 
00078             for(i=0; i<4; i++)
00079                 a->offset[i]= *(bytestream++);
00080 
00081             offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
00082             for(x=0; x<avctx->width; x+=4){
00083                 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
00084                 luma[1]=( offset += a->delta[ bytestream[2]>>4  ]);
00085                 luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
00086                 luma[3]=( offset += a->delta[ bytestream[0]>>4  ]);
00087                 luma += 4;
00088 
00089                 *(cb++) = bytestream[3];
00090                 *(cr++) = bytestream[1];
00091 
00092                 bytestream+= 4;
00093             }
00094         }else{
00095             offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
00096 
00097             for(x=0; x<avctx->width; x+=8){
00098                 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
00099                 luma[1]=( offset += a->delta[ bytestream[2]>>4  ]);
00100                 luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
00101                 luma[3]=( offset += a->delta[ bytestream[3]>>4  ]);
00102                 luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
00103                 luma[5]=( offset += a->delta[ bytestream[0]>>4  ]);
00104                 luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
00105                 luma[7]=( offset += a->delta[ bytestream[1]>>4  ]);
00106                 luma += 8;
00107                 bytestream+= 4;
00108             }
00109         }
00110     }
00111 
00112     *picture= *(AVFrame*)&a->picture;
00113     *data_size = sizeof(AVPicture);
00114 
00115     emms_c();
00116 
00117     return buf_size;
00118 }
00119 
00120 #if CONFIG_VCR1_ENCODER
00121 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
00122     VCR1Context * const a = avctx->priv_data;
00123     AVFrame *pict = data;
00124     AVFrame * const p= (AVFrame*)&a->picture;
00125     int size;
00126 
00127     *p = *pict;
00128     p->pict_type= FF_I_TYPE;
00129     p->key_frame= 1;
00130 
00131     emms_c();
00132 
00133     align_put_bits(&a->pb);
00134     while(get_bit_count(&a->pb)&31)
00135         put_bits(&a->pb, 8, 0);
00136 
00137     size= get_bit_count(&a->pb)/32;
00138 
00139     return size*4;
00140 }
00141 #endif
00142 
00143 static av_cold void common_init(AVCodecContext *avctx){
00144     VCR1Context * const a = avctx->priv_data;
00145 
00146     avctx->coded_frame= (AVFrame*)&a->picture;
00147     a->avctx= avctx;
00148 }
00149 
00150 static av_cold int decode_init(AVCodecContext *avctx){
00151 
00152     common_init(avctx);
00153 
00154     avctx->pix_fmt= PIX_FMT_YUV410P;
00155 
00156     return 0;
00157 }
00158 
00159 #if CONFIG_VCR1_ENCODER
00160 static av_cold int encode_init(AVCodecContext *avctx){
00161 
00162     common_init(avctx);
00163 
00164     return 0;
00165 }
00166 #endif
00167 
00168 AVCodec vcr1_decoder = {
00169     "vcr1",
00170     CODEC_TYPE_VIDEO,
00171     CODEC_ID_VCR1,
00172     sizeof(VCR1Context),
00173     decode_init,
00174     NULL,
00175     NULL,
00176     decode_frame,
00177     CODEC_CAP_DR1,
00178     .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
00179 };
00180 
00181 #if CONFIG_VCR1_ENCODER
00182 AVCodec vcr1_encoder = {
00183     "vcr1",
00184     CODEC_TYPE_VIDEO,
00185     CODEC_ID_VCR1,
00186     sizeof(VCR1Context),
00187     encode_init,
00188     encode_frame,
00189     //encode_end,
00190     .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
00191 };
00192 #endif

Generated on Sat Feb 16 2013 09:23:14 for ffmpeg by  doxygen 1.7.1