Statistics
| Branch: | Revision:

ffmpeg / libavcodec / vcr1.c @ 5509bffa

History | View | Annotate | Download (4.72 KB)

1 be3564ed Michael Niedermayer
/*
2
 * ATI VCR1 codec
3
 * Copyright (c) 2003 Michael Niedermayer
4
 *
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.
9
 *
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.
14
 *
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 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 be3564ed Michael Niedermayer
 */
19 115329f1 Diego Biurrun
20 be3564ed Michael Niedermayer
/**
21
 * @file vcr1.c
22
 * ati vcr1 codec.
23
 */
24 115329f1 Diego Biurrun
25 be3564ed Michael Niedermayer
#include "avcodec.h"
26
#include "mpegvideo.h"
27
28
//#undef NDEBUG
29
//#include <assert.h>
30
31
typedef struct VCR1Context{
32
    AVCodecContext *avctx;
33
    AVFrame picture;
34
    int delta[16];
35
    int offset[4];
36
} VCR1Context;
37
38 115329f1 Diego Biurrun
static int decode_frame(AVCodecContext *avctx,
39 be3564ed Michael Niedermayer
                        void *data, int *data_size,
40
                        uint8_t *buf, int buf_size)
41
{
42
    VCR1Context * const a = avctx->priv_data;
43
    AVFrame *picture = data;
44
    AVFrame * const p= (AVFrame*)&a->picture;
45
    uint8_t *bytestream= buf;
46
    int i, x, y;
47
48
    if(p->data[0])
49
        avctx->release_buffer(avctx, p);
50
51
    p->reference= 0;
52
    if(avctx->get_buffer(avctx, p) < 0){
53 9b879566 Michel Bardiaux
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
54 be3564ed Michael Niedermayer
        return -1;
55
    }
56
    p->pict_type= I_TYPE;
57
    p->key_frame= 1;
58
59
    for(i=0; i<16; i++){
60
        a->delta[i]= *(bytestream++);
61
        bytestream++;
62
    }
63 115329f1 Diego Biurrun
64 be3564ed Michael Niedermayer
    for(y=0; y<avctx->height; y++){
65
        int offset;
66
        uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
67
68
        if((y&3) == 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] ];
71
72
            for(i=0; i<4; i++)
73
                a->offset[i]= *(bytestream++);
74
75 14bc6e63 Michael Niedermayer
            offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
76 be3564ed Michael Niedermayer
            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  ]);
81
                luma += 4;
82 115329f1 Diego Biurrun
83 14bc6e63 Michael Niedermayer
                *(cb++) = bytestream[3];
84
                *(cr++) = bytestream[1];
85 115329f1 Diego Biurrun
86 be3564ed Michael Niedermayer
                bytestream+= 4;
87
            }
88
        }else{
89 14bc6e63 Michael Niedermayer
            offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
90 be3564ed Michael Niedermayer
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  ]);
100
                luma += 8;
101
                bytestream+= 4;
102
            }
103
        }
104
    }
105
106
    *picture= *(AVFrame*)&a->picture;
107
    *data_size = sizeof(AVPicture);
108
109
    emms_c();
110 115329f1 Diego Biurrun
111 be3564ed Michael Niedermayer
    return buf_size;
112
}
113
114
#if 0
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;
119
    int size;
120
    int mb_x, mb_y;
121

122
    *p = *pict;
123
    p->pict_type= I_TYPE;
124
    p->key_frame= 1;
125

126
    emms_c();
127 115329f1 Diego Biurrun

128 be3564ed Michael Niedermayer
    align_put_bits(&a->pb);
129
    while(get_bit_count(&a->pb)&31)
130
        put_bits(&a->pb, 8, 0);
131 115329f1 Diego Biurrun

132 be3564ed Michael Niedermayer
    size= get_bit_count(&a->pb)/32;
133 115329f1 Diego Biurrun

134 be3564ed Michael Niedermayer
    return size*4;
135
}
136
#endif
137
138
static void common_init(AVCodecContext *avctx){
139
    VCR1Context * const a = avctx->priv_data;
140
141
    avctx->coded_frame= (AVFrame*)&a->picture;
142
    a->avctx= avctx;
143
}
144
145
static int decode_init(AVCodecContext *avctx){
146 115329f1 Diego Biurrun
147 be3564ed Michael Niedermayer
    common_init(avctx);
148 115329f1 Diego Biurrun
149 be3564ed Michael Niedermayer
    avctx->pix_fmt= PIX_FMT_YUV410P;
150
151
    return 0;
152
}
153
154 88730be6 Måns Rullgård
#if 0
155 be3564ed Michael Niedermayer
static int encode_init(AVCodecContext *avctx){
156 115329f1 Diego Biurrun

157 be3564ed Michael Niedermayer
    common_init(avctx);
158 115329f1 Diego Biurrun

159 be3564ed Michael Niedermayer
    return 0;
160
}
161 88730be6 Måns Rullgård
#endif
162 be3564ed Michael Niedermayer
163
AVCodec vcr1_decoder = {
164
    "vcr1",
165
    CODEC_TYPE_VIDEO,
166
    CODEC_ID_VCR1,
167
    sizeof(VCR1Context),
168
    decode_init,
169
    NULL,
170 eea8c08f Michael Niedermayer
    NULL,
171 be3564ed Michael Niedermayer
    decode_frame,
172
    CODEC_CAP_DR1,
173
};
174
#if 0
175
#ifdef CONFIG_ENCODERS
176

177
AVCodec vcr1_encoder = {
178
    "vcr1",
179
    CODEC_TYPE_VIDEO,
180
    CODEC_ID_VCR1,
181
    sizeof(VCR1Context),
182
    encode_init,
183
    encode_frame,
184
    //encode_end,
185
};
186

187
#endif //CONFIG_ENCODERS
188
#endif