514
|
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 |
"
|
|
12 |
|
|
13 |
|
510
|
14 |
ImageReader subclass:#FLIReader
|
|
15 |
instanceVariableNames:'frames nframes frameBuffer frameBufferSize imageBuffer redPalette
|
|
16 |
greenPalette bluePalette flags frameDelay'
|
|
17 |
classVariableNames:'FLI_FILE_MAGIC FLC_FILE_MAGIC FLI_FRAME_MAGIC FILE_HEAD_SIZE
|
|
18 |
FRAME_HEAD_SIZE CHUNK_HEAD_SIZE FLI_256_COLOR FLI_DELTA FLI_COLOR
|
|
19 |
FLI_LC FLI_BLACK FLI_BRUN FLI_COPY FLI_MINI MAXCOLORS'
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Graphics-Images-Support'
|
|
22 |
!
|
|
23 |
|
|
24 |
!FLIReader class methodsFor:'documentation'!
|
|
25 |
|
514
|
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 |
!
|
|
40 |
|
510
|
41 |
documentation
|
|
42 |
"
|
|
43 |
Read frames from a FLI/FLC file.
|
|
44 |
|
|
45 |
this is a very first attempt in reading FLI files;
|
|
46 |
its very experimental and may change.
|
|
47 |
(will introduce a new class hierarchy based upon
|
|
48 |
MovieReader ...).
|
|
49 |
|
|
50 |
When used like an imageReader, #fromFile: will return
|
|
51 |
the very first frame.
|
|
52 |
|
511
|
53 |
Warning: right now, the complete movie is read and huge
|
|
54 |
amounts of memoru are allocated. The interface will be changed
|
|
55 |
to allow stream operation ...
|
|
56 |
|
510
|
57 |
[author:]
|
|
58 |
Claus Gittinger
|
|
59 |
|
|
60 |
[see also:]
|
|
61 |
ImageReader
|
|
62 |
"
|
|
63 |
!
|
|
64 |
|
|
65 |
examples
|
|
66 |
"
|
|
67 |
|reader film view tNext|
|
|
68 |
|
|
69 |
reader := FLIReader readFile:'/usr/local/FLI/jeffmild.fli'.
|
|
70 |
reader isNil ifTrue:[^ nil].
|
|
71 |
film := reader images.
|
|
72 |
view := StandardSystemView extent:(film first extent).
|
|
73 |
view openAndWait.
|
|
74 |
|
|
75 |
tNext := Time millisecondClockValue + (reader frameDelay).
|
|
76 |
film do:[:frame |
|
|
77 |
frame displayOn:view x:0 y:0.
|
|
78 |
(Delay untilMilliseconds:tNext) wait.
|
|
79 |
tNext := tNext + (reader frameDelay).
|
|
80 |
].
|
|
81 |
"
|
|
82 |
! !
|
|
83 |
|
|
84 |
!FLIReader class methodsFor:'class initialization'!
|
|
85 |
|
|
86 |
initialize
|
|
87 |
FLI_FILE_MAGIC := 16rAF11.
|
|
88 |
FLC_FILE_MAGIC := 16rAF12.
|
|
89 |
|
|
90 |
FLI_FRAME_MAGIC := 16rF1FA.
|
|
91 |
|
|
92 |
FILE_HEAD_SIZE := 128.
|
|
93 |
FRAME_HEAD_SIZE := 16.
|
|
94 |
CHUNK_HEAD_SIZE := 6.
|
|
95 |
|
|
96 |
FLI_256_COLOR := 4.
|
|
97 |
FLI_DELTA := 7.
|
|
98 |
FLI_COLOR := 11.
|
|
99 |
FLI_LC := 12.
|
|
100 |
FLI_BLACK := 13.
|
|
101 |
FLI_BRUN := 15.
|
|
102 |
FLI_COPY := 16.
|
|
103 |
FLI_MINI := 18.
|
|
104 |
|
|
105 |
MAXCOLORS := 256.
|
|
106 |
|
|
107 |
"
|
|
108 |
FLIReader initialize
|
|
109 |
"
|
|
110 |
|
|
111 |
"Modified: 4.4.1997 / 22:19:45 / cg"
|
|
112 |
! !
|
|
113 |
|
|
114 |
!FLIReader class methodsFor:'testing'!
|
|
115 |
|
|
116 |
isValidImageFile:aFileName
|
|
117 |
"return true, if aFileName contains an FLI/FLC-movie"
|
|
118 |
|
|
119 |
|header n inStream len type|
|
|
120 |
|
|
121 |
inStream := self streamReadingFile:aFileName.
|
|
122 |
inStream isNil ifTrue:[^ false].
|
|
123 |
|
|
124 |
header := ByteArray new:FILE_HEAD_SIZE.
|
|
125 |
n := inStream nextBytes:FILE_HEAD_SIZE into:header.
|
|
126 |
inStream close.
|
|
127 |
n ~~ FILE_HEAD_SIZE ifTrue:[^ false].
|
|
128 |
|
|
129 |
len := header doubleWordAt:(1+0).
|
|
130 |
type := header wordAt:(1+4).
|
|
131 |
|
|
132 |
type ~~ FLI_FILE_MAGIC ifTrue:[
|
|
133 |
type ~~ FLC_FILE_MAGIC ifTrue:[
|
|
134 |
^ false
|
|
135 |
]
|
|
136 |
].
|
|
137 |
^ true
|
|
138 |
|
|
139 |
"
|
|
140 |
FLIReader isValidImageFile:'bitmaps/magtape.xpm'
|
|
141 |
FLIReader isValidImageFile:'/usr/local/FLI/jeffmild.fli'
|
|
142 |
"
|
|
143 |
|
|
144 |
"Modified: 4.4.1997 / 22:30:19 / cg"
|
|
145 |
! !
|
|
146 |
|
|
147 |
!FLIReader methodsFor:'accessing'!
|
|
148 |
|
|
149 |
frameDelay
|
|
150 |
"return the value of the instance variable 'frameDelay' (automatically generated)"
|
|
151 |
|
|
152 |
^ frameDelay
|
|
153 |
|
|
154 |
"Created: 4.4.1997 / 21:59:02 / cg"
|
|
155 |
!
|
|
156 |
|
|
157 |
hasMultipleImages
|
|
158 |
^ frames size > 1
|
|
159 |
|
|
160 |
"Created: 4.4.1997 / 21:39:25 / cg"
|
|
161 |
"Modified: 4.4.1997 / 21:42:59 / cg"
|
|
162 |
!
|
|
163 |
|
|
164 |
images
|
|
165 |
"return a collection of all images as represented by myself"
|
|
166 |
|
|
167 |
|images image depth|
|
|
168 |
|
|
169 |
depth := self bitsPerPixel.
|
|
170 |
|
|
171 |
images := OrderedCollection new.
|
|
172 |
frames do:[:aFrame |
|
|
173 |
image := (Image implementorForDepth:depth) new.
|
|
174 |
image
|
|
175 |
width:width
|
|
176 |
height:height
|
|
177 |
photometric:photometric
|
|
178 |
samplesPerPixel:samplesPerPixel
|
|
179 |
bitsPerSample:bitsPerSample
|
|
180 |
colorMap:colorMap
|
|
181 |
bits:aFrame
|
|
182 |
mask:mask.
|
|
183 |
images add:image.
|
|
184 |
].
|
|
185 |
^ images
|
|
186 |
|
|
187 |
"Modified: 20.6.1996 / 17:09:04 / cg"
|
|
188 |
"Created: 4.4.1997 / 21:44:44 / cg"
|
|
189 |
! !
|
|
190 |
|
|
191 |
!FLIReader methodsFor:'processing chunks'!
|
|
192 |
|
|
193 |
brunChunkAt:chunkOffs
|
|
194 |
|offs lineIdx nextLineIdx packets sz|
|
|
195 |
|
512
|
196 |
"/ 'brunChunkAt' infoPrintCR.
|
510
|
197 |
|
|
198 |
imageBuffer := ByteArray uninitializedNew:(width*height).
|
|
199 |
|
|
200 |
offs := chunkOffs.
|
|
201 |
lineIdx := 1.
|
|
202 |
1 to:height do:[:y |
|
|
203 |
nextLineIdx := lineIdx + width.
|
|
204 |
|
|
205 |
packets := frameBuffer byteAt:offs. offs := offs + 1.
|
|
206 |
|
|
207 |
1 to:packets do:[:p |
|
|
208 |
sz := frameBuffer signedByteAt:offs. offs := offs + 1.
|
|
209 |
sz > 0 ifTrue:[
|
|
210 |
data := frameBuffer at:offs. offs := offs + 1.
|
|
211 |
imageBuffer from:lineIdx to:(lineIdx+sz-1) put:data.
|
|
212 |
] ifFalse:[
|
|
213 |
sz == 0 ifTrue:[
|
|
214 |
self halt:'error in brun chunk'.
|
|
215 |
^ self.
|
|
216 |
].
|
|
217 |
sz := sz negated.
|
|
218 |
imageBuffer replaceFrom:lineIdx to:(lineIdx+sz-1)
|
|
219 |
with:frameBuffer startingAt:offs.
|
|
220 |
offs := offs + sz.
|
|
221 |
].
|
|
222 |
lineIdx := lineIdx + sz.
|
|
223 |
].
|
|
224 |
lineIdx := nextLineIdx
|
|
225 |
].
|
|
226 |
|
|
227 |
frames add:imageBuffer.
|
|
228 |
|
|
229 |
"
|
|
230 |
FLIReader imagesFromFile:'/usr/local/FLI/jeffmild.fli'
|
|
231 |
"
|
|
232 |
|
512
|
233 |
"Modified: 4.4.1997 / 22:45:37 / cg"
|
510
|
234 |
!
|
|
235 |
|
|
236 |
color256ChunkAt:chunkOffs
|
512
|
237 |
"/ 'color256Chunk' infoPrintCR.
|
510
|
238 |
self colorChunkAt:chunkOffs shift:0
|
|
239 |
|
512
|
240 |
"Modified: 4.4.1997 / 22:45:42 / cg"
|
510
|
241 |
!
|
|
242 |
|
|
243 |
color64ChunkAt:chunkOffs
|
512
|
244 |
"/ 'color64Chunk' infoPrintCR.
|
510
|
245 |
self colorChunkAt:chunkOffs shift:2
|
|
246 |
|
512
|
247 |
"Modified: 4.4.1997 / 22:45:45 / cg"
|
510
|
248 |
!
|
|
249 |
|
|
250 |
colorChunkAt:chunkOffs shift:colorShift
|
|
251 |
|b0 b1 packets offs ic skip change red green blue|
|
|
252 |
|
512
|
253 |
"/ ' colorChunk' infoPrintCR.
|
510
|
254 |
|
|
255 |
offs := chunkOffs.
|
|
256 |
packets := frameBuffer wordAt:offs. offs := offs + 2.
|
|
257 |
|
|
258 |
ic := 0.
|
|
259 |
1 to:packets do:[:i |
|
|
260 |
skip := frameBuffer byteAt:offs. offs := offs + 1.
|
|
261 |
ic := ic + skip.
|
|
262 |
ic := ic \\ MAXCOLORS.
|
|
263 |
change := frameBuffer byteAt:offs. offs := offs + 1.
|
|
264 |
change == 0 ifTrue:[change := 256].
|
|
265 |
|
|
266 |
1 to:change do:[:n |
|
|
267 |
red := frameBuffer at:offs. offs := offs + 1.
|
|
268 |
green := frameBuffer at:offs. offs := offs + 1.
|
|
269 |
blue := frameBuffer at:offs. offs := offs + 1.
|
|
270 |
red := red bitShift:colorShift.
|
|
271 |
green := green bitShift:colorShift.
|
|
272 |
blue := blue bitShift:colorShift.
|
|
273 |
"/ red print. ' ' print. green print. ' ' print. blue printCR.
|
|
274 |
|
|
275 |
redPalette at:(ic + 1) put:red.
|
|
276 |
greenPalette at:(ic + 1) put:green.
|
|
277 |
bluePalette at:(ic + 1) put:blue.
|
|
278 |
ic := ic + 1.
|
|
279 |
]
|
|
280 |
].
|
|
281 |
|
|
282 |
"
|
|
283 |
FLIReader fromFile:'/usr/local/FLI/jeffmild.fli'
|
|
284 |
"
|
|
285 |
|
512
|
286 |
"Modified: 4.4.1997 / 22:45:49 / cg"
|
510
|
287 |
!
|
|
288 |
|
|
289 |
deltaChunkAt:chunkOffs
|
512
|
290 |
"/ 'deltaChunkAt' infoPrintCR.
|
|
291 |
self halt:'not yet implemented'
|
510
|
292 |
|
512
|
293 |
"Modified: 4.4.1997 / 22:46:11 / cg"
|
510
|
294 |
!
|
|
295 |
|
|
296 |
lcChunkAt:chunkOffs
|
|
297 |
|jnext lines lineCnt offs lineIdx packets idx skip sz|
|
|
298 |
|
512
|
299 |
"/ 'lcChunkAt' infoPrintCR.
|
510
|
300 |
|
|
301 |
imageBuffer := imageBuffer copyFrom:1 to:(width*height).
|
|
302 |
|
|
303 |
offs := chunkOffs.
|
|
304 |
|
|
305 |
jnext := frameBuffer wordAt:offs. offs := offs + 2.
|
|
306 |
lines := frameBuffer wordAt:offs. offs := offs + 2.
|
|
307 |
lineCnt := 0.
|
|
308 |
lineIdx := 1.
|
|
309 |
|
|
310 |
0 to:height-1 do:[:row |
|
|
311 |
lineCnt >= lines ifTrue:[
|
|
312 |
frames add:imageBuffer.
|
|
313 |
^ self
|
|
314 |
].
|
|
315 |
|
|
316 |
row < jnext ifFalse:[
|
|
317 |
packets := frameBuffer byteAt:offs. offs := offs + 1.
|
|
318 |
lineCnt := lineCnt + 1.
|
|
319 |
idx := lineIdx.
|
|
320 |
1 to:packets do:[:p |
|
|
321 |
skip := frameBuffer byteAt:offs. offs := offs + 1.
|
|
322 |
idx := idx + skip.
|
|
323 |
sz := frameBuffer signedByteAt:offs. offs := offs + 1.
|
|
324 |
sz > 0 ifTrue:[
|
|
325 |
imageBuffer replaceFrom:idx to:(idx+sz-1)
|
|
326 |
with:frameBuffer startingAt:offs.
|
|
327 |
offs := offs + sz.
|
|
328 |
] ifFalse:[
|
|
329 |
sz < 0 ifTrue:[
|
|
330 |
sz := sz negated.
|
|
331 |
data := frameBuffer at:offs. offs := offs + 1.
|
|
332 |
imageBuffer from:idx to:(idx+sz-1) put:data.
|
|
333 |
]
|
|
334 |
].
|
|
335 |
idx := idx + sz.
|
|
336 |
].
|
|
337 |
].
|
|
338 |
lineIdx := lineIdx + width
|
|
339 |
].
|
|
340 |
frames add:imageBuffer.
|
|
341 |
|
512
|
342 |
"Modified: 4.4.1997 / 22:46:15 / cg"
|
510
|
343 |
!
|
|
344 |
|
|
345 |
processChunks:nchunks size:dataLen
|
|
346 |
"process chunks in a frame"
|
|
347 |
|
|
348 |
|len type offs chunkOffs|
|
|
349 |
|
|
350 |
offs := 1+0.
|
|
351 |
1 to:nchunks do:[:chunkIndex |
|
|
352 |
len := frameBuffer doubleWordAt:(offs+0).
|
|
353 |
type := frameBuffer wordAt:(offs+4).
|
|
354 |
chunkOffs := offs + CHUNK_HEAD_SIZE.
|
|
355 |
|
|
356 |
type == FLI_COLOR ifTrue:[
|
|
357 |
self color64ChunkAt:chunkOffs.
|
|
358 |
] ifFalse:[
|
|
359 |
type == FLI_256_COLOR ifTrue:[
|
|
360 |
self color256ChunkAt:chunkOffs.
|
|
361 |
] ifFalse:[
|
|
362 |
type == FLI_DELTA ifTrue:[
|
|
363 |
self deltaChunkAt:chunkOffs.
|
|
364 |
] ifFalse:[
|
|
365 |
type == FLI_LC ifTrue:[
|
|
366 |
self lcChunkAt:chunkOffs.
|
|
367 |
] ifFalse:[
|
|
368 |
type == FLI_BRUN ifTrue:[
|
|
369 |
self brunChunkAt:chunkOffs.
|
|
370 |
] ifFalse:[
|
|
371 |
'FLI [info]: unknown chunk type: ' infoPrint.
|
|
372 |
type hexPrintString infoPrintCR.
|
|
373 |
^ false.
|
|
374 |
]
|
|
375 |
]
|
|
376 |
]
|
|
377 |
].
|
|
378 |
].
|
|
379 |
offs := offs + len
|
|
380 |
].
|
|
381 |
|
|
382 |
"
|
|
383 |
FLIReader fromFile:'/usr/local/FLI/jeffmild.fli'
|
|
384 |
"
|
|
385 |
|
|
386 |
"Created: 3.4.1997 / 22:28:11 / cg"
|
|
387 |
"Modified: 3.4.1997 / 22:52:38 / cg"
|
|
388 |
! !
|
|
389 |
|
|
390 |
!FLIReader methodsFor:'reading from stream'!
|
|
391 |
|
|
392 |
fromStream:aStream
|
512
|
393 |
"read a FLI-movie from aStream."
|
510
|
394 |
|
|
395 |
inStream := aStream.
|
|
396 |
|
|
397 |
(self getHeader) ifFalse:[^ nil].
|
|
398 |
|
|
399 |
1 to:nframes do:[:frameIndex |
|
|
400 |
self getFrame
|
|
401 |
].
|
|
402 |
|
|
403 |
"/ return the first frame as image
|
|
404 |
|
|
405 |
colorMap := Colormap
|
|
406 |
redVector:redPalette
|
|
407 |
greenVector:greenPalette
|
|
408 |
blueVector:bluePalette.
|
|
409 |
|
|
410 |
photometric := #palette.
|
|
411 |
samplesPerPixel := 1.
|
|
412 |
bitsPerSample := #(8).
|
|
413 |
|
|
414 |
data := frames at:1.
|
|
415 |
|
|
416 |
"
|
|
417 |
FLIReader fromFile:'/usr/local/FLI/jeffmild.fli'
|
|
418 |
"
|
|
419 |
|
512
|
420 |
"Modified: 4.4.1997 / 22:45:32 / cg"
|
510
|
421 |
!
|
|
422 |
|
|
423 |
getFrame
|
|
424 |
"get a single frame"
|
|
425 |
|
|
426 |
|header n len type dataLen nchunks|
|
|
427 |
|
|
428 |
header := ByteArray new:FRAME_HEAD_SIZE.
|
|
429 |
n := inStream nextBytes:FRAME_HEAD_SIZE into:header.
|
|
430 |
n ~~ FRAME_HEAD_SIZE ifTrue:[^ false].
|
|
431 |
|
|
432 |
len := header doubleWordAt:(1+0).
|
|
433 |
type := header wordAt:(1+4).
|
|
434 |
|
|
435 |
type ~~ FLI_FRAME_MAGIC ifTrue:[^ false].
|
|
436 |
|
|
437 |
dataLen := len - FRAME_HEAD_SIZE.
|
|
438 |
dataLen > frameBufferSize ifTrue:[
|
|
439 |
frameBuffer := ByteArray uninitializedNew:dataLen.
|
|
440 |
frameBufferSize := dataLen.
|
|
441 |
].
|
|
442 |
|
|
443 |
n := inStream nextBytes:dataLen into:frameBuffer.
|
|
444 |
n ~~ dataLen ifTrue:[^ false].
|
|
445 |
|
|
446 |
nchunks := header wordAt:(1+6).
|
|
447 |
nchunks == 0 ifTrue:[
|
|
448 |
"/ mhmh - a timing frame; should add a dummy frame
|
|
449 |
^ self.
|
|
450 |
].
|
|
451 |
^ self processChunks:nchunks size:dataLen.
|
|
452 |
|
|
453 |
"
|
|
454 |
FLIReader fromFile:'bitmaps/magtape.xpm'
|
|
455 |
FLIReader fromFile:'/usr/local/FLI/jeffmild.fli'
|
|
456 |
"
|
|
457 |
|
|
458 |
"Created: 3.4.1997 / 22:15:19 / cg"
|
|
459 |
"Modified: 4.4.1997 / 22:18:21 / cg"
|
|
460 |
!
|
|
461 |
|
|
462 |
getHeader
|
512
|
463 |
"read the header; return true, if its valid"
|
510
|
464 |
|
|
465 |
|header n len type speed|
|
|
466 |
|
|
467 |
header := ByteArray new:FILE_HEAD_SIZE.
|
|
468 |
n := inStream nextBytes:FILE_HEAD_SIZE into:header.
|
|
469 |
n ~~ FILE_HEAD_SIZE ifTrue:[^ false].
|
|
470 |
|
|
471 |
len := header doubleWordAt:(1+0).
|
|
472 |
type := header wordAt:(1+4).
|
|
473 |
|
|
474 |
type ~~ FLI_FILE_MAGIC ifTrue:[
|
|
475 |
type ~~ FLC_FILE_MAGIC ifTrue:[
|
|
476 |
^ false
|
|
477 |
]
|
|
478 |
].
|
|
479 |
|
|
480 |
nframes := header wordAt:(1+6).
|
|
481 |
width := header wordAt:(1+8).
|
|
482 |
height := header wordAt:(1+10).
|
|
483 |
|
|
484 |
dimensionCallBack notNil ifTrue:[
|
|
485 |
dimensionCallBack value
|
|
486 |
].
|
|
487 |
flags := header wordAt:(1+14).
|
|
488 |
speed := header wordAt:(1+16).
|
|
489 |
speed <= 0 ifTrue:[
|
|
490 |
speed := 1
|
|
491 |
].
|
|
492 |
"/ FLI uses 1/70th of a second;
|
|
493 |
"/ FLC measures the frameDelay in milliseconds
|
|
494 |
type == FLI_FILE_MAGIC ifTrue:[
|
|
495 |
frameDelay := 1000 * speed // 70
|
|
496 |
] ifFalse:[
|
|
497 |
frameDelay := speed
|
|
498 |
].
|
|
499 |
|
|
500 |
frameBufferSize := width * height.
|
|
501 |
frameBuffer := ByteArray uninitializedNew:frameBufferSize.
|
|
502 |
|
|
503 |
redPalette := ByteArray new:256.
|
|
504 |
greenPalette := ByteArray new:256.
|
|
505 |
bluePalette := ByteArray new:256.
|
|
506 |
|
|
507 |
frames := OrderedCollection new:nframes.
|
|
508 |
|
|
509 |
^ true
|
|
510 |
|
|
511 |
"
|
|
512 |
FLIReader fromFile:'bitmaps/magtape.xpm'
|
|
513 |
FLIReader fromFile:'/usr/local/FLI/jeffmild.fli'
|
|
514 |
"
|
|
515 |
|
|
516 |
"Created: 3.4.1997 / 22:09:12 / cg"
|
512
|
517 |
"Modified: 4.4.1997 / 22:45:20 / cg"
|
510
|
518 |
! !
|
|
519 |
|
|
520 |
!FLIReader class methodsFor:'documentation'!
|
|
521 |
|
|
522 |
version
|
514
|
523 |
^ '$Header: /cvs/stx/stx/libview2/FLIReader.st,v 1.4 1997-04-05 09:27:54 cg Exp $'
|
510
|
524 |
! !
|
|
525 |
FLIReader initialize!
|