3 * Copyright (c) 2003 Michael Niedermayer
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 /* Disable the encoder. */
34 #undef CONFIG_VCR1_ENCODER
35 #define CONFIG_VCR1_ENCODER 0
37 typedef struct VCR1Context{
38 AVCodecContext *avctx;
44 static int decode_frame(AVCodecContext *avctx,
45 void *data, int *data_size,
48 const uint8_t *buf = avpkt->data;
49 int buf_size = avpkt->size;
50 VCR1Context * const a = avctx->priv_data;
51 AVFrame *picture = data;
52 AVFrame * const p = &a->picture;
53 const uint8_t *bytestream= buf;
57 avctx->release_buffer(avctx, p);
59 if(buf_size < 16 + avctx->height + avctx->width*avctx->height*5/8){
60 av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
61 return AVERROR(EINVAL);
65 if(avctx->get_buffer(avctx, p) < 0){
66 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
69 p->pict_type= AV_PICTURE_TYPE_I;
73 a->delta[i]= *(bytestream++);
77 for(y=0; y<avctx->height; y++){
79 uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
82 uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
83 uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
86 a->offset[i]= *(bytestream++);
88 offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
89 for(x=0; x<avctx->width; x+=4){
90 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
91 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
92 luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
93 luma[3]=( offset += a->delta[ bytestream[0]>>4 ]);
96 *(cb++) = bytestream[3];
97 *(cr++) = bytestream[1];
102 offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
104 for(x=0; x<avctx->width; x+=8){
105 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
106 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
107 luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
108 luma[3]=( offset += a->delta[ bytestream[3]>>4 ]);
109 luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
110 luma[5]=( offset += a->delta[ bytestream[0]>>4 ]);
111 luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
112 luma[7]=( offset += a->delta[ bytestream[1]>>4 ]);
119 *picture = a->picture;
120 *data_size = sizeof(AVPicture);
125 #if CONFIG_VCR1_ENCODER
126 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
127 VCR1Context * const a = avctx->priv_data;
128 AVFrame *pict = data;
129 AVFrame * const p = &a->picture;
133 p->pict_type= AV_PICTURE_TYPE_I;
136 avpriv_align_put_bits(&a->pb);
137 while(get_bit_count(&a->pb)&31)
138 put_bits(&a->pb, 8, 0);
140 size= get_bit_count(&a->pb)/32;
146 static av_cold void common_init(AVCodecContext *avctx){
147 VCR1Context * const a = avctx->priv_data;
149 avctx->coded_frame = &a->picture;
150 avcodec_get_frame_defaults(&a->picture);
154 static av_cold int decode_init(AVCodecContext *avctx){
158 avctx->pix_fmt= PIX_FMT_YUV410P;
163 static av_cold int decode_end(AVCodecContext *avctx){
164 VCR1Context *s = avctx->priv_data;
166 if (s->picture.data[0])
167 avctx->release_buffer(avctx, &s->picture);
172 #if CONFIG_VCR1_ENCODER
173 static av_cold int encode_init(AVCodecContext *avctx){
181 AVCodec ff_vcr1_decoder = {
183 .type = AVMEDIA_TYPE_VIDEO,
185 .priv_data_size = sizeof(VCR1Context),
188 .decode = decode_frame,
189 .capabilities = CODEC_CAP_DR1,
190 .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
193 #if CONFIG_VCR1_ENCODER
194 AVCodec ff_vcr1_encoder = {
196 .type = AVMEDIA_TYPE_VIDEO,
198 .priv_data_size = sizeof(VCR1Context),
200 .encode = encode_frame,
201 .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),