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