3aff069b |
/*
* Cirrus Logic AccuPak (CLJR) codec
* Copyright (c) 2003 Alex Beregszaszi
* |
b78e7197 |
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or |
3aff069b |
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either |
b78e7197 |
* version 2.1 of the License, or (at your option) any later version. |
3aff069b |
* |
b78e7197 |
* FFmpeg is distributed in the hope that it will be useful, |
3aff069b |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public |
b78e7197 |
* License along with FFmpeg; if not, write to the Free Software |
5509bffa |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
3aff069b |
*/ |
115329f1 |
|
3aff069b |
/** |
ba87f080 |
* @file |
3aff069b |
* Cirrus Logic AccuPak codec.
*/ |
115329f1 |
|
3aff069b |
#include "avcodec.h" |
fbd4293d |
#include "dsputil.h" |
9106a698 |
#include "get_bits.h" |
3aff069b |
|
c7ac9449 |
/* Disable the encoder. */
#undef CONFIG_CLJR_ENCODER |
b250f9c6 |
#define CONFIG_CLJR_ENCODER 0 |
c7ac9449 |
|
3aff069b |
typedef struct CLJRContext{
AVCodecContext *avctx;
AVFrame picture;
int delta[16];
int offset[4];
GetBitContext gb;
} CLJRContext;
|
115329f1 |
static int decode_frame(AVCodecContext *avctx, |
3aff069b |
void *data, int *data_size, |
7a00bbad |
AVPacket *avpkt) |
3aff069b |
{ |
7a00bbad |
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size; |
3aff069b |
CLJRContext * const a = avctx->priv_data;
AVFrame *picture = data;
AVFrame * const p= (AVFrame*)&a->picture; |
d9c533a5 |
int x, y; |
3aff069b |
if(p->data[0])
avctx->release_buffer(avctx, p);
|
f2953365 |
if(buf_size/avctx->height < avctx->width) {
av_log(avctx, AV_LOG_ERROR, "Resolution larger than buffer size. Invalid header?\n");
return -1;
}
|
3aff069b |
p->reference= 0;
if(avctx->get_buffer(avctx, p) < 0){ |
9b879566 |
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
3aff069b |
return -1;
} |
ce5e49b0 |
p->pict_type= AV_PICTURE_TYPE_I; |
3aff069b |
p->key_frame= 1;
|
3a0649dd |
init_get_bits(&a->gb, buf, buf_size * 8); |
3aff069b |
for(y=0; y<avctx->height; y++){
uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ]; |
c39c1dca |
uint8_t *cb= &a->picture.data[1][ y*a->picture.linesize[1] ];
uint8_t *cr= &a->picture.data[2][ y*a->picture.linesize[2] ]; |
3aff069b |
for(x=0; x<avctx->width; x+=4){ |
bb270c08 |
luma[3] = get_bits(&a->gb, 5) << 3;
luma[2] = get_bits(&a->gb, 5) << 3;
luma[1] = get_bits(&a->gb, 5) << 3;
luma[0] = get_bits(&a->gb, 5) << 3;
luma+= 4;
*(cb++) = get_bits(&a->gb, 6) << 2;
*(cr++) = get_bits(&a->gb, 6) << 2; |
3aff069b |
}
}
*picture= *(AVFrame*)&a->picture;
*data_size = sizeof(AVPicture);
emms_c(); |
115329f1 |
|
3aff069b |
return buf_size;
}
|
b250f9c6 |
#if CONFIG_CLJR_ENCODER |
3aff069b |
static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
CLJRContext * const a = avctx->priv_data;
AVFrame *pict = data;
AVFrame * const p= (AVFrame*)&a->picture;
int size;
*p = *pict; |
ce5e49b0 |
p->pict_type= AV_PICTURE_TYPE_I; |
3aff069b |
p->key_frame= 1;
emms_c(); |
115329f1 |
|
3aff069b |
align_put_bits(&a->pb);
while(get_bit_count(&a->pb)&31)
put_bits(&a->pb, 8, 0); |
115329f1 |
|
3aff069b |
size= get_bit_count(&a->pb)/32; |
115329f1 |
|
3aff069b |
return size*4;
}
#endif
|
98a6fff9 |
static av_cold void common_init(AVCodecContext *avctx){ |
3aff069b |
CLJRContext * const a = avctx->priv_data;
|
01042d41 |
avcodec_get_frame_defaults(&a->picture); |
3aff069b |
avctx->coded_frame= (AVFrame*)&a->picture;
a->avctx= avctx;
}
|
98a6fff9 |
static av_cold int decode_init(AVCodecContext *avctx){ |
d9c533a5 |
|
3aff069b |
common_init(avctx); |
115329f1 |
|
c39c1dca |
avctx->pix_fmt= PIX_FMT_YUV411P; |
3aff069b |
return 0;
}
|
b250f9c6 |
#if CONFIG_CLJR_ENCODER |
98a6fff9 |
static av_cold int encode_init(AVCodecContext *avctx){ |
d9c533a5 |
|
3aff069b |
common_init(avctx); |
115329f1 |
|
3aff069b |
return 0;
} |
88730be6 |
#endif |
3aff069b |
|
e7e2df27 |
AVCodec ff_cljr_decoder = { |
3aff069b |
"cljr", |
72415b2a |
AVMEDIA_TYPE_VIDEO, |
3aff069b |
CODEC_ID_CLJR,
sizeof(CLJRContext),
decode_init,
NULL, |
eea8c08f |
NULL, |
3aff069b |
decode_frame,
CODEC_CAP_DR1, |
fe4bf374 |
.long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), |
3aff069b |
}; |
c7ac9449 |
|
b250f9c6 |
#if CONFIG_CLJR_ENCODER |
e7e2df27 |
AVCodec ff_cljr_encoder = { |
3aff069b |
"cljr", |
72415b2a |
AVMEDIA_TYPE_VIDEO, |
01c53437 |
CODEC_ID_CLJR, |
3aff069b |
sizeof(CLJRContext),
encode_init,
encode_frame,
//encode_end, |
fe4bf374 |
.long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), |
3aff069b |
}; |
f544a5fc |
#endif |