--- a/JPEGReader.st Sat Feb 27 23:38:02 2016 +0100
+++ b/JPEGReader.st Wed Mar 02 14:14:03 2016 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
@@ -19,7 +17,7 @@
instanceVariableNames:'jpeg_decompress_struct jpeg_compress_struct jpeg_error_mgr_struct
colorComponents forceGrayscale forceDitherMode app1SegmentHandler
compressQuality bytesPerRow'
- classVariableNames:'ErrorPrinting'
+ classVariableNames:'ErrorPrinting DefaultCompressQuality'
poolDictionaries:''
category:'Graphics-Images-Readers'
!
@@ -272,7 +270,11 @@
!JPEGReader class methodsFor:'defaults'!
defaultCompressQuality
- ^ 85
+ ^ DefaultCompressQuality ? 85
+!
+
+defaultCompressQuality:percent
+ DefaultCompressQuality := percent.
! !
!JPEGReader class methodsFor:'testing'!
@@ -907,31 +909,27 @@
%}
!
+save:anImage onFile:fileName
+ anImage depth ~~ 24 ifTrue:[
+ Error handle:[:ex |
+ ^ Image cannotRepresentImageSignal
+ raiseWith:anImage
+ errorString:('failed to convert image to depth24: ', ex description).
+ "/ ex return.
+ ] do:[
+ ^ self save:(Depth24Image fromImage:anImage) onFile:fileName
+ ].
+ ].
+ ^ super save:anImage onFile:fileName.
+!
+
save:image onStream:aStream
"save image in JPG-file-format onto aStream"
- self save:image onStream:aStream compressQuality:(self class defaultCompressQuality)
-
- "
- |i i24 i2|
-
- i := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
- i24 := Depth24Image fromImage:i.
- JPEGReader save:i24 onFile:'test.jpg'.
- i2 := Image fromFile:'test.jpg'.
- i2 inspect
- "
-
- "Modified (comment): / 18-02-2016 / 02:36:44 / cg"
-!
-
-save:image onStream:aStream compressQuality:qualityInPercent
- "save image in JPG-file-format onto aStream"
-
image depth ~~ 24 ifTrue:[
- ^ Image cannotRepresentImageSignal
- raiseWith:image
- errorString:('JPG (currently) only supports depth24 images').
+ ^ Image cannotRepresentImageSignal
+ raiseWith:image
+ errorString:('JPG (currently) only supports depth24 images').
].
outStream := aStream.
@@ -950,10 +948,12 @@
colorMap := image colorMap.
bytesPerRow := image bytesPerRow.
data := image bits.
- compressQuality := qualityInPercent.
+ compressQuality isNil ifTrue:[
+ compressQuality := self class defaultCompressQuality.
+ ].
(self create_jpeg_compress_struct not) ifTrue:[
- self errir:'JPG: setup error'.
+ self error:'JPG: setup error'.
].
self compressScanlines.