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