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 emms_c();
00118
00119 return buf_size;
00120 }
00121
00122 #if CONFIG_VCR1_ENCODER
00123 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
00124 VCR1Context * const a = avctx->priv_data;
00125 AVFrame *pict = data;
00126 AVFrame * const p= (AVFrame*)&a->picture;
00127 int size;
00128
00129 *p = *pict;
00130 p->pict_type= AV_PICTURE_TYPE_I;
00131 p->key_frame= 1;
00132
00133 emms_c();
00134
00135 align_put_bits(&a->pb);
00136 while(get_bit_count(&a->pb)&31)
00137 put_bits(&a->pb, 8, 0);
00138
00139 size= get_bit_count(&a->pb)/32;
00140
00141 return size*4;
00142 }
00143 #endif
00144
00145 static av_cold void common_init(AVCodecContext *avctx){
00146 VCR1Context * const a = avctx->priv_data;
00147
00148 avctx->coded_frame= (AVFrame*)&a->picture;
00149 avcodec_get_frame_defaults(&a->picture);
00150 a->avctx= avctx;
00151 }
00152
00153 static av_cold int decode_init(AVCodecContext *avctx){
00154
00155 common_init(avctx);
00156
00157 avctx->pix_fmt= PIX_FMT_YUV410P;
00158
00159 return 0;
00160 }
00161
00162 static av_cold int decode_end(AVCodecContext *avctx){
00163 VCR1Context *s = avctx->priv_data;
00164
00165 if (s->picture.data[0])
00166 avctx->release_buffer(avctx, &s->picture);
00167
00168 return 0;
00169 }
00170
00171 #if CONFIG_VCR1_ENCODER
00172 static av_cold int encode_init(AVCodecContext *avctx){
00173
00174 common_init(avctx);
00175
00176 return 0;
00177 }
00178 #endif
00179
00180 AVCodec ff_vcr1_decoder = {
00181 "vcr1",
00182 AVMEDIA_TYPE_VIDEO,
00183 CODEC_ID_VCR1,
00184 sizeof(VCR1Context),
00185 decode_init,
00186 NULL,
00187 decode_end,
00188 decode_frame,
00189 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 "vcr1",
00196 AVMEDIA_TYPE_VIDEO,
00197 CODEC_ID_VCR1,
00198 sizeof(VCR1Context),
00199 encode_init,
00200 encode_frame,
00201
00202 .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
00203 };
00204 #endif