3
* Copyright (c) 2003 Michael Niedermayer
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26
#include "mpegvideo.h"
31
typedef struct VCR1Context{
32
AVCodecContext *avctx;
38
static int decode_frame(AVCodecContext *avctx,
39
void *data, int *data_size,
40
uint8_t *buf, int buf_size)
42
VCR1Context * const a = avctx->priv_data;
43
AVFrame *picture = data;
44
AVFrame * const p= (AVFrame*)&a->picture;
45
uint8_t *bytestream= buf;
49
avctx->release_buffer(avctx, p);
52
if(avctx->get_buffer(avctx, p) < 0){
53
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
60
a->delta[i]= *(bytestream++);
64
for(y=0; y<avctx->height; y++){
66
uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
69
uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
70
uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
73
a->offset[i]= *(bytestream++);
75
offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
76
for(x=0; x<avctx->width; x+=4){
77
luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
78
luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
79
luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
80
luma[3]=( offset += a->delta[ bytestream[0]>>4 ]);
83
*(cb++) = bytestream[3];
84
*(cr++) = bytestream[1];
89
offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
91
for(x=0; x<avctx->width; x+=8){
92
luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
93
luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
94
luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
95
luma[3]=( offset += a->delta[ bytestream[3]>>4 ]);
96
luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
97
luma[5]=( offset += a->delta[ bytestream[0]>>4 ]);
98
luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
99
luma[7]=( offset += a->delta[ bytestream[1]>>4 ]);
106
*picture= *(AVFrame*)&a->picture;
107
*data_size = sizeof(AVPicture);
115
static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
116
VCR1Context * const a = avctx->priv_data;
117
AVFrame *pict = data;
118
AVFrame * const p= (AVFrame*)&a->picture;
123
p->pict_type= I_TYPE;
128
align_put_bits(&a->pb);
129
while(get_bit_count(&a->pb)&31)
130
put_bits(&a->pb, 8, 0);
132
size= get_bit_count(&a->pb)/32;
138
static void common_init(AVCodecContext *avctx){
139
VCR1Context * const a = avctx->priv_data;
141
avctx->coded_frame= (AVFrame*)&a->picture;
145
static int decode_init(AVCodecContext *avctx){
149
avctx->pix_fmt= PIX_FMT_YUV410P;
155
static int encode_init(AVCodecContext *avctx){
163
AVCodec vcr1_decoder = {
175
#ifdef CONFIG_ENCODERS
177
AVCodec vcr1_encoder = {
187
#endif //CONFIG_ENCODERS