00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "avcodec.h"
00027 #include "mpegvideo.h"
00028
00029 typedef struct CLJRContext{
00030 AVCodecContext *avctx;
00031 AVFrame picture;
00032 int delta[16];
00033 int offset[4];
00034 GetBitContext gb;
00035 } CLJRContext;
00036
00037 static int decode_frame(AVCodecContext *avctx,
00038 void *data, int *data_size,
00039 uint8_t *buf, int buf_size)
00040 {
00041 CLJRContext * const a = avctx->priv_data;
00042 AVFrame *picture = data;
00043 AVFrame * const p= (AVFrame*)&a->picture;
00044 int x, y;
00045
00046 if(p->data[0])
00047 avctx->release_buffer(avctx, p);
00048
00049 p->reference= 0;
00050 if(avctx->get_buffer(avctx, p) < 0){
00051 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00052 return -1;
00053 }
00054 p->pict_type= I_TYPE;
00055 p->key_frame= 1;
00056
00057 init_get_bits(&a->gb, buf, buf_size);
00058
00059 for(y=0; y<avctx->height; y++){
00060 uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
00061 uint8_t *cb= &a->picture.data[1][ y*a->picture.linesize[1] ];
00062 uint8_t *cr= &a->picture.data[2][ y*a->picture.linesize[2] ];
00063 for(x=0; x<avctx->width; x+=4){
00064 luma[3] = get_bits(&a->gb, 5) << 3;
00065 luma[2] = get_bits(&a->gb, 5) << 3;
00066 luma[1] = get_bits(&a->gb, 5) << 3;
00067 luma[0] = get_bits(&a->gb, 5) << 3;
00068 luma+= 4;
00069 *(cb++) = get_bits(&a->gb, 6) << 2;
00070 *(cr++) = get_bits(&a->gb, 6) << 2;
00071 }
00072 }
00073
00074 *picture= *(AVFrame*)&a->picture;
00075 *data_size = sizeof(AVPicture);
00076
00077 emms_c();
00078
00079 return buf_size;
00080 }
00081
00082 #if 0
00083 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
00084 CLJRContext * const a = avctx->priv_data;
00085 AVFrame *pict = data;
00086 AVFrame * const p= (AVFrame*)&a->picture;
00087 int size;
00088 int mb_x, mb_y;
00089
00090 *p = *pict;
00091 p->pict_type= I_TYPE;
00092 p->key_frame= 1;
00093
00094 emms_c();
00095
00096 align_put_bits(&a->pb);
00097 while(get_bit_count(&a->pb)&31)
00098 put_bits(&a->pb, 8, 0);
00099
00100 size= get_bit_count(&a->pb)/32;
00101
00102 return size*4;
00103 }
00104 #endif
00105
00106 static void common_init(AVCodecContext *avctx){
00107 CLJRContext * const a = avctx->priv_data;
00108
00109 avctx->coded_frame= (AVFrame*)&a->picture;
00110 a->avctx= avctx;
00111 }
00112
00113 static int decode_init(AVCodecContext *avctx){
00114
00115 common_init(avctx);
00116
00117 avctx->pix_fmt= PIX_FMT_YUV411P;
00118
00119 return 0;
00120 }
00121
00122 #if 0
00123 static int encode_init(AVCodecContext *avctx){
00124
00125 common_init(avctx);
00126
00127 return 0;
00128 }
00129 #endif
00130
00131 AVCodec cljr_decoder = {
00132 "cljr",
00133 CODEC_TYPE_VIDEO,
00134 CODEC_ID_CLJR,
00135 sizeof(CLJRContext),
00136 decode_init,
00137 NULL,
00138 NULL,
00139 decode_frame,
00140 CODEC_CAP_DR1,
00141 };
00142 #if 0
00143 #ifdef CONFIG_ENCODERS
00144
00145 AVCodec cljr_encoder = {
00146 "cljr",
00147 CODEC_TYPE_VIDEO,
00148 CODEC_ID_cljr,
00149 sizeof(CLJRContext),
00150 encode_init,
00151 encode_frame,
00152
00153 };
00154
00155 #endif //CONFIG_ENCODERS
00156 #endif