#FEATURE
authorClaus Gittinger <cg@exept.de>
Wed, 02 Mar 2016 14:13:50 +0100
changeset 7172 6d903c0407fa
parent 7167 12b5d9ffc66c
child 7173 075306bcac68
#FEATURE class: ImageReader added: #compressQuality: #save:onFile:quality: #save:onStream:quality: comment/format in: #documentation #save:onFile: #save:onStream:
ImageReader.st
--- a/ImageReader.st	Sat Feb 27 23:27:56 2016 +0100
+++ b/ImageReader.st	Wed Mar 02 14:13:50 2016 +0100
@@ -913,18 +913,20 @@
 
 documentation
 "
-    Abstract class to provide common functions for image-readers
-    (i.e. TIFFReader, GIFReader etc.). In contrast to what the name suggests,
-    ImageReaders are suposed to support both reading and writing of images
+    Abstract class to provide common functions for image-readers/writers.
+    (i.e. TIFFReader, GIFReader etc.).
+    
+    In contrast to what the name suggests, ImageReaders are supposed to support 
+    both reading and writing of images
     (i.e. the name is somewhat outdated, but kept for historic and backward
-    compatibility reasons). They provide functionality similar to Squeak's
-    ImageReaderWriter classes.
+    compatibility reasons). 
+    They provide functionality similar to Squeak's ImageReaderWriter classes.
 
     ImageReaders are created temporary to read an image from a stream.
     Normally, they are not directly used - instead, the image class is
     asked to read some file, and return an instance for it:
-	Image fromFile:<someFileName>
-    The Image class will guess the images format and forward the task to
+        Image fromFile:<someFileName>
+    The Image class will guess the image's format and forward the task to
     some concrete ImageReaderClass.
     If that class thinks, that the file's format is incorrect,
     other readers are tried until some reader class finds the file's format acceptable.
@@ -935,9 +937,9 @@
 
     See the implementation of #fromStream: in concrete subclasses.
     The public interfaces are:
-	 <ConcreteReaderClass> fromFile:aFilename
+         <ConcreteReaderClass> fromFile:aFilename
     or:
-	 <ConcreteReaderClass> fromStream:aStream
+         <ConcreteReaderClass> fromStream:aStream
 
     If you add a new reader, don't forget to add the method #isValidImageFile:
     which should return true, if this reader supports reading a given file.
@@ -945,11 +947,15 @@
     If your new reader class supports writing files, don't forget to add
     #canRepresent:anImage and return true from this method.
 
+    writing:
+        tell the image, to save itself, via <image> saveOn:fileName
+        or <image> saveOn:fileName using:<readerClass>
+        
     [See also:]
-	Image Icon Form
+        Image Icon Form
 
     [author:]
-	Claus Gittinger
+        Claus Gittinger
 "
 ! !
 
@@ -1629,12 +1635,32 @@
     "Modified: 10.4.1997 / 17:42:57 / cg"
 !
 
+save:anImage onFile:aFileName quality:qualityPercent
+    "save the image in my format on aFileName.
+     qualityPercent is ignored by all lossless formats.
+     JPG does care for it."
+
+    ^ (self basicNew) save:anImage onFile:aFileName quality:qualityPercent
+
+    "Modified: 10.4.1997 / 17:42:57 / cg"
+!
+
 save:anImage onStream:aStream
     "save the image in my format on a Stream"
 
     ^ (self basicNew) save:anImage onStream:aStream
 
     "Modified: 10.4.1997 / 17:42:57 / cg"
+!
+
+save:anImage onStream:aStream quality:qualityPercent
+    "save the image in my format on a Stream.
+     qualityPercent is ignored by all lossless formats.
+     JPG does care for it."
+
+    ^ (self basicNew) save:anImage onStream:aStream quality:qualityPercent
+
+    "Modified: 10.4.1997 / 17:42:57 / cg"
 ! !
 
 !ImageReader class methodsFor:'testing'!
@@ -1702,6 +1728,10 @@
     "Modified: 22.4.1996 / 19:15:24 / cg"
 !
 
+compressQuality:qualityPercentIgnoredHere
+    "/ intentionally ignored here (redefined in JPEGReader)
+!
+
 data
     "return the raw image data"
 
@@ -1991,18 +2021,33 @@
     "save image in my format on aFile"
 
     self writingFile:aFileName for:image do:[:stream |
-	self save:image onStream:stream.
+        self save:image onStream:stream.
     ].
+!
+
+save:image onFile:aFileName quality:qualityPercentOrNil
+    "save image in my format on aFile"
+
+    self compressQuality:qualityPercentOrNil.
+    self save:image onFile:aFileName
 
     "Modified: / 01-06-2010 / 19:02:17 / cg"
 !
 
 save:image onStream:aStream
-    "save image in my format on a Stream"
+    "save image in my file-format onto aStream"
 
     ^ Image cannotRepresentImageSignal
-	raiseWith:image
-	errorString:('image save not implemented/supported for this format').
+        raiseWith:image
+        errorString:('image save not implemented/supported for this format').
+!
+
+save:image onStream:aStream quality:qualityPercentOrNil
+    "save image in my format on a Stream.
+     QualityPercent is ignored by lossless formats (jpg uses it)"
+
+    self compressQuality:qualityPercentOrNil.
+    self save:image onStream:aStream
 !
 
 saveAll:aCollectionOfImages onFile:aFileName