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