--- a/Depth16Image.st Thu Jul 11 16:47:03 2019 +0200
+++ b/Depth16Image.st Fri Jul 12 14:49:42 2019 +0200
@@ -204,6 +204,38 @@
"return the number of bytes in one scanline of the image"
^ width * 2.
+!
+
+valueFromRGB:rgb
+ "given a color as rgb-value, with 8 bits per component,
+ return the corresponding pixel value.
+ The red component is in the high 8 bits.
+ Non-representable colors return nil."
+
+ |pixel redBits greenBits blueBits r g b a|
+
+ b := rgb bitAnd:16rFF.
+ g := (rgb bitShift:-8) bitAnd:16rFF.
+ r := (rgb bitShift:-16) bitAnd:16rFF.
+ a := 255.
+
+ photometric == #rgb ifTrue:[
+ samplesPerPixel >= 3 ifTrue:[
+ "/ rrrrrrrrggggggggbbbbbbbb -> rrrrrgggggbbbbb
+ "/ r,g,b r in hi bits, b in low bits
+ redBits := bitsPerSample at:1.
+ greenBits := bitsPerSample at:2.
+ blueBits := bitsPerSample at:3.
+ r := r bitShift:(redBits-8).
+ g := g bitShift:(greenBits-8).
+ b := b bitShift:(blueBits-8).
+ pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
+ ^ pixel
+ ]
+ ].
+ ^ super valueFromRGB:rgb
+
+ "Created: / 12-07-2019 / 14:48:31 / Stefan Reise"
! !
!Depth16Image class methodsFor:'documentation'!