author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 2000 19:40:46 +0100 | |
changeset 1437 | b4cc563c0895 |
parent 1436 | 7477ea5b2cdd |
child 1745 | 4fa0fad2a463 |
permissions | -rw-r--r-- |
540 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
525 | 12 |
|
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
13 |
"{ Package: 'stx:libview2' }" |
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
14 |
|
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
15 |
ImageReader subclass:#AVIReader |
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
16 |
instanceVariableNames:'riffReader frames nframes frameBuffer frameBufferSize imageBuffer |
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
17 |
redPalette greenPalette bluePalette flags frameDelay streamType |
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
18 |
depth compression colorTable numColors deltaMethod' |
525 | 19 |
classVariableNames:'MAXCOLORS UnsupportedFormatErrorSignal' |
20 |
poolDictionaries:'' |
|
21 |
category:'Graphics-Images-Support' |
|
22 |
! |
|
23 |
||
24 |
!AVIReader class methodsFor:'documentation'! |
|
25 |
||
526 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! |
|
39 |
||
525 | 40 |
documentation |
41 |
" |
|
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
42 |
This is not yet completed, untested and highly experimental. |
540 | 43 |
|
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
44 |
This reader read frames from an AVI file; however, only a tiny subset of AVI is supported. |
616 | 45 |
|
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
46 |
This is a very first attempt in reading AVI files; |
616 | 47 |
Its very experimental, preliminary and will certainly change. |
48 |
(will introduce a new class hierarchy based upon some MovieReader ...). |
|
525 | 49 |
|
50 |
When used like an imageReader, #fromFile: will return |
|
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
51 |
the very first frame and the rest as imageFrameSequence. |
525 | 52 |
|
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
53 |
Warning: |
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
54 |
right now, the complete movie is read and huge |
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
55 |
amounts of memory are allocated. |
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
56 |
The interface will be changed to allow stream operation ... |
525 | 57 |
|
58 |
[author:] |
|
59 |
Claus Gittinger |
|
60 |
||
61 |
[see also:] |
|
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
62 |
ImageReader RIFFReader |
525 | 63 |
" |
64 |
! |
|
65 |
||
66 |
examples |
|
67 |
" |
|
68 |
|reader film view tNext| |
|
69 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
70 |
reader := AVIReader readFile:'/phys/exept/home/pd_stuff/movies/avi/drlair.avi'. |
525 | 71 |
reader isNil ifTrue:[^ nil]. |
72 |
film := reader images. |
|
73 |
view := StandardSystemView extent:(film first extent). |
|
74 |
view openAndWait. |
|
75 |
||
76 |
tNext := Time millisecondClockValue + (reader frameDelay). |
|
77 |
film do:[:frame | |
|
78 |
frame displayOn:view x:0 y:0. |
|
79 |
(Delay untilMilliseconds:tNext) wait. |
|
80 |
tNext := tNext + (reader frameDelay). |
|
81 |
]. |
|
82 |
" |
|
83 |
! ! |
|
84 |
||
85 |
!AVIReader class methodsFor:'class initialization'! |
|
86 |
||
87 |
initialize |
|
88 |
MAXCOLORS := 256. |
|
89 |
||
90 |
UnsupportedFormatErrorSignal isNil ifTrue:[ |
|
91 |
UnsupportedFormatErrorSignal := ErrorSignal newSignalMayProceed:true. |
|
92 |
UnsupportedFormatErrorSignal nameClass:self message:#unsupportedFormatErrorSignal. |
|
93 |
]. |
|
94 |
||
95 |
" |
|
96 |
AVIReader initialize |
|
97 |
" |
|
98 |
||
99 |
"Created: 4.4.1997 / 22:35:52 / cg" |
|
100 |
"Modified: 5.4.1997 / 14:37:08 / cg" |
|
101 |
! ! |
|
102 |
||
103 |
!AVIReader class methodsFor:'testing'! |
|
104 |
||
105 |
isValidImageFile:aFileName |
|
106 |
"return true, if aFileName contains an AVI-movie" |
|
107 |
||
1437 | 108 |
^ RIFFReader isRIFFFile:aFileName withType:'AVI' |
525 | 109 |
|
110 |
" |
|
1437 | 111 |
AVIReader isValidImageFile:'bitmaps/magtape.xpm' |
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
112 |
AVIReader isValidImageFile:'/phys/exept/home/pd_stuff/movies/avi/drlair.avi' |
525 | 113 |
" |
114 |
||
115 |
"Created: 4.4.1997 / 22:35:52 / cg" |
|
116 |
"Modified: 4.4.1997 / 23:15:39 / cg" |
|
117 |
! ! |
|
118 |
||
119 |
!AVIReader methodsFor:'accessing'! |
|
120 |
||
121 |
frameDelay |
|
122 |
"return the value of the instance variable 'frameDelay' (automatically generated)" |
|
123 |
||
124 |
^ frameDelay |
|
125 |
||
126 |
"Created: 4.4.1997 / 22:35:52 / cg" |
|
127 |
! |
|
128 |
||
129 |
images |
|
130 |
"return a collection of all images as represented by myself" |
|
131 |
||
622 | 132 |
|image depth| |
525 | 133 |
|
134 |
depth := self bitsPerPixel. |
|
622 | 135 |
1 to:imageSequence size do:[:i | |
136 |
|frame| |
|
525 | 137 |
|
622 | 138 |
frame := imageSequence at:i. |
139 |
||
140 |
frame isImage ifFalse:[ |
|
141 |
image := (Image implementorForDepth:depth) new. |
|
142 |
image |
|
143 |
width:width |
|
144 |
height:height |
|
145 |
photometric:photometric |
|
146 |
samplesPerPixel:samplesPerPixel |
|
147 |
bitsPerSample:bitsPerSample |
|
148 |
colorMap:colorMap |
|
149 |
bits:frame |
|
150 |
mask:mask. |
|
151 |
imageSequence at:i put:image. |
|
152 |
]. |
|
525 | 153 |
]. |
622 | 154 |
^ imageSequence |
525 | 155 |
|
156 |
"Created: 4.4.1997 / 22:35:52 / cg" |
|
622 | 157 |
"Modified: 24.6.1997 / 15:57:17 / cg" |
525 | 158 |
! ! |
159 |
||
160 |
!AVIReader methodsFor:'decoders'! |
|
161 |
||
162 |
AVI_Decode_CRAM:data |
|
163 |
" |
|
164 |
||
165 |
/* |
|
166 |
* Routine to Decode an AVI CRAM chunk |
|
167 |
*/ |
|
168 |
||
169 |
#define AVI_CRAM_C1(ip,clr,rdec) { \ |
|
170 |
*ip++ = clr; *ip++ = clr; *ip++ = clr; *ip = clr; ip -= rdec; \ |
|
171 |
*ip++ = clr; *ip++ = clr; *ip++ = clr; *ip = clr; ip -= rdec; \ |
|
172 |
*ip++ = clr; *ip++ = clr; *ip++ = clr; *ip = clr; ip -= rdec; \ |
|
173 |
*ip++ = clr; *ip++ = clr; *ip++ = clr; *ip = clr; } |
|
174 |
||
175 |
#define AVI_CRAM_C2(ip,flag,cA,cB,rdec) { \ |
|
176 |
*ip++ =(flag&0x01)?(cB):(cA); *ip++ =(flag&0x02)?(cB):(cA); \ |
|
177 |
*ip++ =(flag&0x04)?(cB):(cA); *ip =(flag&0x08)?(cB):(cA); ip-=rdec; \ |
|
178 |
*ip++ =(flag&0x10)?(cB):(cA); *ip++ =(flag&0x20)?(cB):(cA); \ |
|
179 |
*ip++ =(flag&0x40)?(cB):(cA); *ip =(flag&0x80)?(cB):(cA); } |
|
180 |
||
181 |
#define AVI_CRAM_C4(ip,flag,cA0,cA1,cB0,cB1,rdec) { \ |
|
182 |
*ip++ =(flag&0x01)?(cB0):(cA0); *ip++ =(flag&0x02)?(cB0):(cA0); \ |
|
183 |
*ip++ =(flag&0x04)?(cB1):(cA1); *ip =(flag&0x08)?(cB1):(cA1); ip-=rdec; \ |
|
184 |
*ip++ =(flag&0x10)?(cB0):(cA0); *ip++ =(flag&0x20)?(cB0):(cA0); \ |
|
185 |
*ip++ =(flag&0x40)?(cB1):(cA1); *ip =(flag&0x80)?(cB1):(cA1); } |
|
186 |
||
187 |
#define AVI_MIN_MAX_CHECK(x,y,min_x,max_x,min_y,max_y) { \ |
|
188 |
if (x < min_x) min_x = x; if (y > max_y) max_y = y; \ |
|
189 |
if (x > max_x) max_x = x; if (y < min_y) min_y = y; } |
|
190 |
||
191 |
#define AVI_BLOCK_INC(x,y,imagex) { x += 4; if (x>=imagex) { x=0; y -= 4; } } |
|
192 |
||
193 |
#define AVI_GET_16(data,dptr) { data = *dptr++; data |= (*dptr++) << 8; } |
|
194 |
||
195 |
#define AVI_CRAM_rgbC1(ip,r,g,b) { \ |
|
196 |
*ip++=r; *ip++=g; *ip++=b; *ip++=r; *ip++=g; *ip++=b; \ |
|
197 |
*ip++=r; *ip++=g; *ip++=b; *ip++=r; *ip++=g; *ip =b; } |
|
198 |
||
199 |
#define AVI_CRAM_rgbC2(ip,flag,rA,gA,bA,rB,gB,bB) { \ |
|
200 |
if (flag&0x01) {*ip++=rB; *ip++=gB; *ip++=bB;} \ |
|
201 |
else {*ip++=rA; *ip++=gA; *ip++=bA;} \ |
|
202 |
if (flag&0x02) {*ip++=rB; *ip++=gB; *ip++=bB;} \ |
|
203 |
else {*ip++=rA; *ip++=gA; *ip++=bA;} \ |
|
204 |
if (flag&0x04) {*ip++=rB; *ip++=gB; *ip++=bB;} \ |
|
205 |
else {*ip++=rA; *ip++=gA; *ip++=bA;} \ |
|
206 |
if (flag&0x08) {*ip++=rB; *ip++=gB; *ip =bB;} \ |
|
207 |
else {*ip++=rA; *ip++=gA; *ip =bA;} } |
|
208 |
||
209 |
#define AVI_CRAM_rgbC4(ip,flag,rA,gA,bA,rB,gB,bB) { \ |
|
210 |
if (flag&0x01) {*ip++=rB; *ip++=gB; *ip++=bB;} \ |
|
211 |
else {*ip++=rA; *ip++=gA; *ip++=bA;} \ |
|
212 |
if (flag&0x02) {*ip++=rB; *ip++=gB; *ip =bB;} \ |
|
213 |
else {*ip++=rA; *ip++=gA; *ip =bA;} } |
|
214 |
||
215 |
#define AVI_Get_RGBColor(r,g,b,color) \ |
|
216 |
{ register ULONG _r,_g,_b; \ |
|
217 |
_r = (color >> 10) & 0x1f; r = (_r << 3) | (_r >> 2); \ |
|
218 |
_g = (color >> 5) & 0x1f; g = (_g << 3) | (_g >> 2); \ |
|
219 |
_b = color & 0x1f; b = (_b << 3) | (_b >> 2); \ |
|
220 |
if (xa_gamma_flag==TRUE) { r = xa_gamma_adj[r]>>8; \ |
|
221 |
g = xa_gamma_adj[g]>>8; b = xa_gamma_adj[b]>>8; } } |
|
222 |
||
223 |
||
224 |
ULONG |
|
225 |
AVI_Decode_CRAM(image,delta,dsize,chdr,map,map_flag,imagex,imagey,imaged, |
|
226 |
xs,ys,xe,ye,special,extra) |
|
227 |
UBYTE *image; /* Image Buffer. */ |
|
228 |
UBYTE *delta; /* delta data. */ |
|
229 |
ULONG dsize; /* delta size */ |
|
230 |
XA_CHDR *chdr; /* color map info */ |
|
231 |
ULONG *map; /* used if it's going to be remapped. */ |
|
232 |
ULONG map_flag; /* whether or not to use remap_map info. */ |
|
233 |
ULONG imagex,imagey; /* Size of image buffer. */ |
|
234 |
ULONG imaged; /* Depth of Image. (IFF specific) */ |
|
235 |
ULONG *xs,*ys; /* pos of changed area. */ |
|
236 |
ULONG *xe,*ye; /* size of changed area. */ |
|
237 |
ULONG special; /* Special Info. */ |
|
238 |
void *extra; /* extra info needed to decode delta */ |
|
239 |
{ |
|
240 |
ULONG row_dec,exitflag,changed,block_cnt; |
|
241 |
ULONG code0,code1; |
|
242 |
LONG x,y,min_x,max_x,min_y,max_y; |
|
243 |
UBYTE *dptr; |
|
244 |
||
245 |
changed = 0; |
|
246 |
max_x = max_y = 0; min_x = imagex; min_y = imagey; |
|
247 |
dptr = delta; |
|
248 |
row_dec = imagex + 3; |
|
249 |
x = 0; |
|
250 |
y = imagey - 1; |
|
251 |
exitflag = 0; |
|
252 |
block_cnt = ((imagex * imagey) >> 4) + 1; |
|
253 |
||
254 |
if (map_flag == TRUE) |
|
255 |
{ |
|
256 |
if (x11_bytes_pixel == 4) |
|
257 |
{ |
|
258 |
while(!!exitflag) |
|
259 |
{ |
|
260 |
code0 = *dptr++; code1 = *dptr++; block_cnt--; |
|
261 |
if ( ((code1==0) && (code0==0) && !!block_cnt) || (y<0)) exitflag = 1; |
|
262 |
else |
|
263 |
{ |
|
264 |
if ((code1 >= 0x84) && (code1 <= 0x87)) /* skip */ |
|
265 |
{ ULONG skip = ((code1 - 0x84) << 8) + code0; |
|
266 |
block_cnt -= (skip-1); while(skip--) AVI_BLOCK_INC(x,y,imagex); |
|
267 |
} |
|
268 |
else /* single block encoded */ |
|
269 |
{ |
|
270 |
if (code1 >= 0x90) /* 8 color quadrant encoding */ |
|
271 |
{ ULONG cA0,cA1,cB0,cB1; |
|
272 |
ULONG *i_ptr = (ULONG *)(image + ((y * imagex + x) << 2) ); |
|
273 |
cB0 = (ULONG)map[*dptr++]; cA0 = (ULONG)map[*dptr++]; |
|
274 |
cB1 = (ULONG)map[*dptr++]; cA1 = (ULONG)map[*dptr++]; |
|
275 |
AVI_CRAM_C4(i_ptr,code0,cA0,cA1,cB0,cB1,row_dec); i_ptr -=row_dec; |
|
276 |
cB0 = (ULONG)map[*dptr++]; cA0 = (ULONG)map[*dptr++]; |
|
277 |
cB1 = (ULONG)map[*dptr++]; cA1 = (ULONG)map[*dptr++]; |
|
278 |
AVI_CRAM_C4(i_ptr,code1,cA0,cA1,cB0,cB1,row_dec); |
|
279 |
} else if (code1 < 0x80) /* 2 color encoding */ |
|
280 |
{ register ULONG clr_A,clr_B; |
|
281 |
ULONG *i_ptr = (ULONG *)(image + ((y * imagex + x) << 2) ); |
|
282 |
clr_B = (ULONG)map[*dptr++]; clr_A = (ULONG)map[*dptr++]; |
|
283 |
AVI_CRAM_C2(i_ptr,code0,clr_A,clr_B,row_dec); i_ptr -= row_dec; |
|
284 |
AVI_CRAM_C2(i_ptr,code1,clr_A,clr_B,row_dec); |
|
285 |
} |
|
286 |
else /* 1 color encoding */ |
|
287 |
{ ULONG clr = (ULONG)map[code0]; |
|
288 |
ULONG *i_ptr = (ULONG *)(image + ((y * imagex + x) << 2) ); |
|
289 |
AVI_CRAM_C1(i_ptr,clr,row_dec); |
|
290 |
} |
|
291 |
AVI_MIN_MAX_CHECK(x,y,min_x,max_x,min_y,max_y); |
|
292 |
changed = 1; AVI_BLOCK_INC(x,y,imagex); |
|
293 |
} /* end of single block */ |
|
294 |
} /* end of not term code */ |
|
295 |
} /* end of not while exit */ |
|
296 |
} /* end of 4 bytes pixel */ |
|
297 |
else if (x11_bytes_pixel == 2) |
|
298 |
{ |
|
299 |
while(!!exitflag) |
|
300 |
{ |
|
301 |
code0 = *dptr++; code1 = *dptr++; block_cnt--; |
|
302 |
if ( ((code1==0) && (code0==0) && !!block_cnt) || (y<0)) exitflag = 1; |
|
303 |
else |
|
304 |
{ |
|
305 |
if ((code1 >= 0x84) && (code1 <= 0x87)) /* skip */ |
|
306 |
{ ULONG skip = ((code1 - 0x84) << 8) + code0; |
|
307 |
block_cnt -= (skip-1); while(skip--) AVI_BLOCK_INC(x,y,imagex); |
|
308 |
} else /* single block encoded */ |
|
309 |
{ |
|
310 |
if (code1 >= 0x90) /* 8 color quadrant encoding */ |
|
311 |
{ |
|
312 |
USHORT cA0,cA1,cB0,cB1; |
|
313 |
USHORT *i_ptr = (USHORT *)(image + ((y * imagex + x) << 1) ); |
|
314 |
cB0 = map[*dptr++]; cA0 = map[*dptr++]; |
|
315 |
cB1 = map[*dptr++]; cA1 = map[*dptr++]; |
|
316 |
AVI_CRAM_C4(i_ptr,code0,cA0,cA1,cB0,cB1,row_dec); i_ptr -=row_dec; |
|
317 |
cB0 = map[*dptr++]; cA0 = map[*dptr++]; |
|
318 |
cB1 = map[*dptr++]; cA1 = map[*dptr++]; |
|
319 |
AVI_CRAM_C4(i_ptr,code1,cA0,cA1,cB0,cB1,row_dec); |
|
320 |
} /* end of 8 color quadrant encoding */ |
|
321 |
else if (code1 < 0x80) /* 2 color encoding */ |
|
322 |
{ USHORT clr_A,clr_B; |
|
323 |
USHORT *i_ptr = (USHORT *)(image + ((y * imagex + x) << 1) ); |
|
324 |
clr_B = (USHORT)map[*dptr++]; clr_A = (USHORT)map[*dptr++]; |
|
325 |
AVI_CRAM_C2(i_ptr,code0,clr_A,clr_B,row_dec); i_ptr -= row_dec; |
|
326 |
AVI_CRAM_C2(i_ptr,code1,clr_A,clr_B,row_dec); |
|
327 |
} /* end of 2 color */ |
|
328 |
else /* 1 color encoding */ |
|
329 |
{ USHORT clr = (USHORT)map[code0]; |
|
330 |
USHORT *i_ptr = (USHORT *)(image + ((y * imagex + x) << 1) ); |
|
331 |
AVI_CRAM_C1(i_ptr,clr,row_dec); |
|
332 |
} |
|
333 |
AVI_MIN_MAX_CHECK(x,y,min_x,max_x,min_y,max_y); |
|
334 |
changed = 1; AVI_BLOCK_INC(x,y,imagex); |
|
335 |
} /* end of single block */ |
|
336 |
} /* end of not term code */ |
|
337 |
} /* end of not while exit */ |
|
338 |
} /* end of 2 bytes pixel */ |
|
339 |
else /* (x11_bytes_pixel == 1) */ |
|
340 |
{ |
|
341 |
while(!!exitflag) |
|
342 |
{ |
|
343 |
code0 = *dptr++; code1 = *dptr++; block_cnt--; |
|
344 |
if ( ((code1==0) && (code0==0) && !!block_cnt) || (y<0)) exitflag = 1; |
|
345 |
else |
|
346 |
{ |
|
347 |
if ((code1 >= 0x84) && (code1 <= 0x87)) /* skip */ |
|
348 |
{ ULONG skip = ((code1 - 0x84) << 8) + code0; |
|
349 |
block_cnt -= (skip-1); while(skip--) AVI_BLOCK_INC(x,y,imagex); |
|
350 |
} else /* single block encoded */ |
|
351 |
{ |
|
352 |
if (code1 >= 0x90) /* 8 color quadrant encoding */ |
|
353 |
{ UBYTE cA0,cA1,cB0,cB1; |
|
354 |
UBYTE *i_ptr = (UBYTE *)(image + y * imagex + x); |
|
355 |
cB0 = (UBYTE)map[*dptr++]; cA0 = (UBYTE)map[*dptr++]; |
|
356 |
cB1 = (UBYTE)map[*dptr++]; cA1 = (UBYTE)map[*dptr++]; |
|
357 |
AVI_CRAM_C4(i_ptr,code0,cA0,cA1,cB0,cB1,row_dec); i_ptr -=row_dec; |
|
358 |
cB0 = (UBYTE)map[*dptr++]; cA0 = (UBYTE)map[*dptr++]; |
|
359 |
cB1 = (UBYTE)map[*dptr++]; cA1 = (UBYTE)map[*dptr++]; |
|
360 |
AVI_CRAM_C4(i_ptr,code1,cA0,cA1,cB0,cB1,row_dec); |
|
361 |
} |
|
362 |
else if (code1 < 0x80) /* 2 color encoding */ |
|
363 |
{ UBYTE clr_A,clr_B; |
|
364 |
UBYTE *i_ptr = (UBYTE *)(image + y * imagex + x); |
|
365 |
clr_B = (UBYTE)map[*dptr++]; clr_A = (UBYTE)map[*dptr++]; |
|
366 |
AVI_CRAM_C2(i_ptr,code0,clr_A,clr_B,row_dec); i_ptr -= row_dec; |
|
367 |
AVI_CRAM_C2(i_ptr,code1,clr_A,clr_B,row_dec); |
|
368 |
} |
|
369 |
else /* 1 color encoding */ |
|
370 |
{ UBYTE clr = (UBYTE)map[code0]; |
|
371 |
UBYTE *i_ptr = (UBYTE *)(image + y * imagex + x); |
|
372 |
AVI_CRAM_C1(i_ptr,clr,row_dec); |
|
373 |
} |
|
374 |
AVI_MIN_MAX_CHECK(x,y,min_x,max_x,min_y,max_y); |
|
375 |
changed = 1; AVI_BLOCK_INC(x,y,imagex); |
|
376 |
} /* end of single block */ |
|
377 |
} /* end of not term code */ |
|
378 |
} /* end of not while exit */ |
|
379 |
} /* end of 1 bytes pixel */ |
|
380 |
} /* end of map is TRUE */ |
|
381 |
else |
|
382 |
{ |
|
383 |
while(!!exitflag) |
|
384 |
{ |
|
385 |
code0 = *dptr++; code1 = *dptr++; block_cnt--; |
|
386 |
if ( ((code1==0) && (code0==0) && !!block_cnt) || (y<0)) exitflag = 1; |
|
387 |
else |
|
388 |
{ |
|
389 |
if ((code1 >= 0x84) && (code1 <= 0x87)) /* skip */ |
|
390 |
{ ULONG skip = ((code1 - 0x84) << 8) + code0; |
|
391 |
block_cnt -= (skip-1); while(skip--) AVI_BLOCK_INC(x,y,imagex); |
|
392 |
} else /* single block encoded */ |
|
393 |
{ |
|
394 |
if (code1 >= 0x90) /* 8 color quadrant encoding */ |
|
395 |
{ |
|
396 |
UBYTE cA0,cA1,cB0,cB1; |
|
397 |
UBYTE *i_ptr = (UBYTE *)(image + y * imagex + x); |
|
398 |
cB0 = (UBYTE)*dptr++; cA0 = (UBYTE)*dptr++; |
|
399 |
cB1 = (UBYTE)*dptr++; cA1 = (UBYTE)*dptr++; |
|
400 |
AVI_CRAM_C4(i_ptr,code0,cA0,cA1,cB0,cB1,row_dec); i_ptr -=row_dec; |
|
401 |
cB0 = (UBYTE)*dptr++; cA0 = (UBYTE)*dptr++; |
|
402 |
cB1 = (UBYTE)*dptr++; cA1 = (UBYTE)*dptr++; |
|
403 |
AVI_CRAM_C4(i_ptr,code1,cA0,cA1,cB0,cB1,row_dec); |
|
404 |
} |
|
405 |
else if (code1 < 0x80) /* 2 color encoding */ |
|
406 |
{ UBYTE clr_A,clr_B; |
|
407 |
UBYTE *i_ptr = (UBYTE *)(image + y * imagex + x); |
|
408 |
clr_B = (UBYTE)*dptr++; clr_A = (UBYTE)*dptr++; |
|
409 |
AVI_CRAM_C2(i_ptr,code0,clr_A,clr_B,row_dec); i_ptr -= row_dec; |
|
410 |
AVI_CRAM_C2(i_ptr,code1,clr_A,clr_B,row_dec); |
|
411 |
} /* end of 2 color */ |
|
412 |
else /* 1 color encoding */ |
|
413 |
{ |
|
414 |
UBYTE clr = (UBYTE)code0; |
|
415 |
UBYTE *i_ptr = (UBYTE *)(image + y * imagex + x); |
|
416 |
AVI_CRAM_C1(i_ptr,clr,row_dec); |
|
417 |
} |
|
418 |
AVI_MIN_MAX_CHECK(x,y,min_x,max_x,min_y,max_y); |
|
419 |
changed = 1; AVI_BLOCK_INC(x,y,imagex); |
|
420 |
} /* end of single block */ |
|
421 |
} /* end of not term code */ |
|
422 |
} /* end of not while exit */ |
|
423 |
} |
|
424 |
if (xa_optimize_flag == TRUE) |
|
425 |
{ |
|
426 |
if (changed) { *xs=min_x; *ys=min_y - 3; *xe=max_x + 4; *ye=max_y + 1; } |
|
427 |
else { *xs = *ys = *xe = *ye = 0; return(ACT_DLTA_NOP); } |
|
428 |
} |
|
429 |
else { *xs = *ys = 0; *xe = imagex; *ye = imagey; } |
|
430 |
if (map_flag) return(ACT_DLTA_MAPD); |
|
431 |
else return(ACT_DLTA_NORM); |
|
432 |
} |
|
433 |
||
434 |
" |
|
435 |
||
436 |
'AVI_Decode_CRAM' infoPrint. |
|
437 |
||
438 |
" |
|
439 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi' |
|
440 |
" |
|
441 |
||
442 |
"Created: 5.4.1997 / 16:06:10 / cg" |
|
443 |
"Modified: 11.4.1997 / 14:03:32 / cg" |
|
444 |
! ! |
|
445 |
||
446 |
!AVIReader methodsFor:'helpers'! |
|
447 |
||
448 |
alignHeightTo:multiple |
|
449 |
"make height a multiple of the argument" |
|
450 |
||
451 |
height := multiple * ((height + multiple - 1) // multiple). |
|
452 |
||
453 |
"Modified: 5.4.1997 / 14:47:36 / cg" |
|
454 |
! |
|
455 |
||
456 |
alignTo:multiple |
|
457 |
"make width & height a multiple of the argument" |
|
458 |
||
459 |
width := multiple * ((width + multiple - 1) // multiple). |
|
460 |
height := multiple * ((height + multiple - 1) // multiple). |
|
461 |
||
462 |
"Created: 5.4.1997 / 14:47:54 / cg" |
|
463 |
! |
|
464 |
||
465 |
alignWidthTo:multiple |
|
466 |
"make height a multiple of the argument" |
|
467 |
||
468 |
width := multiple * ((width + multiple - 1) // multiple). |
|
469 |
||
470 |
"Created: 5.4.1997 / 14:47:16 / cg" |
|
471 |
"Modified: 5.4.1997 / 14:47:41 / cg" |
|
472 |
! ! |
|
473 |
||
474 |
!AVIReader methodsFor:'reading from stream'! |
|
475 |
||
476 |
fromStream:aStream |
|
477 |
"read a AVI-movie from aStream. Return a frame sequence." |
|
478 |
||
479 |
inStream := aStream. |
|
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
480 |
|
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
481 |
riffReader := RIFFReader new. |
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
482 |
riffReader client:self. |
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
483 |
riffReader processStream:inStream. |
525 | 484 |
|
1436 | 485 |
"/ return the first frame as image |
525 | 486 |
|
1436 | 487 |
"/ ATTENTION: the following is not true: |
525 | 488 |
|
489 |
colorMap := Colormap |
|
490 |
redVector:redPalette |
|
491 |
greenVector:greenPalette |
|
492 |
blueVector:bluePalette. |
|
493 |
||
494 |
photometric := #palette. |
|
495 |
samplesPerPixel := 1. |
|
496 |
bitsPerSample := #(8). |
|
497 |
||
498 |
" |
|
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
499 |
AVIReader readFile:'/phys/exept/home/pd_stuff/movies/avi/drlair.avi'. |
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
500 |
AVIReader readFile:'/phys/exept/home/pd_stuff/movies/avi/hangldm.avi'. |
525 | 501 |
" |
502 |
||
503 |
"Created: 4.4.1997 / 22:35:53 / cg" |
|
622 | 504 |
"Modified: 24.6.1997 / 15:58:29 / cg" |
525 | 505 |
! |
506 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
507 |
getChunk_ISBJ:chunkSize |
525 | 508 |
"process (ignore) a ISBJ chunk" |
509 |
||
510 |
'getChunk_ISBJ -> ' infoPrint. |
|
511 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
512 |
self skipChunk:chunkSize |
525 | 513 |
|
514 |
"Created: 5.4.1997 / 15:19:17 / cg" |
|
515 |
! |
|
516 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
517 |
getChunk_auds:chunkSize |
525 | 518 |
"process an auds chunk" |
519 |
||
520 |
|format channels rate av_bps align size| |
|
521 |
||
522 |
'getChunk_auds' infoPrint. |
|
523 |
||
524 |
format := inStream nextShortMSB:false. |
|
525 |
channels := inStream nextShortMSB:false. |
|
526 |
rate := inStream nextLongMSB:false. |
|
527 |
av_bps := inStream nextLongMSB:false. |
|
528 |
align := inStream nextShortMSB:false. |
|
529 |
size := inStream nextShortMSB:false. |
|
530 |
||
531 |
inStream skip:(chunkSize - 16). |
|
532 |
||
533 |
" |
|
534 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi' |
|
535 |
" |
|
536 |
||
537 |
"Created: 5.4.1997 / 00:01:15 / cg" |
|
538 |
"Modified: 5.4.1997 / 14:34:36 / cg" |
|
539 |
! |
|
540 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
541 |
getChunk_auds_wb:chunkSize |
525 | 542 |
"process (ignore for now) an auds chunk" |
543 |
||
544 |
'getChunk_auds_wb -> ' infoPrint. |
|
545 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
546 |
self skipChunk:chunkSize |
525 | 547 |
|
548 |
" |
|
549 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi' |
|
550 |
" |
|
551 |
||
552 |
"Created: 5.4.1997 / 13:57:56 / cg" |
|
553 |
"Modified: 5.4.1997 / 14:34:33 / cg" |
|
554 |
! |
|
555 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
556 |
getChunk_avih:chunkSize |
525 | 557 |
"process an avih chunk" |
558 |
||
559 |
|us_frame max_bps pad_gram flags tot_frames init_frames nstreams |
|
560 |
sug_bsize scale rate start length| |
|
561 |
||
562 |
'getChunk_avih' infoPrint. |
|
563 |
||
564 |
chunkSize ~~ 56 ifTrue:[ |
|
565 |
self halt:'bad chunk size'. |
|
566 |
]. |
|
567 |
||
568 |
us_frame := inStream nextLongMSB:false. |
|
569 |
max_bps := inStream nextLongMSB:false. |
|
570 |
pad_gram := inStream nextLongMSB:false. |
|
571 |
flags := inStream nextLongMSB:false. |
|
572 |
tot_frames := inStream nextLongMSB:false. |
|
573 |
init_frames := inStream nextLongMSB:false. |
|
574 |
nstreams := inStream nextLongMSB:false. |
|
575 |
sug_bsize := inStream nextLongMSB:false. |
|
576 |
width := inStream nextLongMSB:false. |
|
577 |
height := inStream nextLongMSB:false. |
|
578 |
scale := inStream nextLongMSB:false. |
|
579 |
rate := inStream nextLongMSB:false. |
|
580 |
start := inStream nextLongMSB:false. |
|
581 |
length := inStream nextLongMSB:false. |
|
582 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
583 |
riffReader streamTypes:(OrderedCollection new:nstreams). |
525 | 584 |
|
585 |
" |
|
586 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi' |
|
587 |
" |
|
588 |
||
589 |
"Created: 4.4.1997 / 23:19:37 / cg" |
|
590 |
"Modified: 5.4.1997 / 14:34:30 / cg" |
|
591 |
! |
|
592 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
593 |
getChunk_hdrl:chunkSize |
525 | 594 |
"process (ignore) a hdrl chunk" |
595 |
||
596 |
'getChunk_hdrl -> ' infoPrint. |
|
597 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
598 |
self skipChunk:chunkSize |
525 | 599 |
|
600 |
"Created: 5.4.1997 / 15:18:07 / cg" |
|
601 |
! |
|
602 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
603 |
getChunk_idx1:chunkSize |
525 | 604 |
"process (ignore) a idx1 chunk" |
605 |
||
606 |
'getChunk_idx1 -> ' infoPrint. |
|
607 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
608 |
self skipChunk:chunkSize |
525 | 609 |
|
610 |
"Created: 5.4.1997 / 15:17:53 / cg" |
|
611 |
! |
|
612 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
613 |
getChunk_strf:chunkSize |
525 | 614 |
"process a strf chunk" |
615 |
||
616 |
|sel| |
|
617 |
||
618 |
'getChunk_strf -> ' infoPrint. |
|
619 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
620 |
sel := ('getChunk_' , streamType, ':') asSymbolIfInterned. |
525 | 621 |
(sel isNil or:[(self respondsTo:sel) not]) ifTrue:[ |
622 |
'[' infoPrint. ('getChunk_' , streamType) infoPrint. '] ' infoPrint. |
|
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
623 |
sel := #'getChunk_Unknown:' |
525 | 624 |
]. |
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
625 |
self perform:sel with:chunkSize. |
525 | 626 |
|
627 |
" |
|
628 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi' |
|
629 |
" |
|
630 |
||
631 |
"Created: 4.4.1997 / 23:41:09 / cg" |
|
632 |
"Modified: 5.4.1997 / 15:05:00 / cg" |
|
633 |
! |
|
634 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
635 |
getChunk_strh:chunkSize |
525 | 636 |
"process a strh chunk" |
637 |
||
638 |
|fcc_type fcc_handler priority flags rate init_frames streams |
|
639 |
sug_bsize scale start length quality samp_size size| |
|
640 |
||
641 |
'getChunk_strh' infoPrint. |
|
642 |
||
643 |
chunkSize < 48 ifTrue:[ |
|
644 |
self halt:'bad chunk size'. |
|
645 |
]. |
|
646 |
||
647 |
fcc_type := String new:4. |
|
648 |
inStream nextBytes:4 into:fcc_type. |
|
649 |
fcc_handler := inStream nextLongMSB:true. |
|
650 |
flags := inStream nextLongMSB:false. |
|
651 |
priority := inStream nextLongMSB:false. |
|
652 |
init_frames := inStream nextLongMSB:false. |
|
653 |
scale := inStream nextLongMSB:false. |
|
654 |
rate := inStream nextLongMSB:false. |
|
655 |
start := inStream nextLongMSB:false. |
|
656 |
length := inStream nextLongMSB:false. |
|
657 |
sug_bsize := inStream nextLongMSB:false. |
|
658 |
quality := inStream nextLongMSB:false. |
|
659 |
samp_size := inStream nextLongMSB:false. |
|
660 |
||
661 |
size := chunkSize. |
|
662 |
(size bitTest:1) ifTrue:[ |
|
663 |
size := size + 1 |
|
664 |
]. |
|
665 |
inStream skip:(size - 48). |
|
666 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
667 |
riffReader addStream:fcc_type. |
525 | 668 |
streamType := fcc_type. |
669 |
||
670 |
" |
|
671 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi' |
|
672 |
" |
|
673 |
||
674 |
"Created: 4.4.1997 / 23:25:54 / cg" |
|
675 |
"Modified: 5.4.1997 / 14:34:23 / cg" |
|
676 |
! |
|
677 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
678 |
getChunk_strl:chunkSize |
525 | 679 |
"process (ignore) a strl chunk" |
680 |
||
681 |
'getChunk_strl -> ' infoPrint. |
|
682 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
683 |
self skipChunk:chunkSize |
525 | 684 |
|
685 |
"Created: 5.4.1997 / 15:18:01 / cg" |
|
686 |
! |
|
687 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
688 |
getChunk_vedt:chunkSize |
525 | 689 |
"process (ignore) a vedt chunk" |
690 |
||
691 |
'getChunk_vedt -> ' infoPrint. |
|
692 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
693 |
self skipChunk:chunkSize |
525 | 694 |
|
695 |
"Created: 5.4.1997 / 15:17:43 / cg" |
|
696 |
! |
|
697 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
698 |
getChunk_vids:chunkSize |
525 | 699 |
"process a vids chunk" |
700 |
||
701 |
|size sz |
|
702 |
width height planes image_size |
|
703 |
xpels_meter ypels_meter num_colors imp_colors |
|
704 |
sel nMore| |
|
705 |
||
706 |
'getChunk_vids -> ' infoPrint. |
|
707 |
||
708 |
sz := chunkSize. |
|
709 |
(sz bitTest:1) ifTrue:[ |
|
710 |
sz := sz + 1 |
|
711 |
]. |
|
712 |
colorTable := true. |
|
713 |
||
714 |
size := inStream nextLongMSB:false. |
|
715 |
width := inStream nextLongMSB:false. |
|
716 |
height := inStream nextLongMSB:false. |
|
717 |
planes := inStream nextShortMSB:false. |
|
718 |
depth := inStream nextShortMSB:false. |
|
719 |
compression := String new:4. |
|
720 |
inStream nextBytes:4 into:compression. |
|
721 |
image_size := inStream nextLongMSB:false. |
|
722 |
xpels_meter := inStream nextLongMSB:false. |
|
723 |
ypels_meter := inStream nextLongMSB:false. |
|
724 |
num_colors := inStream nextLongMSB:false. |
|
725 |
imp_colors := inStream nextLongMSB:false. |
|
726 |
sz := sz - 40. |
|
727 |
||
728 |
numColors := num_colors. |
|
729 |
(numColors == 0 and:[depth <= 8]) ifTrue:[ |
|
730 |
numColors := 1 bitShift:depth. |
|
731 |
]. |
|
732 |
||
733 |
sel := ('setupData_vids_' , compression) asSymbolIfInterned. |
|
734 |
(sel isNil or:[(self respondsTo:sel) not]) ifTrue:[ |
|
735 |
'[' infoPrint. ('setupData_vids_' , compression) infoPrint. '] ' infoPrint. |
|
736 |
sel := #'setupData_vids_Unknown' |
|
737 |
]. |
|
738 |
||
739 |
"/ setup compression-specific data |
|
740 |
self perform:sel. |
|
741 |
||
742 |
"/ read a colorTable - if any |
|
743 |
((depth <= 8) and:[colorTable]) ifTrue:[ |
|
744 |
redPalette := ByteArray new:256. |
|
745 |
greenPalette := ByteArray new:256. |
|
746 |
bluePalette := ByteArray new:256. |
|
747 |
||
748 |
1 to:numColors do:[:i | |
|
749 |
sz > 0 ifTrue:[ |
|
750 |
bluePalette at:i put:(inStream nextByte). |
|
751 |
greenPalette at:i put:(inStream nextByte). |
|
752 |
redPalette at:i put:(inStream nextByte). |
|
753 |
inStream nextByte. "/ padding |
|
754 |
sz := sz - 4. |
|
755 |
]. |
|
756 |
] |
|
757 |
]. |
|
758 |
||
759 |
"/ read more compression-specific data |
|
760 |
sel := ('readData_vids2_' , compression) asSymbolIfInterned. |
|
761 |
(sel isNil or:[(self respondsTo:sel) not]) ifTrue:[ |
|
762 |
] ifFalse:[ |
|
763 |
nMore := self perform:sel. |
|
764 |
sz := sz - nMore. |
|
765 |
]. |
|
766 |
||
767 |
inStream skip:sz. |
|
768 |
||
769 |
" |
|
770 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi' |
|
771 |
" |
|
772 |
||
773 |
"Created: 4.4.1997 / 23:25:54 / cg" |
|
774 |
"Modified: 5.4.1997 / 15:32:10 / cg" |
|
775 |
! |
|
776 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
777 |
getChunk_vids_dc:chunkSize |
525 | 778 |
"process a vids chunk" |
779 |
||
780 |
|sz data sel| |
|
781 |
||
782 |
'getChunk_vids_dc -> ' infoPrint. |
|
783 |
||
784 |
sz := chunkSize. |
|
785 |
(sz bitTest:1) ifTrue:[ |
|
786 |
sz := sz + 1 |
|
787 |
]. |
|
788 |
||
789 |
sz == 0 ifTrue:[ |
|
790 |
"/ NOP wait frame |
|
791 |
^ self |
|
792 |
]. |
|
793 |
||
794 |
data := ByteArray new:sz. |
|
795 |
inStream nextBytes:sz into:data startingAt:1. |
|
796 |
||
797 |
sel := deltaMethod. |
|
798 |
(self respondsTo:sel) not ifTrue:[ |
|
799 |
'[' infoPrint. deltaMethod infoPrint. '] ' infoPrint. |
|
800 |
^ self |
|
801 |
]. |
|
802 |
||
803 |
self perform:deltaMethod with:data. |
|
804 |
||
805 |
" |
|
806 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi' |
|
807 |
" |
|
808 |
||
809 |
"Created: 5.4.1997 / 01:01:37 / cg" |
|
810 |
"Modified: 5.4.1997 / 15:44:46 / cg" |
|
811 |
! |
|
812 |
||
813 |
readData_vids2_IJPG |
|
814 |
"more extra data here" |
|
815 |
||
816 |
|offset jsize format cspace| |
|
817 |
||
818 |
'readData_vids2_IJPG' infoPrint. |
|
819 |
||
820 |
offset := inStream nextLongMSB:false. |
|
821 |
jsize := inStream nextLongMSB:false. |
|
822 |
format := inStream nextLongMSB:false. |
|
823 |
cspace := inStream nextLongMSB:false. |
|
824 |
||
825 |
self JFIF_Read_IJPG_Tables. |
|
826 |
||
827 |
^ 16 + 128. |
|
828 |
||
829 |
"Created: 5.4.1997 / 15:08:04 / cg" |
|
830 |
! |
|
831 |
||
832 |
readData_vids2_JPEG |
|
833 |
"more extra data here" |
|
834 |
||
835 |
|offset jsize format cspace bits hsubsamp vsubsamp| |
|
836 |
||
837 |
'readData_vids2_IJPG' infoPrint. |
|
838 |
||
839 |
offset := inStream nextLongMSB:false. |
|
840 |
jsize := inStream nextLongMSB:false. |
|
841 |
format := inStream nextLongMSB:false. |
|
842 |
cspace := inStream nextLongMSB:false. |
|
843 |
bits := inStream nextLongMSB:false. |
|
844 |
hsubsamp := inStream nextLongMSB:false. |
|
845 |
vsubsamp := inStream nextLongMSB:false. |
|
846 |
||
847 |
^ 28. |
|
848 |
||
849 |
"Created: 5.4.1997 / 15:08:43 / cg" |
|
850 |
! |
|
851 |
||
852 |
setupData_vids_CRAM |
|
853 |
"CRAM specific setup" |
|
854 |
||
855 |
'setupData_vids_CRAM' infoPrint. |
|
856 |
||
857 |
"/ need to be multiple of 4 |
|
858 |
self alignTo:4. |
|
859 |
||
860 |
depth == 8 ifTrue:[ |
|
861 |
deltaMethod := #AVI_Decode_CRAM: |
|
862 |
] ifFalse:[ |
|
863 |
depth == 16 ifTrue:[ |
|
864 |
deltaMethod := #AVI_Decode_CRAM16: |
|
865 |
] ifFalse:[ |
|
866 |
"/ 'AVI [info]: CRAM but depth ~~ 8/16 format not supported' errorPrintCR. |
|
867 |
UnsupportedFormatErrorSignal raiseErrorString:'CRAM but depth ~~ 8/16'. |
|
868 |
] |
|
869 |
] |
|
870 |
||
871 |
"Modified: 5.4.1997 / 15:42:12 / cg" |
|
872 |
! |
|
873 |
||
874 |
setupData_vids_CVID |
|
875 |
"CVID specific setup" |
|
876 |
||
877 |
'setupData_vids_CVID' infoPrint. |
|
878 |
||
879 |
"/ 'AVI [info]: Radius Cinepak format not supported' errorPrintCR. |
|
880 |
UnsupportedFormatErrorSignal raiseErrorString:'Radius Cinepak format not supported'. |
|
881 |
||
882 |
"Modified: 5.4.1997 / 15:42:38 / cg" |
|
883 |
! |
|
884 |
||
885 |
setupData_vids_IJPG |
|
886 |
"IJPG specific setup" |
|
887 |
||
888 |
'setupData_vids_IJPG' infoPrint. |
|
889 |
||
890 |
"/ need to be multiple of 4@2 |
|
891 |
self alignWidthTo:4. |
|
892 |
self alignHeightTo:2. |
|
893 |
||
894 |
depth > 8 ifTrue:[ |
|
895 |
self QT_Gen_YUV_Tabs. |
|
896 |
] ifFalse:[ |
|
897 |
colorTable := false |
|
898 |
]. |
|
899 |
self jpg_alloc_MCU_bufs:width. |
|
900 |
||
901 |
depth ~~ 24 ifTrue:[ |
|
902 |
"/ 'AVI [info]: IJPG but depth ~~ 24' errorPrintCR. |
|
903 |
UnsupportedFormatErrorSignal raiseErrorString:'IJPG but depth ~~ 24'. |
|
904 |
^ self |
|
905 |
]. |
|
906 |
deltaMethod := #JFIF_Decode_JPEG: |
|
907 |
||
908 |
"Modified: 5.4.1997 / 15:55:55 / cg" |
|
909 |
! |
|
910 |
||
911 |
setupData_vids_IV31 |
|
912 |
"IV31 specific setup" |
|
913 |
||
914 |
'setupData_vids_IV31' infoPrint. |
|
915 |
||
916 |
"/ 'AVI [info]: AVI: Intel Indeo Video Codec Not Supported' errorPrintCR. |
|
917 |
UnsupportedFormatErrorSignal raiseErrorString:'AVI: Intel Indeo Video Codec Not Supported'. |
|
918 |
||
919 |
"Created: 5.4.1997 / 15:56:43 / cg" |
|
920 |
! |
|
921 |
||
922 |
setupData_vids_IV32 |
|
923 |
"IV32 specific setup" |
|
924 |
||
925 |
'setupData_vids_IV32' infoPrint. |
|
926 |
||
927 |
"/ 'AVI [info]: AVI: Intel Indeo Video Codec Not Supported' errorPrintCR. |
|
928 |
UnsupportedFormatErrorSignal raiseErrorString:'AVI: Intel Indeo Video Codec Not Supported'. |
|
929 |
||
930 |
"Created: 5.4.1997 / 15:56:49 / cg" |
|
931 |
! |
|
932 |
||
933 |
setupData_vids_JPEG |
|
934 |
"JPEG specific setup" |
|
935 |
||
936 |
'setupData_vids_JPEG' infoPrint. |
|
937 |
||
938 |
"/ need to be multiple of 4@2 |
|
939 |
self alignWidthTo:4. |
|
940 |
self alignHeightTo:2. |
|
941 |
||
942 |
depth > 8 ifTrue:[ |
|
943 |
self QT_Gen_YUV_Tabs. |
|
944 |
] ifFalse:[ |
|
945 |
colorTable := false |
|
946 |
]. |
|
947 |
self jpg_alloc_MCU_bufs:width. |
|
948 |
||
949 |
depth ~~ 8 ifTrue:[ |
|
950 |
depth ~~ 24 ifTrue:[ |
|
951 |
"/ 'AVI [info]: JPEG but depth ~~ 8/24' errorPrintCR. |
|
952 |
UnsupportedFormatErrorSignal raiseErrorString:'JPEG but depth ~~ 8/24'. |
|
953 |
^ self |
|
954 |
] |
|
955 |
]. |
|
956 |
deltaMethod := #JFIF_Decode_JPEG: |
|
957 |
||
958 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
959 |
"Modified: 5.4.1997 / 15:55:05 / cg" |
|
960 |
! |
|
961 |
||
962 |
setupData_vids_MJPG |
|
963 |
"MJPG specific setup" |
|
964 |
||
965 |
'setupData_vids_MJPG' infoPrint. |
|
966 |
||
967 |
UnsupportedFormatErrorSignal raiseErrorString:'MJPG not yet supported'. |
|
968 |
||
969 |
"/ need to be multiple of 4@2 |
|
970 |
self alignWidthTo:4. |
|
971 |
self alignHeightTo:2. |
|
972 |
||
973 |
depth > 8 ifTrue:[ |
|
974 |
self QT_Gen_YUV_Tabs. |
|
975 |
] ifFalse:[ |
|
976 |
colorTable := false |
|
977 |
]. |
|
978 |
self jpg_alloc_MCU_bufs:width. |
|
979 |
||
980 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
981 |
"Modified: 5.4.1997 / 15:53:08 / cg" |
|
982 |
! |
|
983 |
||
984 |
setupData_vids_MSVC |
|
985 |
"MSVC specific setup" |
|
986 |
||
987 |
'setupData_vids_MSVC' infoPrint. |
|
988 |
||
989 |
"/ need to be multiple of 4 |
|
990 |
self alignTo:4. |
|
991 |
||
992 |
depth == 8 ifTrue:[ |
|
993 |
deltaMethod := #AVI_Decode_CRAM: |
|
994 |
] ifFalse:[ |
|
995 |
depth == 16 ifTrue:[ |
|
996 |
deltaMethod := #AVI_Decode_CRAM16: |
|
997 |
] ifFalse:[ |
|
998 |
"/ 'AVI [info]: MSVC but depth ~~ 8/16 format not supported' errorPrintCR. |
|
999 |
UnsupportedFormatErrorSignal raiseErrorString:'MSVC but depth ~~ 8/16'. |
|
1000 |
] |
|
1001 |
] |
|
1002 |
||
1003 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1004 |
"Modified: 5.4.1997 / 15:41:56 / cg" |
|
1005 |
! |
|
1006 |
||
1007 |
setupData_vids_NONE |
|
1008 |
"NONE specific setup" |
|
1009 |
||
1010 |
'setupData_vids_NONE' infoPrint. |
|
1011 |
||
1012 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1013 |
"Modified: 5.4.1997 / 15:34:25 / cg" |
|
1014 |
! |
|
1015 |
||
1016 |
setupData_vids_PACK |
|
1017 |
"PACK specific setup" |
|
1018 |
||
1019 |
'setupData_vids_PACK' infoPrint. |
|
1020 |
||
1021 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1022 |
"Modified: 5.4.1997 / 15:34:31 / cg" |
|
1023 |
! |
|
1024 |
||
1025 |
setupData_vids_RGB |
|
1026 |
"RGB specific setup" |
|
1027 |
||
1028 |
'setupData_vids_RGB' infoPrint. |
|
1029 |
||
1030 |
depth == 8 ifTrue:[ |
|
1031 |
deltaMethod := #AVI_Decode_RGB: |
|
1032 |
] ifFalse:[ |
|
1033 |
depth == 24 ifTrue:[ |
|
1034 |
deltaMethod := #AVI_Decode_RGB24: |
|
1035 |
] ifFalse:[ |
|
1036 |
"/ 'AVI [info]: RGB but depth ~~ 8/24 format not supported' errorPrintCR. |
|
1037 |
UnsupportedFormatErrorSignal raiseErrorString:'RGB but depth ~~ 8/24'. |
|
1038 |
] |
|
1039 |
] |
|
1040 |
||
1041 |
"Modified: 5.4.1997 / 15:41:56 / cg" |
|
1042 |
"Created: 5.4.1997 / 15:48:47 / cg" |
|
1043 |
! |
|
1044 |
||
1045 |
setupData_vids_RLE4 |
|
1046 |
"RLE4 specific setup" |
|
1047 |
||
1048 |
'setupData_vids_RLE4' infoPrint. |
|
1049 |
||
1050 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1051 |
"Modified: 5.4.1997 / 15:34:38 / cg" |
|
1052 |
! |
|
1053 |
||
1054 |
setupData_vids_RLE8 |
|
1055 |
"RLE8 specific setup" |
|
1056 |
||
1057 |
'setupData_vids_RLE8' infoPrint. |
|
1058 |
||
1059 |
depth ~~ 8 ifTrue:[ |
|
1060 |
"/ 'AVI [info]: RLE8 but depth ~~ 8 format not supported' errorPrintCR. |
|
1061 |
UnsupportedFormatErrorSignal raiseErrorString:'RLE8 but depth ~~ 8'. |
|
1062 |
^ self |
|
1063 |
]. |
|
1064 |
deltaMethod := #AVI_Decode_RLE8: |
|
1065 |
||
1066 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1067 |
"Modified: 5.4.1997 / 15:43:22 / cg" |
|
1068 |
! |
|
1069 |
||
1070 |
setupData_vids_RT21 |
|
1071 |
"RT21 specific setup" |
|
1072 |
||
1073 |
'setupData_vids_RT21' infoPrint. |
|
1074 |
||
1075 |
"/ 'AVI [info]: AVI: Intel Indeo Video Codec Not Supported' errorPrintCR. |
|
1076 |
UnsupportedFormatErrorSignal raiseErrorString:'AVI: Intel Indeo Video Codec Not Supported'. |
|
1077 |
||
1078 |
"Created: 5.4.1997 / 15:56:37 / cg" |
|
1079 |
! |
|
1080 |
||
1081 |
setupData_vids_TRAN |
|
1082 |
"TRAN specific setup" |
|
1083 |
||
1084 |
'setupData_vids_TRAN' infoPrint. |
|
1085 |
||
1086 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1087 |
"Modified: 5.4.1997 / 15:34:53 / cg" |
|
1088 |
! |
|
1089 |
||
1090 |
setupData_vids_ULTI |
|
1091 |
"ULTI specific setup" |
|
1092 |
||
1093 |
'setupData_vids_ULTI' infoPrint. |
|
1094 |
||
1095 |
depth == 16 ifTrue:[ |
|
1096 |
deltaMethod := #AVI_Decode_ULTI: |
|
1097 |
] ifFalse:[ |
|
1098 |
"/ 'AVI [info]: ULTI depth ~~ 16 format not supported' errorPrintCR. |
|
1099 |
UnsupportedFormatErrorSignal raiseErrorString:'ULTI depth ~~ 16'. |
|
1100 |
^ self. |
|
1101 |
]. |
|
1102 |
||
1103 |
"/ need to be multiple of 8 |
|
1104 |
self alignTo:8. |
|
1105 |
||
1106 |
self AVI_ULTI_Gen_YUV. |
|
1107 |
self AVI_Ulti_Gen_LTC. |
|
1108 |
||
1109 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1110 |
"Modified: 5.4.1997 / 15:46:14 / cg" |
|
1111 |
! |
|
1112 |
||
1113 |
setupData_vids_Unknown |
|
1114 |
"ignore an unknown vids chunk" |
|
1115 |
||
1116 |
'setupData_vids_Unknown' infoPrint. |
|
1117 |
||
1118 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1119 |
"Modified: 5.4.1997 / 15:32:52 / cg" |
|
1120 |
! |
|
1121 |
||
1122 |
setupData_vids_XMPG |
|
1123 |
"XMPG specific setup" |
|
1124 |
||
1125 |
'setupData_vids_XMPG' infoPrint. |
|
1126 |
||
1127 |
"/ need to be multiple of 4 |
|
1128 |
self alignTo:4. |
|
1129 |
||
1130 |
self QT_Gen_YUV_Tabs. |
|
1131 |
self jpg_alloc_MCU_bufs:width. |
|
1132 |
self jpg_setup_samp_limit_table. |
|
1133 |
self mpg_init_stuff. |
|
1134 |
||
1135 |
deltaMethod := #MPG_Decode_I: |
|
1136 |
||
1137 |
"Modified: 5.4.1997 / 15:49:53 / cg" |
|
1138 |
! |
|
1139 |
||
1140 |
setupData_vids_YUV9 |
|
1141 |
"YUV9 specific setup" |
|
1142 |
||
1143 |
'setupData_vids_YUV9' infoPrint. |
|
1144 |
||
1145 |
self QT_Gen_YUV_Tabs. |
|
1146 |
self jpg_setup_samp_limit_table. |
|
1147 |
||
1148 |
"/ need to be multiple of 4 |
|
1149 |
self alignTo:4. |
|
1150 |
||
1151 |
deltaMethod := #AVI_Decode_YUV9: |
|
1152 |
||
1153 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1154 |
"Modified: 5.4.1997 / 15:49:19 / cg" |
|
1155 |
! |
|
1156 |
||
1157 |
setupData_vids_YVU9 |
|
1158 |
"YVU9 specific setup" |
|
1159 |
||
1160 |
'setupData_vids_YVU9' infoPrint. |
|
1161 |
||
1162 |
self QT_Gen_YUV_Tabs. |
|
1163 |
self jpg_setup_samp_limit_table. |
|
1164 |
||
1165 |
"/ need to be multiple of 4 |
|
1166 |
self alignTo:4. |
|
1167 |
||
1168 |
deltaMethod := #AVI_Decode_YUV9: |
|
1169 |
||
1170 |
"Modified: 5.4.1997 / 15:49:32 / cg" |
|
1171 |
! |
|
1172 |
||
1173 |
setupData_vids_cvid |
|
1174 |
"same as CVID" |
|
1175 |
||
1176 |
'setupData_vids_cvid' infoPrint. |
|
1177 |
compression := 'CVID'. |
|
1178 |
^ self setupData_vids_CVID. |
|
1179 |
||
1180 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1181 |
"Modified: 5.4.1997 / 15:35:32 / cg" |
|
1182 |
! |
|
1183 |
||
1184 |
setupData_vids_iv31 |
|
1185 |
"same as IV31" |
|
1186 |
||
1187 |
'setupData_vids_iv31' infoPrint. |
|
1188 |
compression := 'IV31'. |
|
1189 |
^ self setupData_vids_IV31. |
|
1190 |
||
1191 |
"Created: 5.4.1997 / 15:29:54 / cg" |
|
1192 |
"Modified: 5.4.1997 / 15:35:39 / cg" |
|
1193 |
! |
|
1194 |
||
1195 |
setupData_vids_iv32 |
|
1196 |
"same as IV32" |
|
1197 |
||
1198 |
'setupData_vids_iv32' infoPrint. |
|
1199 |
compression := 'IV32'. |
|
1200 |
^ self setupData_vids_IV32. |
|
1201 |
||
1202 |
"Created: 5.4.1997 / 15:29:55 / cg" |
|
1203 |
"Modified: 5.4.1997 / 15:35:45 / cg" |
|
1204 |
! |
|
1205 |
||
1206 |
setupData_vids_jpeg |
|
1207 |
"same as JPEG" |
|
1208 |
||
1209 |
'setupData_vids_jpeg' infoPrint. |
|
1210 |
compression := 'JPEG'. |
|
1211 |
^ self setupData_vids_JPEG. |
|
1212 |
||
1213 |
"Created: 5.4.1997 / 15:29:55 / cg" |
|
1214 |
"Modified: 5.4.1997 / 15:35:53 / cg" |
|
1215 |
! |
|
1216 |
||
1217 |
setupData_vids_none |
|
1218 |
"same as NONE" |
|
1219 |
||
1220 |
'setupData_vids_none' infoPrint. |
|
1221 |
compression := 'NONE'. |
|
1222 |
^ self setupData_vids_NONE. |
|
1223 |
||
1224 |
"Created: 5.4.1997 / 15:29:55 / cg" |
|
1225 |
"Modified: 5.4.1997 / 15:36:02 / cg" |
|
1226 |
! |
|
1227 |
||
1228 |
setupData_vids_pack |
|
1229 |
"same as PACK" |
|
1230 |
||
1231 |
'setupData_vids_pack' infoPrint. |
|
1232 |
compression := 'PACK'. |
|
1233 |
^ self setupData_vids_PACK. |
|
1234 |
||
1235 |
"Created: 5.4.1997 / 15:29:55 / cg" |
|
1236 |
"Modified: 5.4.1997 / 15:36:08 / cg" |
|
1237 |
! |
|
1238 |
||
1239 |
setupData_vids_rle4 |
|
1240 |
"same as RLE4" |
|
1241 |
||
1242 |
'setupData_vids_rle4' infoPrint. |
|
1243 |
compression := 'RLE4'. |
|
1244 |
^ self setupData_vids_RLE4. |
|
1245 |
||
1246 |
"Created: 5.4.1997 / 15:29:55 / cg" |
|
1247 |
"Modified: 5.4.1997 / 15:36:14 / cg" |
|
1248 |
! |
|
1249 |
||
1250 |
setupData_vids_rle8 |
|
1251 |
"same as RLE8" |
|
1252 |
||
1253 |
'setupData_vids_rle8' infoPrint. |
|
1254 |
compression := 'RLE8'. |
|
1255 |
^ self setupData_vids_RLE8. |
|
1256 |
||
1257 |
"Created: 5.4.1997 / 15:29:55 / cg" |
|
1258 |
"Modified: 5.4.1997 / 15:36:21 / cg" |
|
1259 |
! |
|
1260 |
||
1261 |
setupData_vids_rt21 |
|
1262 |
"same as RT21" |
|
1263 |
||
1264 |
'setupData_vids_rt21' infoPrint. |
|
1265 |
compression := 'RT21'. |
|
1266 |
^ self setupData_vids_RT21. |
|
1267 |
||
1268 |
"Created: 5.4.1997 / 15:29:55 / cg" |
|
1269 |
"Modified: 5.4.1997 / 15:36:28 / cg" |
|
1270 |
! |
|
1271 |
||
1272 |
setupData_vids_tran |
|
1273 |
"same as TRAN" |
|
1274 |
||
1275 |
'setupData_vids_tran' infoPrint. |
|
1276 |
compression := 'TRAN'. |
|
1277 |
^ self setupData_vids_TRAN. |
|
1278 |
||
1279 |
"Created: 5.4.1997 / 15:29:55 / cg" |
|
1280 |
"Modified: 5.4.1997 / 15:36:35 / cg" |
|
1281 |
! |
|
1282 |
||
1283 |
setupData_vids_xmpg |
|
1284 |
"same as XMPG" |
|
1285 |
||
1286 |
'setupData_vids_xmpg' infoPrint. |
|
1287 |
compression := 'XMPG'. |
|
1288 |
^ self setupData_vids_XMPG. |
|
1289 |
||
1290 |
"Created: 5.4.1997 / 15:29:55 / cg" |
|
1291 |
"Modified: 5.4.1997 / 15:36:43 / cg" |
|
1292 |
! |
|
1293 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
1294 |
skipChunk:chunkSize |
525 | 1295 |
"skip a chunk" |
1296 |
||
1435
d7c6c5cf4d31
refactored RIFF- and AVIReader for general use
Claus Gittinger <cg@exept.de>
parents:
622
diff
changeset
|
1297 |
riffReader skipChunk:chunkSize |
525 | 1298 |
! ! |
1299 |
||
1300 |
!AVIReader class methodsFor:'documentation'! |
|
1301 |
||
1302 |
version |
|
1437 | 1303 |
^ '$Header: /cvs/stx/stx/libview2/AVIReader.st,v 1.10 2000-11-23 18:40:46 cg Exp $' |
525 | 1304 |
! ! |
1305 |
AVIReader initialize! |