comments and slight cleanup
authorClaus Gittinger <cg@exept.de>
Fri, 02 May 2003 19:50:55 +0200
changeset 3872 390fabbc3036
parent 3871 a7867fb8d880
child 3873 1f62ad46a04a
comments and slight cleanup
Depth16Image.st
Depth24Image.st
Depth4Image.st
Depth8Image.st
Image.st
--- a/Depth16Image.st	Tue Apr 29 23:27:04 2003 +0200
+++ b/Depth16Image.st	Fri May 02 19:50:55 2003 +0200
@@ -94,17 +94,17 @@
     "Created: 24.4.1997 / 17:06:21 / cg"
 !
 
-rowAt:rowIndex putAll:pixelArray startingAt:startIndex
+rowAt:y putAll:pixelArray startingAt:startIndex
     "store a single rows bits from bits in the pixelArray argument;
      Return the pixelArray.
-     Notice: row indexing starts at 0."
+     Notice: row coordinate starts at 0."
 
     |dstIdx "{ Class: SmallInteger }"
      pixel
      bytes|
 
     bytes := self bits.
-    dstIdx := (width * 2 * rowIndex) + 1.
+    dstIdx := (width * 2 * y) + 1.
     1 to:width do:[:col |
         pixel := pixelArray at:(startIndex + col - 1).
         bytes at:dstIdx put:((pixel bitShift:-8) bitAnd:16rFF).
@@ -139,5 +139,5 @@
 !Depth16Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth16Image.st,v 1.11 2003-04-29 19:20:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth16Image.st,v 1.12 2003-05-02 17:50:55 cg Exp $'
 ! !
--- a/Depth24Image.st	Tue Apr 29 23:27:04 2003 +0200
+++ b/Depth24Image.st	Fri May 02 19:50:55 2003 +0200
@@ -152,36 +152,16 @@
     "Created: 24.4.1997 / 17:06:33 / cg"
 !
 
-rowAt:rowIndex putAll:pixelArray
-    "replace a single rows bits from bits in the pixelArray argument;
-     Notice: row indexing starts at 0."
+rowAt:y putAll:pixelArray startingAt:startIndex
+    "store a single rows bits from bits in the pixelArray argument;
+     Return the pixelArray.
+     Notice: row coordinate starts at 0."
 
     |bytes dstIdx pixel|
 
     bytes := self bits.
-    dstIdx := (rowIndex * self bytesPerRow) + 1.
-    1 to:width do:[:col |
-        pixel := pixelArray at:col.
-        bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
-        bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
-        bytes at:dstIdx+2 put:(pixel bitAnd:16rFF).
-        dstIdx := dstIdx + 3.
-    ].
-    ^ pixelArray
-
-    "Created: 24.4.1997 / 15:43:08 / cg"
-!
-
-rowAt:rowIndex putAll:pixelArray startingAt:startIndex
-    "store a single rows bits from bits in the pixelArray argument;
-     Return the pixelArray.
-     Notice: row indexing starts at 0."
-
-    |bytes dstIdx pixel|
-
-    bytes := self bits.
-    dstIdx := (rowIndex * self bytesPerRow) + 1.
-    1 to:width do:[:col |
+    dstIdx := (y * self bytesPerRow) + 1.
+    0 to:width-1 do:[:col |
         pixel := pixelArray at:(startIndex + col).
         bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
         bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
@@ -2577,5 +2557,5 @@
 !Depth24Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.79 2003-04-29 19:20:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.80 2003-05-02 17:50:38 cg Exp $'
 ! !
--- a/Depth4Image.st	Tue Apr 29 23:27:04 2003 +0200
+++ b/Depth4Image.st	Fri May 02 19:50:55 2003 +0200
@@ -108,9 +108,9 @@
     "Created: 24.4.1997 / 17:06:39 / cg"
 !
 
-rowAt:rowIndex into:aPixelBuffer
+rowAt:y into:aPixelBuffer
     "fill aBuffer with pixel values retrieved from a single row.
-     Notice: rowIndex is 0-based."
+     Notice: row coordinate starts with 0."
 
     |lineIndex "{ Class: SmallInteger }"
      byte      "{ Class: SmallInteger }" 
@@ -120,7 +120,7 @@
     bytes := self bits.
     dstIdx := 1.
     w := width - 1.
-    lineIndex := (self bytesPerRow * rowIndex).
+    lineIndex := (self bytesPerRow * y).
     0 to:w do:[:x |
         x even ifTrue:[
             lineIndex := lineIndex + 1.
@@ -1029,5 +1029,5 @@
 !Depth4Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.45 2003-04-29 19:42:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.46 2003-05-02 17:50:18 cg Exp $'
 ! !
--- a/Depth8Image.st	Tue Apr 29 23:27:04 2003 +0200
+++ b/Depth8Image.st	Fri May 02 19:50:55 2003 +0200
@@ -124,39 +124,30 @@
     bytes at:index put:aPixelValue.
 !
 
-rowAt:rowIndex into:aPixelBuffer startingAt:startIndex
+rowAt:y into:aPixelBuffer startingAt:startIndex
     "fill aPixelBuffer with pixel values from a single row.
-     Notice: row indexing starts at 0."
+     Notice: row coordinate starts at 0."
 
     |srcIdx|
 
-    srcIdx := (rowIndex * width) + 1.
-    aPixelBuffer replaceFrom:startIndex to:startIndex+width-1 with:(self bits) startingAt:srcIdx
+    bytes notNil ifTrue:[
+        srcIdx := (y * width) + 1.
+        aPixelBuffer replaceFrom:startIndex to:startIndex+width-1 with:bytes startingAt:srcIdx.
+        ^ self.
+    ].
+    ^ super rowAt:y into:aPixelBuffer startingAt:startIndex
 
     "Modified: 24.4.1997 / 15:47:22 / cg"
 !
 
-rowAt:rowIndex putAll:pixelArray
-    "replace a single rows bits from bits in the argument;
-     Notice: row indexing starts at 0."
+rowAt:y putAll:pixelArray startingAt:startIndex
+    "store a single rows bits from bits in the pixelArray argument;
+     Return the pixelArray.
+     Notice: row coordinate starts at 0."
 
     |dstIdx|
 
-    dstIdx := (rowIndex*width) + 1.
-    self bits replaceFrom:dstIdx to:dstIdx+width-1 with:pixelArray startingAt:1.
-    ^ pixelArray
-
-    "Modified: 24.4.1997 / 14:34:23 / cg"
-!
-
-rowAt:rowIndex putAll:pixelArray startingAt:startIndex
-    "store a single rows bits from bits in the pixelArray argument;
-     Return the pixelArray.
-     Notice: row indexing starts at 0."
-
-    |dstIdx|
-
-    dstIdx := (rowIndex * width) + 1.
+    dstIdx := (y * width) + 1.
     self bits replaceFrom:dstIdx to:dstIdx+width-1 with:pixelArray startingAt:startIndex.
     ^ pixelArray
 
@@ -1961,5 +1952,5 @@
 !Depth8Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.102 2003-04-29 19:42:40 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.103 2003-05-02 17:49:34 cg Exp $'
 ! !
--- a/Image.st	Tue Apr 29 23:27:04 2003 +0200
+++ b/Image.st	Fri May 02 19:50:55 2003 +0200
@@ -62,14 +62,14 @@
     This gives a device independent image.
     For display, a device representation is required, which can be
     aquired by sending the 
-	'onDevice:aDevice' 
+        'onDevice:aDevice' 
     message to the image. This will create a (possibly dithered) device-form, 
     representing the image using the currently available colors.
 
     In rare cases, an explicit monochrome representation of the image is needed 
     (X servers take monochrome icons only), this can be created by sending
     it the message 
-	'monochromeOn:aDevice'.
+        'monochromeOn:aDevice'.
 
     Also, it is planned to generate another hi-color resolution version,
     which uses its own colormap and allows the use of all 256 colors on an 8bit display 
@@ -105,135 +105,144 @@
        DitherAlgorithm:
 
        nil                  a simple threshold algorithm
-			    (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
+                            (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
 
        #pattern             patterned dither
-			    (for p, take dithered color to fill pixel;
-			     uses dithering in color-class)
+                            (for p, take dithered color to fill pixel;
+                             uses dithering in color-class)
 
        #error               error diffusion dither (Floyd-Steinberg)
-			    planned - not yet implemented.
+                            planned - not yet implemented.
 
 
 
     [instance variables:]
 
-	width               <Integer>       the width in pixels
-	height              <Integer>       the height in pixels
-	bytes               <ByteArray>     the full image information
-	photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
-	samplesPerPixel     <Integer>       the number of planes
-	bitsPerSample       <Array>         the number of bits per plane
-
-	colorMap            <Array>         only if photometric is #palette;
-					    maps pixel values to r/g/b values.
-
-	device              <Workstation>   the device on which deviceForm,
-					    monoDeviceForm and lowResDeviceForm are
-
-	deviceForm          <Form>          the device form which gives the best
-					    possible aproximation of the image on
-					    device using standard colors.
-
-	monoDeviceForm      <Form>          the device form which gives a monochrome
-					    aproximation of the image on device.
-
-	fullColorDeviceForm <Form>          the device form which gives the best
-					    possible aproximation of the image on
-					    device using private colors.
-					    (not yet implemented)
-
-	mask                <ImageMask>     an optional mask;
-					    if non-nil, only pixels for which the
-					    corresponding mask bit is non-zero
-					    are drawn.
-
-	maskedPixelsAre0    <Boolean>       a hint for image processors and drawers
-					    if true, masked pixels are known to be
-					    zero in the pixel bytes.
-
-	fileName            <String>        the name of the file from which the
-					    image was loaded - nil otherwise.
-					    Useful for image save functions
-					    and for the UIPainter utility.
-
-	imageSequence                       the imageSequence, of which the
-					    instance is a frame or nil, 
-					    if its not part of a sequence.
-
-	bitsPerPixel                        not used in ST/X
-	depth                               - these have been added in instVar-slots
-	maxPixelValue                       - according to the ST-80's image class.
-	rowByteSize                         - to allow loading of st-80 images
-					    - (which are stored as instVarAt:put: expressions)
+        width               <Integer>       the width in pixels
+        height              <Integer>       the height in pixels
+        bytes               <ByteArray>     the full image information
+        photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
+        samplesPerPixel     <Integer>       the number of planes
+        bitsPerSample       <Array>         the number of bits per plane
+
+        colorMap            <Array>         only if photometric is #palette;
+                                            maps pixel values to r/g/b values.
+
+        device              <Workstation>   the device on which deviceForm,
+                                            monoDeviceForm and lowResDeviceForm are
+
+        deviceForm          <Form>          the device form which gives the best
+                                            possible aproximation of the image on
+                                            device using standard colors.
+
+        monoDeviceForm      <Form>          the device form which gives a monochrome
+                                            aproximation of the image on device.
+
+        fullColorDeviceForm <Form>          the device form which gives the best
+                                            possible aproximation of the image on
+                                            device using private colors.
+                                            (not yet implemented)
+
+        mask                <ImageMask>     an optional mask;
+                                            if non-nil, only pixels for which the
+                                            corresponding mask bit is non-zero
+                                            are drawn.
+
+        maskedPixelsAre0    <Boolean>       a hint for image processors and drawers
+                                            if true, masked pixels are known to be
+                                            zero in the pixel bytes.
+
+        fileName            <String>        the name of the file from which the
+                                            image was loaded - nil otherwise.
+                                            Useful for image save functions
+                                            and for the UIPainter utility.
+
+        imageSequence                       the imageSequence, of which the
+                                            instance is a frame or nil, 
+                                            if its not part of a sequence.
+
+        bitsPerPixel                        not used in ST/X
+        depth                               - these have been added in instVar-slots
+        maxPixelValue                       - according to the ST-80's image class.
+        rowByteSize                         - to allow loading of st-80 images
+                                            - (which are stored as instVarAt:put: expressions)
 
     [class variables:]
 
-	Lobby               <Registry>      keeps track of known images
-					    (for resource freeing with garbage collector)
-
-	DitherAlgorithm     <Symbol>        defines how to dither
-
-	NumberOfDitherColors <Integer>      defines, how many dither colors to use
-
-	FileFormats         <Dictionary>    associates filename extensions to
-					    image reader classes (now set-up in startup-file)
-
-	CollectGarbageWhenRunningOutOfColors
-			    <Boolean>       if true, and we run out of available
-					    device colors during creation of a
-					    device image, collect garbage for
-					    possible image reclamation.
-					    If false, proceed immediately.
-					    Default is true.
-
-	ImageNotFoundQuerySignal
-			    <QuerySignal>   raised, if an image could not be loaded
-					    from a file. The parameter is the images
-					    fileName. 
-					    A handler may return a replacement
-					    image or proceed with nil.
-					    If unhandled, a nil is returned from the
-					    image creation.
-
-	BadImageFormatQuerySignal
-			    <QuerySignal>   raised, if an image could not be loaded
-					    from a file due to a file error or
-					    unsupported format. 
-					    A handler may return a replacement
-					    image or proceed with nil.
-					    If unhandled, a nil is returned from the
-					    image creation.
-
-	ImageSaveErrorSignal
-			    <Signal>        parent of errors below.
-
-	FileCreationErrorSignal
-			    <Signal>        file could not be created when saving an
-					    image.
-
-	CannotRepresentImageSignal
-			    <Signal>        the specified ImageReader cannot represent
-					    the given image.
-
-	InformationLostQuerySignal
-			    <Signal>        the specified ImageReader can represent
-					    the given image, but some information
-					    (typically color resolution) is lost.
-					    If unhandled, the save proceeds as usual.
-
+        Lobby               <Registry>      keeps track of known images
+                                            (for resource freeing with garbage collector)
+
+        DitherAlgorithm     <Symbol>        defines how to dither
+
+        NumberOfDitherColors <Integer>      defines, how many dither colors to use
+
+        FileFormats         <Dictionary>    associates filename extensions to
+                                            image reader classes (now set-up in startup-file)
+
+        CollectGarbageWhenRunningOutOfColors
+                            <Boolean>       if true, and we run out of available
+                                            device colors during creation of a
+                                            device image, collect garbage for
+                                            possible image reclamation.
+                                            If false, proceed immediately.
+                                            Default is true.
+
+        ImageNotFoundQuerySignal
+                            <QuerySignal>   raised, if an image could not be loaded
+                                            from a file. The parameter is the images
+                                            fileName. 
+                                            A handler may return a replacement
+                                            image or proceed with nil.
+                                            If unhandled, a nil is returned from the
+                                            image creation.
+
+        BadImageFormatQuerySignal
+                            <QuerySignal>   raised, if an image could not be loaded
+                                            from a file due to a file error or
+                                            unsupported format. 
+                                            A handler may return a replacement
+                                            image or proceed with nil.
+                                            If unhandled, a nil is returned from the
+                                            image creation.
+
+        ImageSaveErrorSignal
+                            <Signal>        parent of errors below.
+
+        FileCreationErrorSignal
+                            <Signal>        file could not be created when saving an
+                                            image.
+
+        CannotRepresentImageSignal
+                            <Signal>        the specified ImageReader cannot represent
+                                            the given image.
+
+        InformationLostQuerySignal
+                            <Signal>        the specified ImageReader can represent
+                                            the given image, but some information
+                                            (typically color resolution) is lost.
+                                            If unhandled, the save proceeds as usual.
+
+
+    caveat:
+        the information in
+            photometric, bitsPerPixel, bitsPerSample, samplesPerPixel, depth , colorMap and maxPixelValue
+        is partially redundant and its handling stupid (not to say: braindamaged ;-).
+        The only excuse is that it grew over time, had to incorporate various alien/older schemes for
+        compatibility reasons. All of the above belongs into the single colorMap which must migrate from
+        a stupid seqColl to a color-aware real colorMap.
+        (we are in the process of doing so...)
 
     todo:
-	support alpha masks
-	cleanup the dithering & conversion code
+        support alpha masks
+        cleanup the dithering & conversion code
+        cleanup the color/photometric mess
 
     [See also:]
-	Form Icon ImageReader
+        Form Icon ImageReader
 
     [author:]
-	Claus Gittinger
+        Claus Gittinger
 "
-
 !
 
 examples
@@ -2735,17 +2744,17 @@
     "Created: 24.4.1997 / 17:05:11 / cg"
 !
 
-rowAt:rowIndex
+rowAt:y
     "retrieve an array filled with pixel values from
      a single row.
-     Notice: row indexing starts at 0.
+     Notice: row coordinate starts at 0.
      This is a slow fallBack method, which works with any depth;
      concrete image subclasses should redefine this for more performance."
 
     |pixelArray|
 
     pixelArray := self pixelArraySpecies new:width.
-    self rowAt:rowIndex into:pixelArray startingAt:1.
+    self rowAt:y into:pixelArray startingAt:1.
     ^ pixelArray
 
     "
@@ -2764,19 +2773,19 @@
     "Modified: 24.4.1997 / 15:51:24 / cg"
 !
 
-rowAt:rowIndex into:aPixelBuffer
+rowAt:y into:aPixelBuffer
     "fill aBuffer with pixel values retrieved from a single row.
-     Notice: row indexing starts at 0."
-
-    ^ self rowAt:rowIndex into:aPixelBuffer startingAt:1
+     Notice: row coordinate starts at 0."
+
+    ^ self rowAt:y into:aPixelBuffer startingAt:1
 
     "Created: 24.4.1997 / 15:44:46 / cg"
     "Modified: 24.4.1997 / 15:51:35 / cg"
 !
 
-rowAt:rowIndex into:aPixelBuffer startingAt:startIndex
+rowAt:y into:aPixelBuffer startingAt:startIndex
     "fill aBuffer with pixel values retrieved from a single row.
-     Notice: row indexing starts at 0.
+     Notice: row coordinate starts at 0.
      This is a slow fallBack method, which works with any depth;
      concrete image subclasses should redefine this for more performance."
 
@@ -2784,28 +2793,28 @@
 
     w := width-1.
     0 to:w do:[:col |
-	aPixelBuffer at:(col + startIndex) put:(self pixelAtX:col y:rowIndex)
+        aPixelBuffer at:(col + startIndex) put:(self pixelAtX:col y:y)
     ].
 
     "Created: 24.4.1997 / 15:05:21 / cg"
     "Modified: 24.4.1997 / 16:52:43 / cg"
 !
 
-rowAt:rowIndex putAll:pixelArray
+rowAt:y putAll:pixelArray
     "store a single rows pixels from bits in the argument;
-     Notice: row indexing starts at 0.
+     Notice: row coordinate starts at 0.
      This is a slow fallBack method, which works with any depth;
      concrete image subclasses should redefine this for more performance."
 
-    ^ self rowAt:rowIndex putAll:pixelArray startingAt:1
+    ^ self rowAt:y putAll:pixelArray startingAt:1
 
     "Modified: 24.4.1997 / 15:51:58 / cg"
 !
 
-rowAt:rowIndex putAll:pixelArray startingAt:startIndex
+rowAt:y putAll:pixelArray startingAt:startIndex
     "store a single rows pixels from bits in the pixelArray argument;
      return the pixelArray.
-     Notice: row indexing starts at 0.
+     Notice: row coordinate starts at 0.
      This is a slow fallBack method, which works with any depth;
      concrete image subclasses should redefine this for more performance."
 
@@ -2813,7 +2822,7 @@
 
     w := width-1.
     0 to:w do:[:col |
-	self pixelAtX:col y:rowIndex put:(pixelArray at:(col + startIndex))
+        self pixelAtX:col y:y put:(pixelArray at:(col + startIndex))
     ].
     ^ pixelArray
 
@@ -5235,9 +5244,8 @@
     nPlanes := samplesPerPixel.
     (nPlanes == 2) ifTrue:[
         'Image [info]: alpha plane ignored' infoPrintCR.
-        nPlanes := 1
-    ].
-
+    ].
+    "/ first plane only
     pictureDepth := bitsPerSample at:1.
 
     "monochrome is very easy ..."
@@ -12469,7 +12477,7 @@
 !Image class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.341 2003-04-29 21:27:04 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.342 2003-05-02 17:49:58 cg Exp $'
 ! !
 
 Image initialize!