Mercurial > libavcodec.hg
annotate avs.c @ 6439:8cb7a8f13c2c libavcodec
remove old draw_edges declaration cruft
author | aurel |
---|---|
date | Tue, 04 Mar 2008 10:54:51 +0000 |
parents | a955fb25671d |
children | 48759bfbd073 |
rev | line source |
---|---|
3129
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
1 /* |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
2 * AVS video decoder. |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
3 * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org> |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3129
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3129
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3129
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
3129
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3129
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
3129
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3129
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
3129
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
16 * |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3129
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
5215 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
3129
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
20 */ |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
21 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
22 #include "avcodec.h" |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
23 #include "bitstream.h" |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
24 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
25 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
26 typedef struct { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
27 AVFrame picture; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
28 } avs_context_t; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
29 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
30 typedef enum { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
31 AVS_VIDEO = 0x01, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
32 AVS_AUDIO = 0x02, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
33 AVS_PALETTE = 0x03, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
34 AVS_GAME_DATA = 0x04, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
35 } avs_block_type_t; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
36 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
37 typedef enum { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
38 AVS_I_FRAME = 0x00, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
39 AVS_P_FRAME_3X3 = 0x01, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
40 AVS_P_FRAME_2X2 = 0x02, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
41 AVS_P_FRAME_2X3 = 0x03, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
42 } avs_video_sub_type_t; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
43 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
44 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
45 static int |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
46 avs_decode_frame(AVCodecContext * avctx, |
6226 | 47 void *data, int *data_size, const uint8_t * buf, int buf_size) |
3129
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
48 { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
49 avs_context_t *const avs = avctx->priv_data; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
50 AVFrame *picture = data; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
51 AVFrame *const p = (AVFrame *) & avs->picture; |
6226 | 52 const uint8_t *table, *vect; |
53 uint8_t *out; | |
3129
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
54 int i, j, x, y, stride, vect_w = 3, vect_h = 3; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
55 int sub_type; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
56 avs_block_type_t type; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
57 GetBitContext change_map; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
58 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
59 if (avctx->reget_buffer(avctx, p)) { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
60 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
61 return -1; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
62 } |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
63 p->reference = 1; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
64 p->pict_type = FF_P_TYPE; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
65 p->key_frame = 0; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
66 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
67 out = avs->picture.data[0]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
68 stride = avs->picture.linesize[0]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
69 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
70 sub_type = buf[0]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
71 type = buf[1]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
72 buf += 4; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
73 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
74 if (type == AVS_PALETTE) { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
75 int first, last; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
76 uint32_t *pal = (uint32_t *) avs->picture.data[1]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
77 |
4364 | 78 first = AV_RL16(buf); |
79 last = first + AV_RL16(buf + 2); | |
3129
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
80 buf += 4; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
81 for (i=first; i<last; i++, buf+=3) |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
82 pal[i] = (buf[0] << 18) | (buf[1] << 10) | (buf[2] << 2); |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
83 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
84 sub_type = buf[0]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
85 type = buf[1]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
86 buf += 4; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
87 } |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
88 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
89 if (type != AVS_VIDEO) |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
90 return -1; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
91 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
92 switch (sub_type) { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
93 case AVS_I_FRAME: |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
94 p->pict_type = FF_I_TYPE; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
95 p->key_frame = 1; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
96 case AVS_P_FRAME_3X3: |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
97 vect_w = 3; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
98 vect_h = 3; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
99 break; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
100 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
101 case AVS_P_FRAME_2X2: |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
102 vect_w = 2; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
103 vect_h = 2; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
104 break; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
105 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
106 case AVS_P_FRAME_2X3: |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
107 vect_w = 2; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
108 vect_h = 3; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
109 break; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
110 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
111 default: |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
112 return -1; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
113 } |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
114 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
115 table = buf + (256 * vect_w * vect_h); |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
116 if (sub_type != AVS_I_FRAME) { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
117 int map_size = ((318 / vect_w + 7) / 8) * (198 / vect_h); |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
118 init_get_bits(&change_map, table, map_size); |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
119 table += map_size; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
120 } |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
121 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
122 for (y=0; y<198; y+=vect_h) { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
123 for (x=0; x<318; x+=vect_w) { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
124 if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
125 vect = &buf[*table++ * (vect_w * vect_h)]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
126 for (j=0; j<vect_w; j++) { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
127 out[(y + 0) * stride + x + j] = vect[(0 * vect_w) + j]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
128 out[(y + 1) * stride + x + j] = vect[(1 * vect_w) + j]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
129 if (vect_h == 3) |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
130 out[(y + 2) * stride + x + j] = |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
131 vect[(2 * vect_w) + j]; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
132 } |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
133 } |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
134 } |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
135 if (sub_type != AVS_I_FRAME) |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
136 align_get_bits(&change_map); |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
137 } |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
138 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
139 *picture = *(AVFrame *) & avs->picture; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
140 *data_size = sizeof(AVPicture); |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
141 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
142 return buf_size; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
143 } |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
144 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
145 static int avs_decode_init(AVCodecContext * avctx) |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
146 { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
147 avctx->pix_fmt = PIX_FMT_PAL8; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
148 return 0; |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
149 } |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
150 |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
151 AVCodec avs_decoder = { |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
152 "avs", |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
153 CODEC_TYPE_VIDEO, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
154 CODEC_ID_AVS, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
155 sizeof(avs_context_t), |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
156 avs_decode_init, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
157 NULL, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
158 NULL, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
159 avs_decode_frame, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
160 CODEC_CAP_DR1, |
0ebbd476ba32
complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff
changeset
|
161 }; |