3 * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
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
23 #include "bitstream.h"
39 AVS_P_FRAME_3X3
= 0x01,
40 AVS_P_FRAME_2X2
= 0x02,
41 AVS_P_FRAME_2X3
= 0x03,
42 } avs_video_sub_type_t
;
46 avs_decode_frame(AVCodecContext
* avctx
,
47 void *data
, int *data_size
, uint8_t * buf
, int buf_size
)
49 avs_context_t
*const avs
= avctx
->priv_data
;
50 AVFrame
*picture
= data
;
51 AVFrame
*const p
= (AVFrame
*) & avs
->picture
;
52 uint8_t *table
, *vect
, *out
;
53 int i
, j
, x
, y
, stride
, vect_w
= 3, vect_h
= 3;
55 avs_block_type_t type
;
56 GetBitContext change_map
;
58 if (avctx
->reget_buffer(avctx
, p
)) {
59 av_log(avctx
, AV_LOG_ERROR
, "reget_buffer() failed\n");
63 p
->pict_type
= FF_P_TYPE
;
66 out
= avs
->picture
.data
[0];
67 stride
= avs
->picture
.linesize
[0];
73 if (type
== AVS_PALETTE
) {
75 uint32_t *pal
= (uint32_t *) avs
->picture
.data
[1];
78 last
= first
+ AV_RL16(buf
+ 2);
80 for (i
=first
; i
<last
; i
++, buf
+=3)
81 pal
[i
] = (buf
[0] << 18) | (buf
[1] << 10) | (buf
[2] << 2);
88 if (type
!= AVS_VIDEO
)
93 p
->pict_type
= FF_I_TYPE
;
100 case AVS_P_FRAME_2X2
:
105 case AVS_P_FRAME_2X3
:
114 table
= buf
+ (256 * vect_w
* vect_h
);
115 if (sub_type
!= AVS_I_FRAME
) {
116 int map_size
= ((318 / vect_w
+ 7) / 8) * (198 / vect_h
);
117 init_get_bits(&change_map
, table
, map_size
);
121 for (y
=0; y
<198; y
+=vect_h
) {
122 for (x
=0; x
<318; x
+=vect_w
) {
123 if (sub_type
== AVS_I_FRAME
|| get_bits1(&change_map
)) {
124 vect
= &buf
[*table
++ * (vect_w
* vect_h
)];
125 for (j
=0; j
<vect_w
; j
++) {
126 out
[(y
+ 0) * stride
+ x
+ j
] = vect
[(0 * vect_w
) + j
];
127 out
[(y
+ 1) * stride
+ x
+ j
] = vect
[(1 * vect_w
) + j
];
129 out
[(y
+ 2) * stride
+ x
+ j
] =
130 vect
[(2 * vect_w
) + j
];
134 if (sub_type
!= AVS_I_FRAME
)
135 align_get_bits(&change_map
);
138 *picture
= *(AVFrame
*) & avs
->picture
;
139 *data_size
= sizeof(AVPicture
);
144 static int avs_decode_init(AVCodecContext
* avctx
)
146 avctx
->pix_fmt
= PIX_FMT_PAL8
;
150 AVCodec avs_decoder
= {
154 sizeof(avs_context_t
),