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