Libav 0.7.1
|
00001 /* 00002 * Cirrus Logic AccuPak (CLJR) codec 00003 * Copyright (c) 2003 Alex Beregszaszi 00004 * 00005 * This file is part of Libav. 00006 * 00007 * Libav is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * Libav is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with Libav; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00027 #include "avcodec.h" 00028 #include "dsputil.h" 00029 #include "get_bits.h" 00030 00031 /* Disable the encoder. */ 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 avctx->coded_frame= (AVFrame*)&a->picture; 00122 a->avctx= avctx; 00123 } 00124 00125 static av_cold int decode_init(AVCodecContext *avctx){ 00126 00127 common_init(avctx); 00128 00129 avctx->pix_fmt= PIX_FMT_YUV411P; 00130 00131 return 0; 00132 } 00133 00134 #if CONFIG_CLJR_ENCODER 00135 static av_cold int encode_init(AVCodecContext *avctx){ 00136 00137 common_init(avctx); 00138 00139 return 0; 00140 } 00141 #endif 00142 00143 AVCodec ff_cljr_decoder = { 00144 "cljr", 00145 AVMEDIA_TYPE_VIDEO, 00146 CODEC_ID_CLJR, 00147 sizeof(CLJRContext), 00148 decode_init, 00149 NULL, 00150 NULL, 00151 decode_frame, 00152 CODEC_CAP_DR1, 00153 .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), 00154 }; 00155 00156 #if CONFIG_CLJR_ENCODER 00157 AVCodec ff_cljr_encoder = { 00158 "cljr", 00159 AVMEDIA_TYPE_VIDEO, 00160 CODEC_ID_CLJR, 00161 sizeof(CLJRContext), 00162 encode_init, 00163 encode_frame, 00164 //encode_end, 00165 .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), 00166 }; 00167 #endif