#FEATURE by cg
class: Image
added: #anyImageAsFormOn:
changed:
#asFormOn:
#paletteImageAsTrueColorFormOn:
--- a/Image.st Thu Aug 24 22:48:04 2017 +0200
+++ b/Image.st Fri Aug 25 11:27:52 2017 +0200
@@ -4128,15 +4128,16 @@
]
].
+ visual := aDevice visualType.
+
(aDevice depth == 1
or:[aDevice hasGrayscales not]) ifTrue:[
form := self asMonochromeFormOn:aDevice.
] ifFalse:[
- ((visual := aDevice visualType) == #StaticGray) ifTrue:[
+ (visual == #StaticGray) ifTrue:[
form := self asGrayFormOn:aDevice.
] ifFalse:[
- (visual == #PseudoColor
- or:[visual == #StaticColor]) ifTrue:[
+ (visual == #PseudoColor or:[visual == #StaticColor]) ifTrue:[
form := self asPseudoFormQuickOn:aDevice.
].
]
@@ -4155,7 +4156,13 @@
(photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
form := self rgbImageAsFormOn:aDevice
] ifFalse:[
- form := self greyImageAsFormOn:aDevice
+ (photometric == #blackIs0 or:[photometric == #whiteIs0]) ifTrue:[
+ form := self rgbImageAsFormOn:aDevice
+ ] ifFalse:[
+ "/ other encodings (cmy, for example)
+ "/ calls a slow fallback (which usually enumerates each pixel)
+ form := self rgbImageAsFormOn:aDevice
+ ]
]
]
].
@@ -4195,7 +4202,7 @@
(i asFormOn:Display) inspect.
"
- "Modified: / 06-06-2007 / 12:18:43 / cg"
+ "Modified: / 25-08-2017 / 09:41:22 / cg"
!
asGrayFormOn:aDevice
@@ -6336,6 +6343,27 @@
!Image methodsFor:'converting greyscale images'!
+anyImageAsFormOn:aDevice
+ "return a (usually truecolor) deviceForm from an arbitrary image."
+
+ |nPlanes|
+
+ nPlanes := samplesPerPixel.
+ (nPlanes == 2) ifTrue:[
+ 'Image [info]: alpha plane ignored' infoPrintCR.
+ ].
+
+ (aDevice visualType == #TrueColor) ifTrue:[
+ ^ self anyImageAsTrueColorFormOn:aDevice
+ ].
+
+ "/ PseudoColor conversion also works, although possibly with suboptimal results
+
+ ^ self anyImageAsPseudoFormOn:aDevice
+
+ "Created: / 25-08-2017 / 09:31:17 / cg"
+!
+
greyImageAsFormOn:aDevice
"return a grey-deviceForm from the grey image."
@@ -6714,24 +6742,15 @@
r := colorMap redByteAt:index.
g := colorMap greenByteAt:index.
b := colorMap blueByteAt:index.
-"/ clr := colorMap at:index.
- true "clr notNil" ifTrue:[
-"/ r := clr red.
-"/ g := clr green.
-"/ b := clr blue.
- rv := (r * scaleRed) rounded.
- gv := (g * scaleGreen) rounded.
- bv := (b * scaleBlue) rounded.
-
- v := rv bitShift:redShift.
- v := v bitOr:(gv bitShift:greenShift).
- v := v bitOr:(bv bitShift:blueShift).
- colorValues at:index put:v.
-"/ clr print. ' ' print.
-"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
-"/ ' -> ' print. v printNL.
-
- ]
+
+ rv := (r * scaleRed) rounded.
+ gv := (g * scaleGreen) rounded.
+ bv := (b * scaleBlue) rounded.
+
+ v := rv bitShift:redShift.
+ v := v bitOr:(gv bitShift:greenShift).
+ v := v bitOr:(bv bitShift:blueShift).
+ colorValues at:index put:v.
].
].
@@ -6799,8 +6818,8 @@
^ form
- "Modified: / 24-07-1998 / 00:56:14 / cg"
"Modified: / 31-01-2017 / 15:01:05 / stefan"
+ "Modified: / 25-08-2017 / 08:54:23 / cg"
! !
!Image methodsFor:'converting rgb images'!