176 |
176 |
177 inStream := aStream. |
177 inStream := aStream. |
178 inStream text. |
178 inStream text. |
179 |
179 |
180 inStream next == $P ifFalse:[ |
180 inStream next == $P ifFalse:[ |
181 Image badImageFormatQuerySignal |
181 ^ self fileFormatError:'not PNM format'. |
182 raiseErrorString:'PBMReader [info]: not PNM format'. |
|
183 ^nil |
|
184 ]. |
182 ]. |
185 pnmType := inStream next. |
183 pnmType := inStream next. |
186 |
184 |
187 (pnmType == $1) ifTrue: [ |
185 (pnmType == $1) ifTrue: [ |
188 ^ self readDepth1AsciiPBMStream:aStream |
186 ^ self readDepth1AsciiPBMStream:aStream |
197 ^ self readDepth8PGMStream:aStream |
195 ^ self readDepth8PGMStream:aStream |
198 ]. |
196 ]. |
199 (pnmType == $6) ifTrue: [ |
197 (pnmType == $6) ifTrue: [ |
200 ^ self readDepth24PPMStream:aStream |
198 ^ self readDepth24PPMStream:aStream |
201 ]. |
199 ]. |
202 Image badImageFormatQuerySignal |
200 ^ self fileFormatError:'No recognized PNM file format'. |
203 raiseErrorString:'PBMReader [info]: No recognized PNM file format'. |
|
204 ^ nil |
|
205 |
201 |
206 " |
202 " |
207 PBMReader fromFile:'bitmaps/testimg.ppm' |
203 PBMReader fromFile:'bitmaps/testimg.ppm' |
208 PBMReader fromFile:'../../fileIn/bitmaps/keyboard.pbm' |
204 PBMReader fromFile:'../../fileIn/bitmaps/keyboard.pbm' |
209 PBMReader fromFile:'/home2/cg/ppm2fli_b1-92/jeff.001' |
205 PBMReader fromFile:'/home2/cg/ppm2fli_b1-92/jeff.001' |
210 " |
206 " |
211 |
207 |
212 "Created: / 3.2.1998 / 17:25:34 / cg" |
208 "Created: / 3.2.1998 / 17:25:34 / cg" |
213 "Modified: / 3.2.1998 / 17:31:24 / cg" |
209 "Modified: / 3.2.1998 / 17:56:11 / cg" |
214 ! |
210 ! |
215 |
211 |
216 readDepth1AsciiPBMStream:aStream |
212 readDepth1AsciiPBMStream:aStream |
217 "import portable bitmap ascii (PBM, P1 format); P1 is already read" |
213 "import portable bitmap ascii (PBM, P1 format); P1 is already read" |
218 |
214 |
219 |n bits rowIdx dstIdx bytesPerRow char| |
215 |n bits rowIdx dstIdx bytesPerRow char| |
220 |
216 |
221 self skipPBMJunkOn:aStream. |
217 self skipPBMJunkOn:aStream. |
222 width := Integer readFrom:aStream. |
218 width := Integer readFrom:aStream. |
223 width > 0 ifFalse: [ |
219 width > 0 ifFalse: [ |
224 Image badImageFormatQuerySignal |
220 ^ self fileFormatError:'Invalid width'. |
225 raiseErrorString:'PBMReader [info]: Invalid width'. |
|
226 ^ nil |
|
227 ]. |
221 ]. |
228 |
222 |
229 self skipPBMJunkOn:aStream. |
223 self skipPBMJunkOn:aStream. |
230 height := Integer readFrom:aStream. |
224 height := Integer readFrom:aStream. |
231 height > 0 ifFalse: [ |
225 height > 0 ifFalse: [ |
232 Image badImageFormatQuerySignal |
226 ^ self fileFormatError:'Invalid height'. |
233 raiseErrorString:'PBMReader [info]: Invalid height'. |
|
234 ^ nil |
|
235 ]. |
227 ]. |
236 |
228 |
237 aStream nextLine "skipThrough: Character cr". |
229 aStream nextLine "skipThrough: Character cr". |
238 |
230 |
239 bytesPerRow := (width + 7) // 8. |
231 bytesPerRow := (width + 7) // 8. |
269 photometric := #whiteIs0. |
261 photometric := #whiteIs0. |
270 samplesPerPixel := 1. |
262 samplesPerPixel := 1. |
271 bitsPerSample := #(1). |
263 bitsPerSample := #(1). |
272 |
264 |
273 "Created: / 3.2.1998 / 17:21:22 / cg" |
265 "Created: / 3.2.1998 / 17:21:22 / cg" |
274 "Modified: / 3.2.1998 / 17:32:07 / cg" |
266 "Modified: / 3.2.1998 / 17:56:32 / cg" |
275 ! |
267 ! |
276 |
268 |
277 readDepth1PBMStream:aStream |
269 readDepth1PBMStream:aStream |
278 "import portable bitmap (PBM, P4 format); P4 is already read" |
270 "import portable bitmap (PBM, P4 format); P4 is already read" |
279 |
271 |
280 |bytesPerRow| |
272 |bytesPerRow| |
281 |
273 |
282 self skipPBMJunkOn:aStream. |
274 self skipPBMJunkOn:aStream. |
283 width := Integer readFrom:aStream onError:0. |
275 width := Integer readFrom:aStream onError:0. |
284 width > 0 ifFalse: [ |
276 width > 0 ifFalse: [ |
285 Image badImageFormatQuerySignal |
277 ^ self fileFormatError:'Invalid width'. |
286 raiseErrorString:'PBMReader [info]: Invalid width'. |
|
287 ^ nil |
|
288 ]. |
278 ]. |
289 |
279 |
290 self skipPBMJunkOn:aStream. |
280 self skipPBMJunkOn:aStream. |
291 height := Integer readFrom:aStream onError:0. |
281 height := Integer readFrom:aStream onError:0. |
292 height > 0 ifFalse: [ |
282 height > 0 ifFalse: [ |
293 Image badImageFormatQuerySignal |
283 ^ self fileFormatError:'Invalid height'. |
294 raiseErrorString:'PBMReader [info]: Invalid height'. |
|
295 ^ nil |
|
296 ]. |
284 ]. |
297 |
285 |
298 aStream nextLine "skipThrough: Character cr". |
286 aStream nextLine "skipThrough: Character cr". |
299 |
287 |
300 bytesPerRow := width // 8. |
288 bytesPerRow := width // 8. |
310 photometric := #blackIs0. |
298 photometric := #blackIs0. |
311 samplesPerPixel := 1. |
299 samplesPerPixel := 1. |
312 bitsPerSample := #(1). |
300 bitsPerSample := #(1). |
313 |
301 |
314 "Created: / 3.2.1998 / 17:21:37 / cg" |
302 "Created: / 3.2.1998 / 17:21:37 / cg" |
315 "Modified: / 3.2.1998 / 17:32:24 / cg" |
303 "Modified: / 3.2.1998 / 17:56:59 / cg" |
316 ! |
304 ! |
317 |
305 |
318 readDepth24AsciiPBMStream:aStream |
306 readDepth24AsciiPBMStream:aStream |
319 "import ascii portable pixmap (PBM, P3 format); P3 is already read" |
307 "import ascii portable pixmap (PBM, P3 format); P3 is already read" |
320 |
308 |
324 c| |
312 c| |
325 |
313 |
326 self skipPBMJunkOn:aStream. |
314 self skipPBMJunkOn:aStream. |
327 width := Integer readFrom:aStream. |
315 width := Integer readFrom:aStream. |
328 width > 0 ifFalse: [ |
316 width > 0 ifFalse: [ |
329 Image badImageFormatQuerySignal |
317 ^ self fileFormatError:'Invalid width'. |
330 raiseErrorString:'PBMReader [info]: Invalid width'. |
|
331 ^ nil |
|
332 ]. |
318 ]. |
333 |
319 |
334 self skipPBMJunkOn:aStream. |
320 self skipPBMJunkOn:aStream. |
335 height := Integer readFrom:aStream. |
321 height := Integer readFrom:aStream. |
336 height > 0 ifFalse: [ |
322 height > 0 ifFalse: [ |
337 Image badImageFormatQuerySignal |
323 ^ self fileFormatError:'Invalid height'. |
338 raiseErrorString:'PBMReader [info]: Invalid height'. |
|
339 ^ nil |
|
340 ]. |
324 ]. |
341 |
325 |
342 self skipPBMJunkOn:aStream. |
326 self skipPBMJunkOn:aStream. |
343 maxval := Integer readFrom:aStream. |
327 maxval := Integer readFrom:aStream. |
344 maxval >= 256 ifTrue: [ |
328 maxval >= 256 ifTrue: [ |
345 Image badImageFormatQuerySignal |
329 ^ self fileFormatError:'Invalid format'. |
346 raiseErrorString:'PBMReader [info]: format error'. |
|
347 ^ nil |
|
348 ]. |
330 ]. |
349 |
331 |
350 aStream skipThrough: Character cr. |
332 aStream skipThrough: Character cr. |
351 |
333 |
352 nBytes := width*height*3. |
334 nBytes := width*height*3. |
365 photometric := #rgb. |
347 photometric := #rgb. |
366 samplesPerPixel := 3. |
348 samplesPerPixel := 3. |
367 bitsPerSample := #(8 8 8). |
349 bitsPerSample := #(8 8 8). |
368 |
350 |
369 "Created: / 3.2.1998 / 17:21:55 / cg" |
351 "Created: / 3.2.1998 / 17:21:55 / cg" |
370 "Modified: / 3.2.1998 / 17:32:48 / cg" |
352 "Modified: / 3.2.1998 / 17:57:30 / cg" |
371 ! |
353 ! |
372 |
354 |
373 readDepth24PPMStream:aStream |
355 readDepth24PPMStream:aStream |
374 "import portable pixmap (PPM, P6 format); P6 is already read" |
356 "import portable pixmap (PPM, P6 format); P6 is already read" |
375 |
357 |
376 | maxval | |
358 | maxval | |
377 |
359 |
378 self skipPBMJunkOn:aStream. |
360 self skipPBMJunkOn:aStream. |
379 width := Integer readFrom:aStream. |
361 width := Integer readFrom:aStream. |
380 width > 0 ifFalse: [ |
362 width > 0 ifFalse: [ |
381 Image badImageFormatQuerySignal |
363 ^ self fileFormatError:'Invalid width'. |
382 raiseErrorString:'PBMReader [info]: Invalid width'. |
|
383 ^ nil |
|
384 ]. |
364 ]. |
385 |
365 |
386 self skipPBMJunkOn:aStream. |
366 self skipPBMJunkOn:aStream. |
387 height := Integer readFrom:aStream. |
367 height := Integer readFrom:aStream. |
388 height > 0 ifFalse: [ |
368 height > 0 ifFalse: [ |
389 Image badImageFormatQuerySignal |
369 ^ self fileFormatError:'Invalid height'. |
390 raiseErrorString:'PBMReader [info]: Invalid height'. |
|
391 ^ nil |
|
392 ]. |
370 ]. |
393 |
371 |
394 self skipPBMJunkOn:aStream. |
372 self skipPBMJunkOn:aStream. |
395 maxval := Integer readFrom:aStream. |
373 maxval := Integer readFrom:aStream. |
396 maxval >= 256 ifTrue: [ |
374 maxval >= 256 ifTrue: [ |
397 Image badImageFormatQuerySignal |
375 ^ self fileFormatError:'Invalid format'. |
398 raiseErrorString:'PBMReader [info]: format error'. |
|
399 ^ nil |
|
400 ]. |
376 ]. |
401 |
377 |
402 aStream skipThrough: Character cr. |
378 aStream skipThrough: Character cr. |
403 |
379 |
404 "/ the rest is the binary image data ... |
380 "/ the rest is the binary image data ... |
409 photometric := #rgb. |
385 photometric := #rgb. |
410 samplesPerPixel := 3. |
386 samplesPerPixel := 3. |
411 bitsPerSample := #(8 8 8). |
387 bitsPerSample := #(8 8 8). |
412 |
388 |
413 "Created: / 3.2.1998 / 17:22:18 / cg" |
389 "Created: / 3.2.1998 / 17:22:18 / cg" |
414 "Modified: / 3.2.1998 / 17:33:10 / cg" |
390 "Modified: / 3.2.1998 / 17:57:26 / cg" |
415 ! |
391 ! |
416 |
392 |
417 readDepth8PGMStream:aStream |
393 readDepth8PGMStream:aStream |
418 "import portable gray map (PGM, P5 format); P5 is already read" |
394 "import portable gray map (PGM, P5 format); P5 is already read" |
419 |
395 |
420 |maxval| |
396 |maxval| |
421 |
397 |
422 self skipPBMJunkOn:aStream. |
398 self skipPBMJunkOn:aStream. |
423 width := Integer readFrom:aStream. |
399 width := Integer readFrom:aStream. |
424 width > 0 ifFalse:[ |
400 width > 0 ifFalse:[ |
425 Image badImageFormatQuerySignal |
401 ^ self fileFormatError:'Invalid width'. |
426 raiseErrorString:'PBMReader [info]: Invalid width'. |
|
427 ^ nil |
|
428 ]. |
402 ]. |
429 self skipPBMJunkOn:aStream. |
403 self skipPBMJunkOn:aStream. |
430 height := Integer readFrom:aStream. |
404 height := Integer readFrom:aStream. |
431 height > 0 ifFalse:[ |
405 height > 0 ifFalse:[ |
432 Image badImageFormatQuerySignal |
406 ^ self fileFormatError:'Invalid height'. |
433 raiseErrorString:'PBMReader [info]: Invalid height'. |
|
434 ^ nil |
|
435 ]. |
407 ]. |
436 self skipPBMJunkOn:aStream. |
408 self skipPBMJunkOn:aStream. |
437 maxval := Integer readFrom:aStream. |
409 maxval := Integer readFrom:aStream. |
438 maxval >= 256 ifTrue:[ |
410 maxval >= 256 ifTrue:[ |
439 Image badImageFormatQuerySignal |
411 ^ self fileFormatError:'Invalid format'. |
440 raiseErrorString:'PBMReader [info]: Invalid format'. |
|
441 ^ nil |
|
442 ]. |
412 ]. |
443 aStream nextLine "skipThrough: Character cr". |
413 aStream nextLine "skipThrough: Character cr". |
444 |
414 |
445 "/ the rest is the binary image data ... |
415 "/ the rest is the binary image data ... |
446 aStream binary. |
416 aStream binary. |
449 |
419 |
450 photometric := #blackIs0. |
420 photometric := #blackIs0. |
451 samplesPerPixel := 1. |
421 samplesPerPixel := 1. |
452 bitsPerSample := #(8). |
422 bitsPerSample := #(8). |
453 |
423 |
454 "Modified: / 3.2.1998 / 17:33:29 / cg" |
424 "Modified: / 3.2.1998 / 17:57:21 / cg" |
455 ! ! |
425 ! ! |
456 |
426 |
457 !PBMReader methodsFor:'writing to file'! |
427 !PBMReader methodsFor:'writing to file'! |
458 |
428 |
459 save:image onFile:aFileName |
429 save:image onFile:aFileName |