27
27
#include "avcodec.h"
28
28
#include "dsputil.h"
33
/* Disable the encoder. */
34
#undef CONFIG_VCR1_ENCODER
35
#define CONFIG_VCR1_ENCODER 0
37
typedef struct VCR1Context{
38
AVCodecContext *avctx;
30
#include "libavutil/internal.h"
32
typedef struct VCR1Context {
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= (AVFrame*)&a->picture;
53
const uint8_t *bytestream= buf;
38
static av_cold int vcr1_common_init(AVCodecContext *avctx)
40
VCR1Context *const a = avctx->priv_data;
42
avctx->coded_frame = &a->picture;
47
static av_cold int vcr1_decode_init(AVCodecContext *avctx)
49
vcr1_common_init(avctx);
51
avctx->pix_fmt = AV_PIX_FMT_YUV410P;
53
if (avctx->width & 7) {
54
av_log(avctx, AV_LOG_ERROR, "Width %d is not divisble by 8.\n", avctx->width);
55
return AVERROR_INVALIDDATA;
61
static av_cold int vcr1_decode_end(AVCodecContext *avctx)
63
VCR1Context *s = avctx->priv_data;
65
if (s->picture.data[0])
66
avctx->release_buffer(avctx, &s->picture);
71
static int vcr1_decode_frame(AVCodecContext *avctx, void *data,
72
int *got_frame, AVPacket *avpkt)
74
const uint8_t *buf = avpkt->data;
75
int buf_size = avpkt->size;
76
VCR1Context *const a = avctx->priv_data;
77
AVFrame *picture = data;
78
AVFrame *const p = &a->picture;
79
const uint8_t *bytestream = buf;
57
83
avctx->release_buffer(avctx, p);
60
if(avctx->get_buffer(avctx, p) < 0){
86
if (ff_get_buffer(avctx, p) < 0) {
61
87
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
64
p->pict_type= AV_PICTURE_TYPE_I;
68
a->delta[i]= *(bytestream++);
90
p->pict_type = AV_PICTURE_TYPE_I;
96
for (i = 0; i < 16; i++) {
97
a->delta[i] = *bytestream++;
72
for(y=0; y<avctx->height; y++){
102
for (y = 0; y < avctx->height; y++) {
74
uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
77
uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
78
uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
81
a->offset[i]= *(bytestream++);
83
offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
84
for(x=0; x<avctx->width; x+=4){
85
luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
86
luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
87
luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
88
luma[3]=( offset += a->delta[ bytestream[0]>>4 ]);
91
*(cb++) = bytestream[3];
92
*(cr++) = bytestream[1];
104
uint8_t *luma = &a->picture.data[0][y * a->picture.linesize[0]];
107
uint8_t *cb = &a->picture.data[1][(y >> 2) * a->picture.linesize[1]];
108
uint8_t *cr = &a->picture.data[2][(y >> 2) * a->picture.linesize[2]];
110
if (buf_size < 4 + avctx->width)
113
for (i = 0; i < 4; i++)
114
a->offset[i] = *bytestream++;
117
offset = a->offset[0] - a->delta[bytestream[2] & 0xF];
118
for (x = 0; x < avctx->width; x += 4) {
119
luma[0] = offset += a->delta[bytestream[2] & 0xF];
120
luma[1] = offset += a->delta[bytestream[2] >> 4];
121
luma[2] = offset += a->delta[bytestream[0] & 0xF];
122
luma[3] = offset += a->delta[bytestream[0] >> 4];
125
*cb++ = bytestream[3];
126
*cr++ = bytestream[1];
97
offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
99
for(x=0; x<avctx->width; x+=8){
100
luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
101
luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
102
luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
103
luma[3]=( offset += a->delta[ bytestream[3]>>4 ]);
104
luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
105
luma[5]=( offset += a->delta[ bytestream[0]>>4 ]);
106
luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
107
luma[7]=( offset += a->delta[ bytestream[1]>>4 ]);
132
if (buf_size < avctx->width / 2)
135
offset = a->offset[y & 3] - a->delta[bytestream[2] & 0xF];
137
for (x = 0; x < avctx->width; x += 8) {
138
luma[0] = offset += a->delta[bytestream[2] & 0xF];
139
luma[1] = offset += a->delta[bytestream[2] >> 4];
140
luma[2] = offset += a->delta[bytestream[3] & 0xF];
141
luma[3] = offset += a->delta[bytestream[3] >> 4];
142
luma[4] = offset += a->delta[bytestream[0] & 0xF];
143
luma[5] = offset += a->delta[bytestream[0] >> 4];
144
luma[6] = offset += a->delta[bytestream[1] & 0xF];
145
luma[7] = offset += a->delta[bytestream[1] >> 4];
114
*picture= *(AVFrame*)&a->picture;
115
*data_size = sizeof(AVPicture);
153
*picture = a->picture;
158
av_log(avctx, AV_LOG_ERROR, "Input packet too small.\n");
159
return AVERROR_INVALIDDATA;
162
AVCodec ff_vcr1_decoder = {
164
.type = AVMEDIA_TYPE_VIDEO,
165
.id = AV_CODEC_ID_VCR1,
166
.priv_data_size = sizeof(VCR1Context),
167
.init = vcr1_decode_init,
168
.close = vcr1_decode_end,
169
.decode = vcr1_decode_frame,
170
.capabilities = CODEC_CAP_DR1,
171
.long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
174
/* Disable the encoder. */
175
#undef CONFIG_VCR1_ENCODER
176
#define CONFIG_VCR1_ENCODER 0
120
178
#if CONFIG_VCR1_ENCODER
121
static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
122
VCR1Context * const a = avctx->priv_data;
123
AVFrame *pict = data;
124
AVFrame * const p= (AVFrame*)&a->picture;
180
#include "put_bits.h"
182
static int vcr1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
183
int buf_size, void *data)
185
VCR1Context *const a = avctx->priv_data;
186
AVFrame *pict = data;
187
AVFrame *const p = &a->picture;
128
p->pict_type= AV_PICTURE_TYPE_I;
191
p->pict_type = AV_PICTURE_TYPE_I;
131
194
avpriv_align_put_bits(&a->pb);
132
while(get_bit_count(&a->pb)&31)
133
put_bits(&a->pb, 8, 0);
135
size= get_bit_count(&a->pb)/32;
141
static av_cold void common_init(AVCodecContext *avctx){
142
VCR1Context * const a = avctx->priv_data;
144
avctx->coded_frame= (AVFrame*)&a->picture;
148
static av_cold int decode_init(AVCodecContext *avctx){
152
avctx->pix_fmt= PIX_FMT_YUV410P;
157
static av_cold int decode_end(AVCodecContext *avctx){
158
VCR1Context *s = avctx->priv_data;
160
if (s->picture.data[0])
161
avctx->release_buffer(avctx, &s->picture);
166
#if CONFIG_VCR1_ENCODER
167
static av_cold int encode_init(AVCodecContext *avctx){
175
AVCodec ff_vcr1_decoder = {
177
.type = AVMEDIA_TYPE_VIDEO,
179
.priv_data_size = sizeof(VCR1Context),
182
.decode = decode_frame,
183
.capabilities = CODEC_CAP_DR1,
184
.long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
187
#if CONFIG_VCR1_ENCODER
195
flush_put_bits(&a->pb);
197
size = put_bits_count(&a->pb) / 32;
188
202
AVCodec ff_vcr1_encoder = {
190
204
.type = AVMEDIA_TYPE_VIDEO,
205
.id = AV_CODEC_ID_VCR1,
192
206
.priv_data_size = sizeof(VCR1Context),
194
.encode = encode_frame,
195
.long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
207
.init = vcr1_common_init,
208
.encode = vcr1_encode_frame,
209
.long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
211
#endif /* CONFIG_VCR1_ENCODER */