3 * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
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 St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "bitstream.h"
37 AVS_P_FRAME_3X3
= 0x01,
38 AVS_P_FRAME_2X2
= 0x02,
39 AVS_P_FRAME_2X3
= 0x03,
40 } avs_video_sub_type_t
;
44 avs_decode_frame(AVCodecContext
* avctx
,
45 void *data
, int *data_size
, uint8_t * buf
, int buf_size
)
47 avs_context_t
*const avs
= avctx
->priv_data
;
48 AVFrame
*picture
= data
;
49 AVFrame
*const p
= (AVFrame
*) & avs
->picture
;
50 uint8_t *table
, *vect
, *out
;
51 int i
, j
, x
, y
, stride
, vect_w
= 3, vect_h
= 3;
53 avs_block_type_t type
;
54 GetBitContext change_map
;
56 if (avctx
->reget_buffer(avctx
, p
)) {
57 av_log(avctx
, AV_LOG_ERROR
, "reget_buffer() failed\n");
61 p
->pict_type
= FF_P_TYPE
;
64 out
= avs
->picture
.data
[0];
65 stride
= avs
->picture
.linesize
[0];
71 if (type
== AVS_PALETTE
) {
73 uint32_t *pal
= (uint32_t *) avs
->picture
.data
[1];
76 last
= first
+ LE_16(buf
+ 2);
78 for (i
=first
; i
<last
; i
++, buf
+=3)
79 pal
[i
] = (buf
[0] << 18) | (buf
[1] << 10) | (buf
[2] << 2);
86 if (type
!= AVS_VIDEO
)
91 p
->pict_type
= FF_I_TYPE
;
103 case AVS_P_FRAME_2X3
:
112 table
= buf
+ (256 * vect_w
* vect_h
);
113 if (sub_type
!= AVS_I_FRAME
) {
114 int map_size
= ((318 / vect_w
+ 7) / 8) * (198 / vect_h
);
115 init_get_bits(&change_map
, table
, map_size
);
119 for (y
=0; y
<198; y
+=vect_h
) {
120 for (x
=0; x
<318; x
+=vect_w
) {
121 if (sub_type
== AVS_I_FRAME
|| get_bits1(&change_map
)) {
122 vect
= &buf
[*table
++ * (vect_w
* vect_h
)];
123 for (j
=0; j
<vect_w
; j
++) {
124 out
[(y
+ 0) * stride
+ x
+ j
] = vect
[(0 * vect_w
) + j
];
125 out
[(y
+ 1) * stride
+ x
+ j
] = vect
[(1 * vect_w
) + j
];
127 out
[(y
+ 2) * stride
+ x
+ j
] =
128 vect
[(2 * vect_w
) + j
];
132 if (sub_type
!= AVS_I_FRAME
)
133 align_get_bits(&change_map
);
136 *picture
= *(AVFrame
*) & avs
->picture
;
137 *data_size
= sizeof(AVPicture
);
142 static int avs_decode_init(AVCodecContext
* avctx
)
144 avctx
->pix_fmt
= PIX_FMT_PAL8
;
148 AVCodec avs_decoder
= {
152 sizeof(avs_context_t
),