3 * Copyright (c) 2003 Michael Niedermayer
5 * This file is part of Libav.
7 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "libavutil/internal.h"
31 typedef struct VCR1Context {
37 static av_cold int vcr1_common_init(AVCodecContext *avctx)
39 VCR1Context *const a = avctx->priv_data;
41 avctx->coded_frame = &a->picture;
46 static av_cold int vcr1_decode_init(AVCodecContext *avctx)
48 vcr1_common_init(avctx);
50 avctx->pix_fmt = PIX_FMT_YUV410P;
55 static av_cold int vcr1_decode_end(AVCodecContext *avctx)
57 VCR1Context *s = avctx->priv_data;
59 if (s->picture.data[0])
60 avctx->release_buffer(avctx, &s->picture);
65 static int vcr1_decode_frame(AVCodecContext *avctx, void *data,
66 int *data_size, AVPacket *avpkt)
68 const uint8_t *buf = avpkt->data;
69 int buf_size = avpkt->size;
70 VCR1Context *const a = avctx->priv_data;
71 AVFrame *picture = data;
72 AVFrame *const p = &a->picture;
73 const uint8_t *bytestream = buf;
77 avctx->release_buffer(avctx, p);
80 if (avctx->get_buffer(avctx, p) < 0) {
81 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
84 p->pict_type = AV_PICTURE_TYPE_I;
87 for (i = 0; i < 16; i++) {
88 a->delta[i] = *bytestream++;
92 for (y = 0; y < avctx->height; y++) {
94 uint8_t *luma = &a->picture.data[0][y * a->picture.linesize[0]];
97 uint8_t *cb = &a->picture.data[1][(y >> 2) * a->picture.linesize[1]];
98 uint8_t *cr = &a->picture.data[2][(y >> 2) * a->picture.linesize[2]];
100 for (i = 0; i < 4; i++)
101 a->offset[i] = *bytestream++;
103 offset = a->offset[0] - a->delta[bytestream[2] & 0xF];
104 for (x = 0; x < avctx->width; x += 4) {
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[0] & 0xF];
108 luma[3] = offset += a->delta[bytestream[0] >> 4];
111 *cb++ = bytestream[3];
112 *cr++ = bytestream[1];
117 offset = a->offset[y & 3] - a->delta[bytestream[2] & 0xF];
119 for (x = 0; x < avctx->width; x += 8) {
120 luma[0] = offset += a->delta[bytestream[2] & 0xF];
121 luma[1] = offset += a->delta[bytestream[2] >> 4];
122 luma[2] = offset += a->delta[bytestream[3] & 0xF];
123 luma[3] = offset += a->delta[bytestream[3] >> 4];
124 luma[4] = offset += a->delta[bytestream[0] & 0xF];
125 luma[5] = offset += a->delta[bytestream[0] >> 4];
126 luma[6] = offset += a->delta[bytestream[1] & 0xF];
127 luma[7] = offset += a->delta[bytestream[1] >> 4];
134 *picture = a->picture;
135 *data_size = sizeof(AVPicture);
140 AVCodec ff_vcr1_decoder = {
142 .type = AVMEDIA_TYPE_VIDEO,
143 .id = AV_CODEC_ID_VCR1,
144 .priv_data_size = sizeof(VCR1Context),
145 .init = vcr1_decode_init,
146 .close = vcr1_decode_end,
147 .decode = vcr1_decode_frame,
148 .capabilities = CODEC_CAP_DR1,
149 .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
152 /* Disable the encoder. */
153 #undef CONFIG_VCR1_ENCODER
154 #define CONFIG_VCR1_ENCODER 0
156 #if CONFIG_VCR1_ENCODER
158 #include "put_bits.h"
160 static int vcr1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
161 int buf_size, void *data)
163 VCR1Context *const a = avctx->priv_data;
164 AVFrame *pict = data;
165 AVFrame *const p = &a->picture;
169 p->pict_type = AV_PICTURE_TYPE_I;
172 avpriv_align_put_bits(&a->pb);
173 flush_put_bits(&a->pb);
175 size = put_bits_count(&a->pb) / 32;
180 AVCodec ff_vcr1_encoder = {
182 .type = AVMEDIA_TYPE_VIDEO,
183 .id = AV_CODEC_ID_VCR1,
184 .priv_data_size = sizeof(VCR1Context),
185 .init = vcr1_common_init,
186 .encode = vcr1_encode_frame,
187 .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"),
189 #endif /* CONFIG_VCR1_ENCODER */