--- a/Image.st Tue May 07 19:25:07 1996 +0200
+++ b/Image.st Tue May 07 19:28:57 1996 +0200
@@ -312,96 +312,6 @@
^ self width:ext x height:ext y fromArray:bits
!
-fromFile:aFileName
- "read an image from a file - this methods tries to find
- out the file format itself (by the extension and by contents)
- and lets the appropriate reader read the file."
-
- |image name nm inStream suffixLen|
-
- "
- before trying each reader, check if file is readable
- "
- name := aFileName.
- inStream := Smalltalk systemFileStreamFor:name.
- inStream isNil ifTrue:[
- inStream := Smalltalk bitmapFileStreamFor:name.
- inStream isNil ifTrue:[
- ('IMAGE: ' , aFileName , ' does not exist or is not readable') infoPrintNL.
- ^ nil
- ].
- name := 'bitmaps/' , name.
- ].
- inStream close.
-
- "
- get the imageReader class from the files extension
- "
- nm := name.
- (name endsWith:'.Z') ifTrue:[
- suffixLen := 2
- ] ifFalse:[
- (name endsWith:'.gz') ifTrue:[
- suffixLen := 3
- ] ifFalse:[
- suffixLen := 0
- ]
- ].
- suffixLen ~~ 0 ifTrue:[
- nm := name copyWithoutLast:suffixLen
- ].
-
- "
- ask the corresponding readerclass first
- "
- FileFormats keysAndValuesDo:[:suffix :readerClass |
- (nm endsWith:suffix) ifTrue:[
- readerClass notNil ifTrue:[
- image := readerClass fromFile:name.
- image notNil ifTrue:[^ image].
- ]
- ]
- ].
-
- "
- no known extension - ask all readers if they know
- this format ...
- "
- FileFormats do:[:readerClass |
- readerClass notNil ifTrue:[
- (readerClass isValidImageFile:name) ifTrue:[
- ^ readerClass fromFile:name
- ]
- ]
- ].
-
- "
- nope - unknown format
- "
- 'IMAGE: unknown image file format: ' infoPrint. aFileName infoPrintNL.
- ^ nil
-
- "
- Image fromFile:'bitmaps/dano.tiff'
- Image fromFile:'bitmaps/test.fax'
- Image fromFile:'bitmaps/voice.tiff'
- Image fromFile:'voice.tiff'
-
- Image fromFile:'../fileIn/bitmaps/claus.gif'
- Image fromFile:'../fileIn/bitmaps/garfield.gif'
-
- Image fromFile:'../fileIn/bitmaps/founders.im8'
- Image fromFile:'../goodies/faces/next.com/steve.face'
-
- Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'
- Image fromFile:'bitmaps/globe1.xbm'
- Image fromFile:'bitmaps/globe1.xbm.Z'
- Image fromFile:'bitmaps/hello_world.icon'
- "
-
- "Modified: 7.3.1996 / 19:18:13 / cg"
-!
-
fromForm:aForm
"create & return an Image given a form"
@@ -453,8 +363,16 @@
i8 := Depth8Image fromSubImage:i1 in:(0@0 corner:20@20).
i8 inspect
"
+ "
+ |i1 i8|
+
+ i1 := Image fromFile:'bitmaps/claus.gif'.
+ i8 := Depth8Image fromSubImage:i1 in:(70@50 extent:50@50).
+ i8 inspect
+ "
"Created: 20.9.1995 / 01:05:43 / claus"
+ "Modified: 7.5.1996 / 19:28:17 / cg"
!
new
@@ -599,6 +517,98 @@
"
! !
+!Image class methodsFor:'file reading'!
+
+fromFile:aFileName
+ "read an image from a file - this methods tries to find
+ out the file format itself (by the extension and by contents)
+ and lets the appropriate reader read the file."
+
+ |image name nm inStream suffixLen|
+
+ "
+ before trying each reader, check if file is readable
+ "
+ name := aFileName.
+ inStream := Smalltalk systemFileStreamFor:name.
+ inStream isNil ifTrue:[
+ inStream := Smalltalk bitmapFileStreamFor:name.
+ inStream isNil ifTrue:[
+ ('IMAGE: ' , aFileName , ' does not exist or is not readable') infoPrintNL.
+ ^ nil
+ ].
+ name := 'bitmaps/' , name.
+ ].
+ inStream close.
+
+ "
+ get the imageReader class from the files extension
+ "
+ nm := name.
+ (name endsWith:'.Z') ifTrue:[
+ suffixLen := 2
+ ] ifFalse:[
+ (name endsWith:'.gz') ifTrue:[
+ suffixLen := 3
+ ] ifFalse:[
+ suffixLen := 0
+ ]
+ ].
+ suffixLen ~~ 0 ifTrue:[
+ nm := name copyWithoutLast:suffixLen
+ ].
+
+ "
+ ask the corresponding readerclass first
+ "
+ FileFormats keysAndValuesDo:[:suffix :readerClass |
+ (nm endsWith:suffix) ifTrue:[
+ readerClass notNil ifTrue:[
+ image := readerClass fromFile:name.
+ image notNil ifTrue:[^ image].
+ ]
+ ]
+ ].
+
+ "
+ no known extension - ask all readers if they know
+ this format ...
+ "
+ FileFormats do:[:readerClass |
+ readerClass notNil ifTrue:[
+ (readerClass isValidImageFile:name) ifTrue:[
+ ^ readerClass fromFile:name
+ ]
+ ]
+ ].
+
+ "
+ nope - unknown format
+ "
+ 'IMAGE: unknown image file format: ' infoPrint. aFileName infoPrintNL.
+ ^ nil
+
+ "
+ Image fromFile:'bitmaps/dano.tiff'
+ Image fromFile:'bitmaps/test.fax'
+ Image fromFile:'bitmaps/voice.tiff'
+ Image fromFile:'voice.tiff'
+
+ Image fromFile:'../fileIn/bitmaps/claus.gif'
+ Image fromFile:'../fileIn/bitmaps/garfield.gif'
+
+ Image fromFile:'../fileIn/bitmaps/founders.im8'
+ Image fromFile:'../goodies/faces/next.com/steve.face'
+
+ Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'
+ Image fromFile:'bitmaps/globe1.xbm'
+ Image fromFile:'bitmaps/globe1.xbm.Z'
+ Image fromFile:'bitmaps/hello_world.icon'
+ "
+
+ "Modified: 7.3.1996 / 19:18:13 / cg"
+! !
+
!Image class methodsFor:'misc'!
dither:aSymbol
@@ -3570,5 +3580,6 @@
!Image class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.66 1996-05-07 17:25:07 cg Exp $'! !
+ ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.67 1996-05-07 17:28:57 cg Exp $'
+! !
Image initialize!