eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Depth24Image':

Home

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

Class: Depth24Image


Inheritance:

   Object
   |
   +--Image
      |
      +--Depth24Image

Package:
stx:libview
Category:
Graphics-Images
Version:
rev: 1.139 date: 2023/08/28 09:22:22
user: cg
file: Depth24Image.st directory: libview
module: stx stc-classLibrary: libview

Description:


this class represents true-color (24 bit / pixel) images.
It mainly consists of methods already implemented in Image,
reimplemented here for more performance.

Only the #rgb format is supported here.

with #rgb, pixels are internally stored byte-wise in rgb order
(i.e. r at low byte, b at high byte).

When reading pixel values, these are returned as rrggbb,
both on LSB and on MSB machines.
(red in high bits of the returned 24bit integer)
Thus, pixelValues and rgbValues are identical, simulating MSB on all
architectures (this should be transparent, if you use the rgbValueAt
accessors; however, some old code uses pixelValueAt:, assuming that the
returned pixel value is rrggbb (which it would not be without this hack).

copyright

COPYRIGHT (c) 1993 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:

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 24


Instance protocol:

accessing-pixels
o  colorAtX: x y: y
retrieve a pixel at x/y; return a 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.
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
retrieve a pixel at x/y;
return a pixel value (0..16rFFFFFF) which is 24 bits RGB.
In theory, the interpretation of the pixel value depends on the photometric,
however as the only one supported here is #rgb, the returned value
is always rrggbb (with r in high bits, b in low 8 bits).
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 a pixel at x/y to aPixelValue, (0..16rFFFFFF) which is 24 bits RGB.
In theory, the interpretation of the pixel value depends on the photometric,
however as the only one supported here is #rgb, the expected value
is always rrggbb (with r in high bits, b in low 8 bits).
Pixels start at x=0 , y=0 for upper left pixel, end at
x = width-1, y=height-1 for lower right pixel

o  rgbValueAtX: x y: y
retrieve a pixel's rgb value at x/y;
return a 24bit rgbValue (rrggbb, red is MSB).
Pixels start at 0@0 for the upper left pixel,
and end at (width-1)@(height-1) for the lower right pixel.

o  rgbValueAtX: x y: y put: rgbValue
store a pixel's rgb value at x/y;
return a 24bit rgbValue (rrggbb, red is MSB).
Pixels start at 0@0 for the upper left pixel,
and end at (width-1)@(height-1) for the lower right pixel.

o  rowAt: y putAll: pixelArray startingAt: startIndex
store a single row's bits from bits in the pixelArray argument;
The interpretation of the pixel values depends on the photometric.
Return the pixelArray.
Notice: row coordinate starts at 0.

converting rgb images
o  asGrayFormOn: aDevice
return a grey form from the receiver.
Redefined to use special code when converting to 8-bit
greyScale displays.

o  asThresholdGrayImageDepth: newDepth
return an 8-bit grey image from the rgb picture.
Pixel values are reduced to a 0..255 grey level.

Usage example(s):

     |i|

     i := Image fromFile:'bitmaps/granite.tiff'.
     (i asThresholdGrayImageDepth:8) inspect.
     (i asThresholdGrayImageDepth:4) inspect.
     (i asThresholdGrayImageDepth:2) inspect.
     (i asThresholdGrayImageDepth:1) inspect.

Usage example(s):

     |i|

     i := Image fromFile:'bitmaps/granite.tiff'.
     ((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:2) inspect

Usage example(s):

     |i|

     i := Image fromFile:'bitmaps/granite.tiff'.
     ((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:4) inspect

Usage example(s):

     |i|

     i := Image fromFile:'bitmaps/granite.tiff'.
     (i asThresholdGrayImageDepth:8) asOrderedDitheredMonochromeImage inspect

o  rgbImageAsDitheredPseudoFormOn: aDevice
return a dithered pseudocolor form from the rgb-picture.
This method depends on fixColors being allocated (see Color>>getColors*)

o  rgbImageAsDitheredPseudoFormOn: aDevice colors: fixColors
return a dithered 8-bit pseudocolor form from the rgb-picture, using
arbitrary fix colors in fixColors.

o  rgbImageAsDitheredPseudoFormOn: aDevice colors: fixColors nRed: nRed nGreen: nGreen nBlue: nBlue
return a dithered pseudocolor form from the rgb-picture,
using colors from a colorCube for dithering.

o  rgbImageAsPseudoFormOn: aDevice
return a pseudocolor form from the rgb-picture.
If a colorCube is used, pass the work on to the cube-dither
code. Otherwise, allocate as many colors as possible, then
use those for dithering.
Could be improved, by searching for (& allocating)
heavily used colors and/or min-max colors first.

o  rgbImageAsTrueColorFormOn: aDevice
return a truecolor form from the rgb-picture.

o  rgbImageBitsOn: aDevice bestFormat: bestFormat
return rgb bits from the rgb-picture.

o  rgbImageBitsOn: aDevice bestFormat: bestFormat returnUsedDevicePattingIn: aValueHolder
return rgb bits from the rgb-picture.
Sorry (sigh) - this might decide to use a different padding;
this information is returned in aValueHolder

dither helpers
o  floydSteinbergDitheredDepth8BitsColors: colors map: aMapOrNil
return a floyd-steinberg dithered bitmap from the receiver picture,
which must be a depth-24 image.
This method expects an array of colors to be used for dithering
(which need not be a colorCubes colors).

o  floydSteinbergDitheredGrayBitsDepth: depth
return the bits for dithering a depth gray bitmap from the image.
Redefined to make use of knowing that pixels are 24 bit r/g/b

o  floydSteinbergDitheredMonochromeBits
return the bitmap for a dithered monochrome bitmap from the image.
Redefined to make use of knowing that pixels are 24 bit r/g/b

o  orderedDitheredGrayBitsWithDitherMatrix: ditherMatrix ditherWidth: dW depth: depth
return the bitmap for a dithered depth-bitmap from the image;
with a constant ditherMatrix, this can be used for thresholding.
Redefined to make use of knowing that pixels are 24-bit values.

o  orderedDitheredMonochromeBitsWithDitherMatrix: ditherMatrix ditherWidth: dW
return the dithered monochrome bits for the receiver image;
with a constant ditherMatrix, this can be used for thresholding.
Redefined to make use of knowing that pixels are 24-bit values.

o  threshold8BitGrayBits
return the bits for an 8-bit grey image from the receiver.
Special code, since this is a common case.

enumerating
o  colorsAtX: x from: yLow to: yHigh do: aBlock
perform aBlock for each pixel from y1 to y2 in col x.
The block is passed the color at each pixel.
This method allows slighly faster processing of an
image than using atX:y:, since some processing can be
avoided when going from pixel to pixel. However, for
real image processing, specialized methods should be written.

o  colorsAtY: y from: xLow to: xHigh do: aBlock
perform aBlock for each pixel from x1 to x2 in row y.
The block is passed the color at each pixel.
This method allows slighly faster processing of an
image than using atX:y:, since some processing can be
avoided when going from pixel to pixel. However, for
real image processing, specialized methods should be written.

o  valuesAtY: y from: xLow to: xHigh do: aBlock
WARNING: this enumerates pixel values which need photometric interpretation
Do not confuse with #rgbValuesAtY:from:to:do:

Perform aBlock for each pixelValue from x1 to x2 in row y.

Notice the difference between rgbValue and pixelValue: rgbValues are always
the rgb bytes; pixelvalues depend on the photometric interpretation, and may be
indices into a colormap or be non-byte-sized rgb values.

The block is passed the pixelValue at each pixel.
This method allows slighly faster processing of an
image than using valueAtX:y:, since some processing can be
avoided when going from pixel to pixel. However, for
real image processing, specialized methods should be written.
Notice that the pixelValue is the r/g/b value packed into an MSB integer
(r bitShift:16) bitOr:(g bitSHift:8) bitOr:b
i.e. r is the first byte, but high in the passed pixel value.

o  valuesFromX: xStart y: yStart toX: xEnd y: yEnd do: aBlock
WARNING: this enumerates pixel values which need photometric interpretation
Do not confuse with #rgbValuesAtY:from:to:do:

Perform aBlock for each pixelValue in a rectangular area of the image.

Notice the difference between rgbValue and pixelValue: rgbValues are always
the rgb bytes; pixelvalues depend on the photometric interpretation, and may be
indices into a colormap or be non-byte-sized rgb values.

The block is passed the pixelValue at each pixel.
This method allows slighly faster processing of an
image than using individual valueAtX:y: accesses,
since some processing can be avoided when going from pixel to pixel..
However, for real high performance image processing, specialized methods
should be written which know how to deal with specific photometric interpretations.

image manipulations
o  easyRotateBitsInto: destinationImage angle: degrees
tuned helper for rotation - does the actual pixel shuffling, by degrees clockwise.
Here, only 90, 180 and 270 degrees are implemented.
Hard angles are done in #hardRotate:.
The code here a tuned version of the inherited for more performance

o  negative
return a new image which is the negative-image
(black-white reversed or greyscale-reversed or complementary-color)

Usage example(s):

    Image fromScreen asDepth24Image negative inspect

initialization
o  initialize

magnification
o  hardAntiAliasedMagnifiedBy: scaleArg
return a new image magnified by scalePoint, aPoint.
This interpolates pixels and is therefore much slower,
but generates nicer looking magnifications.

Usage example(s):

     |i|
     i := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
     i := i asDepth24Image.
     i hardAntiAliasedMagnifiedBy:2@2.
     i hardAntiAliasedMagnifiedBy:3@3.
     i hardAntiAliasedMagnifiedBy:0.65@0.65.
     i hardAntiAliasedMagnifiedBy:0.3@0.3.

Usage example(s):

     |i|
     i := Depth24Image width:3 height:3 fromArray:#[ 0 0 0  0 0 0  0 0 0
                                                     0 0 0  255 255 255  0 0 0
                                                     0 0 0  0 0 0  0 0 0].
     i hardAntiAliasedMagnifiedBy:8@8

o  hardMagnifiedBy: scaleArg
return a new image magnified by scalePoint, aPoint.
This is the general magnification method, handling non-integral values.
It is slower than the integral magnification method.

Notice: this is a naive algorithm, which simply samples the pixel value
at the corresponding original pixel's point, without taking neighbors into
consideration (i.e. it does not compute an average of those pixels).
As a consequence, this will generate bad shrunk images when the original contains
sharp lines.

Usage example(s):

     |i|
     i := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
     i := Depth24Image fromImage:i.
     i hardMagnifiedBy:2@2.
     i hardMagnifiedBy:3@3.
     i hardMagnifiedBy:0.65@0.65.
     i hardMagnifiedBy:0.3@0.3.

o  magnifyRowFrom: srcBytes offset: srcStart into: dstBytes offset: dstStart factor: mX
magnify a single pixel row - can only magnify by integer factors

queries
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  blueBitsOf: pixel
given a pixel-value, return the blue component as byteValue (0..255)

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

o  blueMaskForPixelValue
return the mask used with translation from pixelValues to blueBits

o  blueShiftForPixelValue
return the shift amount used with translation from pixelValues to blueBits

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

o  greenBitsOf: pixel
given a pixel-value, return the green component as byteValue (0..255)

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

o  greenMaskForPixelValue
return the mask used with translation from pixelValues to redBits

o  greenShiftForPixelValue
return the shift amount used with translation from pixelValues to greenBits

o  numAlphaBits
(comment from inherited method)
alpha in low bits

o  numBlueBits
(comment from inherited method)
alpha in low bits

o  numGreenBits
(comment from inherited method)
alpha in low bits

o  numRedBits
(comment from inherited method)
alpha in low bits

o  redBitsOf: pixel
given a pixel-value, return the red component as byteValue (0..255)

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

o  redMaskForPixelValue
return the mask used with translation from pixelValues to redBits

o  redShiftForPixelValue
return the shift amount used with translation from pixelValues to redBits

o  rgbFromValue: pixelValue
given a pixel value, return the corresponding 24bit rgbValue
(rrggbb, red is MSB).

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

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

o  valueFromRGB: anRGBValue
get the pixel value corresponding to an RGB value.

o  valueFromRedBits: redBits greenBits: greenBits blueBits: blueBits
given the rgb bits, each in 0..maxXXXValue (i.e. according to
r/g/b channels number of bits, return the corresponding pixel value.
For now, only useful with RGB images



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 22 Dec 2024 03:25:27 GMT