Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "avcodec.h"
00028 #include "dsputil.h"
00029
00030
00031
00032
00033
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 p->reference= 0;
00060 if(avctx->get_buffer(avctx, p) < 0){
00061 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00062 return -1;
00063 }
00064 p->pict_type= AV_PICTURE_TYPE_I;
00065 p->key_frame= 1;
00066
00067 for(i=0; i<16; i++){
00068 a->delta[i]= *(bytestream++);
00069 bytestream++;
00070 }
00071
00072 for(y=0; y<avctx->height; y++){
00073 int offset;
00074 uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
00075
00076 if((y&3) == 0){
00077 uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
00078 uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
00079
00080 for(i=0; i<4; i++)
00081 a->offset[i]= *(bytestream++);
00082
00083 offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
00084 for(x=0; x<avctx->width; x+=4){
00085 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
00086 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
00087 luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
00088 luma[3]=( offset += a->delta[ bytestream[0]>>4 ]);
00089 luma += 4;
00090
00091 *(cb++) = bytestream[3];
00092 *(cr++) = bytestream[1];
00093
00094 bytestream+= 4;
00095 }
00096 }else{
00097 offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
00098
00099 for(x=0; x<avctx->width; x+=8){
00100 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
00101 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
00102 luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
00103 luma[3]=( offset += a->delta[ bytestream[3]>>4 ]);
00104 luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
00105 luma[5]=( offset += a->delta[ bytestream[0]>>4 ]);
00106 luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
00107 luma[7]=( offset += a->delta[ bytestream[1]>>4 ]);
00108 luma += 8;
00109 bytestream+= 4;
00110 }
00111 }
00112 }
00113
00114 *picture= *(AVFrame*)&a->picture;
00115 *data_size = sizeof(AVPicture);
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= AV_PICTURE_TYPE_I;
00129 p->key_frame= 1;
00130
00131 avpriv_align_put_bits(&a->pb);
00132 while(get_bit_count(&a->pb)&31)
00133 put_bits(&a->pb, 8, 0);
00134
00135 size= get_bit_count(&a->pb)/32;
00136
00137 return size*4;
00138 }
00139 #endif
00140
00141 static av_cold void common_init(AVCodecContext *avctx){
00142 VCR1Context * const a = avctx->priv_data;
00143
00144 avctx->coded_frame= (AVFrame*)&a->picture;
00145 a->avctx= avctx;
00146 }
00147
00148 static av_cold int decode_init(AVCodecContext *avctx){
00149
00150 common_init(avctx);
00151
00152 avctx->pix_fmt= PIX_FMT_YUV410P;
00153
00154 return 0;
00155 }
00156
00157 static av_cold int decode_end(AVCodecContext *avctx){
00158 VCR1Context *s = avctx->priv_data;
00159
00160 if (s->picture.data[0])
00161 avctx->release_buffer(avctx, &s->picture);
00162
00163 return 0;
00164 }
00165
00166 #if CONFIG_VCR1_ENCODER
00167 static av_cold int encode_init(AVCodecContext *avctx){
00168
00169 common_init(avctx);
00170
00171 return 0;
00172 }
00173 #endif
00174
00175 AVCodec ff_vcr1_decoder = {
00176 .name = "vcr1",
00177 .type = AVMEDIA_TYPE_VIDEO,
00178 .id = CODEC_ID_VCR1,
00179 .priv_data_size = sizeof(VCR1Context),
00180 .init = decode_init,
00181 .close = decode_end,
00182 .decode = decode_frame,
00183 .capabilities = CODEC_CAP_DR1,
00184 .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
00185 };
00186
00187 #if CONFIG_VCR1_ENCODER
00188 AVCodec ff_vcr1_encoder = {
00189 .name = "vcr1",
00190 .type = AVMEDIA_TYPE_VIDEO,
00191 .id = CODEC_ID_VCR1,
00192 .priv_data_size = sizeof(VCR1Context),
00193 .init = encode_init,
00194 .encode = encode_frame,
00195 .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
00196 };
00197 #endif