525
|
1 |
'From Smalltalk/X, Version:3.1.5 on 11-apr-1997 at 6:49:46 pm' !
|
|
2 |
|
|
3 |
ImageReader subclass:#RIFFReader
|
|
4 |
instanceVariableNames:'chunkSize streamTypes'
|
|
5 |
classVariableNames:'UnsupportedFormatErrorSignal'
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Graphics-Images-Support'
|
|
8 |
!
|
|
9 |
|
|
10 |
!RIFFReader class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
Helper to read RIFF files.
|
|
15 |
"
|
|
16 |
! !
|
|
17 |
|
|
18 |
!RIFFReader class methodsFor:'class initialization'!
|
|
19 |
|
|
20 |
initialize
|
|
21 |
UnsupportedFormatErrorSignal isNil ifTrue:[
|
|
22 |
UnsupportedFormatErrorSignal := ErrorSignal newSignalMayProceed:true.
|
|
23 |
UnsupportedFormatErrorSignal nameClass:self message:#unsupportedFormatErrorSignal.
|
|
24 |
].
|
|
25 |
|
|
26 |
"
|
|
27 |
RIFFReader initialize
|
|
28 |
"
|
|
29 |
|
|
30 |
"Created: 4.4.1997 / 22:35:52 / cg"
|
|
31 |
"Modified: 5.4.1997 / 16:12:16 / cg"
|
|
32 |
! !
|
|
33 |
|
|
34 |
!RIFFReader class methodsFor:'testing'!
|
|
35 |
|
|
36 |
isRIFFFile:aFileName
|
|
37 |
"return true, if aFileName contains RIFF-encoded data"
|
|
38 |
|
|
39 |
|data1 inStream|
|
|
40 |
|
|
41 |
inStream := self streamReadingFile:aFileName.
|
|
42 |
inStream isNil ifTrue:[^ false].
|
|
43 |
inStream binary.
|
|
44 |
|
|
45 |
data1 := String new:4.
|
|
46 |
inStream nextBytes:4 into:data1.
|
|
47 |
inStream close.
|
|
48 |
|
|
49 |
^ (data1 = 'RIFF')
|
|
50 |
|
|
51 |
"
|
|
52 |
RIFFReader isRIFFFile:'bitmaps/magtape.xpm'
|
|
53 |
RIFFReader isRIFFFile:'/home2/pd_stuff/movies/avi/drlair.avi'
|
|
54 |
"
|
|
55 |
|
|
56 |
"Created: 4.4.1997 / 22:35:52 / cg"
|
|
57 |
"Modified: 5.4.1997 / 16:12:16 / cg"
|
|
58 |
! !
|
|
59 |
|
|
60 |
!RIFFReader methodsFor:'reading from stream'!
|
|
61 |
|
|
62 |
getChunk
|
|
63 |
"get a single chunk"
|
|
64 |
|
|
65 |
|id s sel streamNr streamType|
|
|
66 |
|
|
67 |
'getChunk -> ' infoPrint.
|
|
68 |
|
|
69 |
id := ' '.
|
|
70 |
inStream nextBytes:4 into:id startingAt:1.
|
|
71 |
chunkSize := inStream nextLongMSB:false.
|
|
72 |
|
|
73 |
(id at:4) == Character space ifTrue:[
|
|
74 |
id := id copyTo:3
|
|
75 |
].
|
|
76 |
|
|
77 |
(id at:1) isDigit ifTrue:[
|
|
78 |
streamNr := Number readFrom:(id copyTo:2).
|
|
79 |
streamType := streamTypes at:(streamNr + 1).
|
|
80 |
s := 'getChunk_' , streamType , '_' , (id copyFrom:3).
|
|
81 |
] ifFalse:[
|
|
82 |
s := 'getChunk_' , id.
|
|
83 |
].
|
|
84 |
sel := s asSymbolIfInterned.
|
|
85 |
(sel isNil or:[(self respondsTo:sel) not]) ifTrue:[
|
|
86 |
'[' infoPrint. s infoPrint. '] ' infoPrint.
|
|
87 |
sel := #'getChunk_Unknown'
|
|
88 |
].
|
|
89 |
|
|
90 |
self perform:sel.
|
|
91 |
|
|
92 |
'' infoPrintCR.
|
|
93 |
|
|
94 |
"Created: 5.4.1997 / 16:29:40 / cg"
|
|
95 |
"Modified: 11.4.1997 / 14:00:42 / cg"
|
|
96 |
!
|
|
97 |
|
|
98 |
getChunk_LIST
|
|
99 |
"process a LIST chunk"
|
|
100 |
|
|
101 |
'getChunk_LIST' infoPrint.
|
|
102 |
|
|
103 |
inStream skip:4.
|
|
104 |
|
|
105 |
"
|
|
106 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi'
|
|
107 |
"
|
|
108 |
|
|
109 |
"Created: 4.4.1997 / 23:18:33 / cg"
|
|
110 |
"Modified: 5.4.1997 / 16:12:16 / cg"
|
|
111 |
!
|
|
112 |
|
|
113 |
getChunk_RIFF
|
|
114 |
"process a RIFF chunk"
|
|
115 |
|
|
116 |
'getChunk_RIFF' infoPrint.
|
|
117 |
|
|
118 |
inStream skip:4.
|
|
119 |
|
|
120 |
"
|
|
121 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi'
|
|
122 |
"
|
|
123 |
|
|
124 |
"Created: 4.4.1997 / 23:18:08 / cg"
|
|
125 |
"Modified: 5.4.1997 / 16:12:16 / cg"
|
|
126 |
!
|
|
127 |
|
|
128 |
getChunk_Unknown
|
|
129 |
"ignore any other chunk"
|
|
130 |
|
|
131 |
'getChunk_Unknown -> ' infoPrint.
|
|
132 |
|
|
133 |
self skipChunk
|
|
134 |
|
|
135 |
"
|
|
136 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi'
|
|
137 |
"
|
|
138 |
|
|
139 |
"Created: 5.4.1997 / 00:03:43 / cg"
|
|
140 |
"Modified: 5.4.1997 / 16:12:16 / cg"
|
|
141 |
!
|
|
142 |
|
|
143 |
skipChunk
|
|
144 |
"skip a chunk"
|
|
145 |
|
|
146 |
|sz|
|
|
147 |
|
|
148 |
'skipChunk' infoPrint.
|
|
149 |
|
|
150 |
sz := chunkSize.
|
|
151 |
(sz bitTest:1) ifTrue:[
|
|
152 |
sz := sz + 1
|
|
153 |
].
|
|
154 |
|
|
155 |
inStream skip:sz.
|
|
156 |
|
|
157 |
"
|
|
158 |
AVIReader fromFile:'/home2/pd_stuff/movies/avi/hangldm.avi'
|
|
159 |
"
|
|
160 |
|
|
161 |
"Created: 5.4.1997 / 14:13:43 / cg"
|
|
162 |
"Modified: 5.4.1997 / 16:12:16 / cg"
|
|
163 |
! !
|
|
164 |
|
|
165 |
!RIFFReader class methodsFor:'documentation'!
|
|
166 |
|
|
167 |
version
|
|
168 |
^ '$Header: /cvs/stx/stx/libview2/RIFFReader.st,v 1.1 1997-04-14 11:59:34 cg Exp $'
|
|
169 |
! !
|
|
170 |
RIFFReader initialize!
|