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