|
Class: Depth32FloatImage
Object
|
+--Image
|
+--Depth32FloatImage
- Package:
- stx:libview
- Category:
- Graphics-Images
- Version:
- rev:
1.7
date: 2023/08/28 09:23:46
- user: cg
- file: Depth32FloatImage.st directory: libview
- module: stx stc-classLibrary: libview
Experimental and unfinished
this class represents 32 bit grayscale images without mask
and with floating point pixel values in [0..1].
This is provided to allow sophisticated image manipulation code
from eg. openCV to process pixel data.
copyrightCOPYRIGHT (c) 2021 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
private helpers
-
pixelArrayNewByteSize: numBytes
-
given a number of bytes,
return a Float32 array which can be used as pixel storage
-
pixelArrayWithAll: anArray
-
given an array with pixel values (each in 0..1),
return a Float32 array which can be used as pixel storage
queries
-
defaultPhotometric
-
return the default photometric pixel interpretation
-
imageDepth
-
return the depth of images represented by instances of
this class - here we return 32
accessing-pixels
-
colorAtX: x y: y
-
retrieve a pixel at x/y; return a (grey) color.
Pixels start at x=0 , y=0 for upper left pixel,
end at x = width-1, y=height-1 for lower right pixel
-
colorAtX: x y: y put: aColor
-
set the pixel at x/y to aColor's brightness.
Pixels start at x=0 , y=0 for upper left pixel, end at
x = width-1, y=height-1 for lower right pixel.
-
colorFromValue: pixelValue
-
given a pixel value, return the corresponding color.
Pixel values are 0..1
-
depth: d
-
set the depth of the image.
Usage example(s):
-
pixelAtX: x y: y
-
retrieve a pixel at x/y; return the pixelValue as float in 0..1.
Pixels start at x=0 , y=0 for upper left pixel, end at
x = width-1, y=height-1 for lower right pixel
-
pixelAtX: x y: y put: aPixelValue
-
set the pixel at x/y to aPixelValue (a float in 0..1).
-
rowAt: y putAll: pixelArray startingAt: startIndex
-
store a single rows bits from bits in the pixelArray argument.
Notice: row coordinate starts at 0.
-
valueFromColor: aColor
-
get a color's pixel value.
-
valueFromRGB: anRGBValue
-
get the pixel value corresponding to an RGB value.
Usage example(s):
self basicNew valueFromRGB:0xFFFFFF
self basicNew valueFromRGB:0
self basicNew valueFromRGB:0x808080
self basicNew valueFromRGB:0x7F7F7F
|
converting rgb images
-
computeAlphaValuesFromMask: aMaskImage
-
convert a mask into alpha values;
masked pixels get an alpha value of 0, unmasked of 255
-
grayImageAsTrueColorFormOn: aDevice
-
return a true-color device-form for the receiver.
TODO: the pixel loops ought to be implemented as inline primitive code ...
initialization
-
createPixelStore
-
instantiate the underlying pixel storage (a floatArray)
-
initialize
-
queries
-
alphaBitsOf: pixel
-
given a pixel-value, return the alpha component as byteValue (0..255)
-
alphaComponentOf: pixel
-
given a pixel-value, return the alpha component in percent (0..100)
-
alphaMaskForPixelValue
-
return the mask used with translation from pixelValues to alphaBits.
Determines the number of bits of alpha
-
alphaShiftForPixelValue
-
return the shift amount used with translation from pixelValues to alphaBits.
That is the number of bits to shift the alpha value into the pixel value.
-
bitsPerPixel
-
return the number of bits per pixel
-
bitsPerRow
-
return the number of bits in one scanline of the image
-
bitsPerSample
-
return the number of bits per sample.
The return value is an array of bits-per-plane.
-
bytesPerRow
-
return the number of bytes in one scanline of the image
-
hasAlphaChannel
-
could be #rgb in 32 bits...
-
rgbFromValue: pixelValue
-
given a pixel value, return the corresponding 24bit rgbValue (rgb, red is MSB).
Usage example(s):
(self basicNew rgbFromValue:0.5) -> 16r808080
(self basicNew rgbFromValue:0) -> 0
(self basicNew rgbFromValue:1.0) -> 16rFFFFFF
|
-
samplesPerPixel
-
return the number of samples per pixel in the image.
inline image:
default: depth=1 & #blackIs0
|img|
img := Depth32FloatImage
width:8 height:8
fromArray:#f32( 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 ).
img edit
|
|img1 img2|
img1 := Image width:4
height:4
photometric:#blackIs0
depth:8
fromArray:#[0xFF 0xFF 0xFF 0xFF
0xFF 0x00 0x00 0xFF
0xFF 0x00 0x00 0xFF
0xFF 0xFF 0xFF 0xFF].
img2 := Depth32FloatImage fromImage:img1.
img2 edit
|
|img1 img2 img3|
img1 := Image fromScreen:(0@0 corner:200@200).
img2 := img1 asGrayImageDepth:8.
img3 := Depth32FloatImage fromImage:img2.
img3 edit.
img3 inspect.
|
|