eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Depth32FloatImage':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Depth32FloatImage


Inheritance:

   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

Description:


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.

copyright

COPYRIGHT (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.

Class protocol:

private helpers
o  pixelArrayNewByteSize: numBytes
given a number of bytes,
return a Float32 array which can be used as pixel storage

o  pixelArrayWithAll: anArray
given an array with pixel values (each in 0..1),
return a Float32 array which can be used as pixel storage

queries
o  defaultPhotometric
return the default photometric pixel interpretation

o  imageDepth
return the depth of images represented by instances of
this class - here we return 32


Instance protocol:

accessing-pixels
o  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

o  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.

o  colorFromValue: pixelValue
given a pixel value, return the corresponding color.
Pixel values are 0..1

o  depth: d
set the depth of the image.

Usage example(s):

super depth:d.

o  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

o  pixelAtX: x y: y put: aPixelValue
set the pixel at x/y to aPixelValue (a float in 0..1).

o  rowAt: y putAll: pixelArray startingAt: startIndex
store a single rows bits from bits in the pixelArray argument.
Notice: row coordinate starts at 0.

o  valueFromColor: aColor
get a color's pixel value.

o  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
o  computeAlphaValuesFromMask: aMaskImage
convert a mask into alpha values;
masked pixels get an alpha value of 0, unmasked of 255

o  grayImageAsTrueColorFormOn: aDevice
return a true-color device-form for the receiver.
TODO: the pixel loops ought to be implemented as inline primitive code ...

initialization
o  createPixelStore
instantiate the underlying pixel storage (a floatArray)

o  initialize

queries
o  alphaBitsOf: pixel
given a pixel-value, return the alpha component as byteValue (0..255)

o  alphaComponentOf: pixel
given a pixel-value, return the alpha component in percent (0..100)

o  alphaMaskForPixelValue
return the mask used with translation from pixelValues to alphaBits.
Determines the number of bits of alpha

o  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.

o  bitsPerPixel
return the number of bits per pixel

o  bitsPerRow
return the number of bits in one scanline of the image

o  bitsPerSample
return the number of bits per sample.
The return value is an array of bits-per-plane.

o  bytesPerRow
return the number of bytes in one scanline of the image

o  hasAlphaChannel
could be #rgb in 32 bits...

o  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

o  samplesPerPixel
return the number of samples per pixel in the image.


Examples:


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.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 08 Sep 2024 00:42:37 GMT