Depth4Image.st
author Claus Gittinger <cg@exept.de>
Mon, 27 Jul 1998 10:18:11 +0200
changeset 2186 4e4b6f9b0d27
parent 2179 30461fd19cd5
child 2197 1b88e629091d
permissions -rw-r--r--
tuned conversion to trueColor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
claus
parents: 1
diff changeset
     1
"
claus
parents: 1
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
     3
	      All Rights Reserved
4
claus
parents: 1
diff changeset
     4
claus
parents: 1
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 1
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 1
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 1
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 1
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 1
diff changeset
    10
 hereby transferred.
claus
parents: 1
diff changeset
    11
"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    12
304f026e10cd Initial revision
claus
parents:
diff changeset
    13
Image subclass:#Depth4Image
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 280
diff changeset
    14
	instanceVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 280
diff changeset
    15
	classVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 280
diff changeset
    16
	poolDictionaries:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 280
diff changeset
    17
	category:'Graphics-Images'
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    18
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    19
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    20
!Depth4Image class methodsFor:'documentation'!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    21
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    22
copyright
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    23
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    24
 COPYRIGHT (c) 1993 by Claus Gittinger
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
    25
	      All Rights Reserved
4
claus
parents: 1
diff changeset
    26
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    27
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    28
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    30
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    31
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    32
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    33
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    34
!
4
claus
parents: 1
diff changeset
    35
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    36
documentation
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    37
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    38
    this class represents 16-color (4 bit / pixel) images.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    39
    Most images coming from the windows world are represented as Depth4Images.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    40
    It mainly consists of methods already implemented in Image,
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    41
    reimplemented here for more performance.
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    42
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    43
    [author:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    44
        Claus Gittinger
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    45
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    46
    [see also:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    47
        Depth1Image Depth2Image Depth8Image Depth16Image Depth24Image
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    48
        ImageReader
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    49
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    50
! !
4
claus
parents: 1
diff changeset
    51
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    52
!Depth4Image class methodsFor:'queries'!
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    53
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    54
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 280
diff changeset
    55
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 280
diff changeset
    56
     this class - here we return 4"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 280
diff changeset
    57
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    58
    ^ 4
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 280
diff changeset
    59
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 280
diff changeset
    60
    "Modified: 20.4.1996 / 23:40:18 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    61
! !
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    62
1656
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    63
!Depth4Image methodsFor:'accessing - pixels'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    64
1656
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    65
colorAtX:x y:y
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    66
    "retrieve a pixel at x/y; return a color.
304f026e10cd Initial revision
claus
parents:
diff changeset
    67
     Pixels start at x=0 , y=0 for upper left pixel, end at
304f026e10cd Initial revision
claus
parents:
diff changeset
    68
     x = width-1, y=height-1 for lower right pixel"
304f026e10cd Initial revision
claus
parents:
diff changeset
    69
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    70
    |lineIndex "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    71
     byte      "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    72
     value     "{ Class: SmallInteger }" |
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    73
304f026e10cd Initial revision
claus
parents:
diff changeset
    74
    lineIndex := (self bytesPerRow * y) + 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
    75
304f026e10cd Initial revision
claus
parents:
diff changeset
    76
    "left pixel in high bits"
304f026e10cd Initial revision
claus
parents:
diff changeset
    77
    byte := bytes at:(lineIndex + (x // 2)).
304f026e10cd Initial revision
claus
parents:
diff changeset
    78
    x even ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    79
        value := (byte bitShift:-4) bitAnd:16rF.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    80
    ] ifFalse:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    81
        value := byte bitAnd:16rF.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    82
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
    83
    photometric == #whiteIs0 ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    84
        ^ Color gray:100 - (100 / 15 * value)
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    85
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
    86
    photometric == #blackIs0 ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    87
        ^ Color gray:(100 / 15 * value)
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    88
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
    89
    photometric ~~ #palette ifTrue:[
803
899f7eb32ef2 support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
    90
        ^ self colorFromValue:value
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    91
    ].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    92
    ^ colorMap at:(value + 1)
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    93
803
899f7eb32ef2 support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
    94
    "Modified: 8.6.1996 / 10:52:43 / cg"
1656
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    95
    "Created: 24.4.1997 / 17:33:51 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    96
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    97
1656
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    98
pixelAtX:x y:y
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    99
    "retrieve a pixel at x/y; return a pixelValue.
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   100
     Pixels start at x=0 , y=0 for upper left pixel, end at
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   101
     x = width-1, y=height-1 for lower right pixel"
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   102
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   103
    |lineIndex "{ Class: SmallInteger }"
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   104
     byte      "{ Class: SmallInteger }" |
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   105
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   106
    lineIndex := (self bytesPerRow * y) + 1.
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   107
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   108
    "left pixel in high bits"
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   109
    byte := bytes at:(lineIndex + (x // 2)).
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   110
    x even ifTrue:[
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   111
        ^ (byte bitShift:-4) bitAnd:16rF.
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   112
    ].
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   113
    ^ byte bitAnd:16rF.
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   114
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   115
    "Created: 24.4.1997 / 16:06:43 / cg"
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   116
!
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   117
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   118
pixelAtX:x y:y put:aPixelValue
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   119
    "set the pixel at x/y to aPixelValue.
304f026e10cd Initial revision
claus
parents:
diff changeset
   120
     Pixels start at x=0 , y=0 for upper left pixel, end at
304f026e10cd Initial revision
claus
parents:
diff changeset
   121
     x = width-1, y=height-1 for lower right pixel"
304f026e10cd Initial revision
claus
parents:
diff changeset
   122
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   123
    |lineIndex "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   124
     index     "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   125
     byte      "{ Class: SmallInteger }" |
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   126
304f026e10cd Initial revision
claus
parents:
diff changeset
   127
    lineIndex := (self bytesPerRow * y) + 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
   128
304f026e10cd Initial revision
claus
parents:
diff changeset
   129
    "left pixel is in high bits"
304f026e10cd Initial revision
claus
parents:
diff changeset
   130
    index := lineIndex + (x // 2).
304f026e10cd Initial revision
claus
parents:
diff changeset
   131
    byte := bytes at:index.
304f026e10cd Initial revision
claus
parents:
diff changeset
   132
    x even ifTrue:[
1656
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   133
        byte := (byte bitAnd:16rF) bitOr:(aPixelValue bitShift:4)
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   134
    ] ifFalse:[
1656
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   135
        byte := (byte bitAnd:16rF0) bitOr:aPixelValue
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   136
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
   137
    bytes at:index put:byte
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   138
1656
ebcad6911ddb pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   139
    "Created: 24.4.1997 / 17:06:39 / cg"
1816
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   140
!
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   141
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   142
rowAt:rowIndex into:aPixelBuffer
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   143
    "fill aBuffer with pixel values retrieved from a single row.
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   144
     Notice: rowIndex is 0-based."
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   145
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   146
    |lineIndex "{ Class: SmallInteger }"
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   147
     byte      "{ Class: SmallInteger }" 
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   148
     w         "{ Class: SmallInteger }" 
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   149
     pixel dstIdx|
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   150
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   151
    dstIdx := 1.
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   152
    w := width - 1.
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   153
    lineIndex := (self bytesPerRow * rowIndex).
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   154
    0 to:w do:[:x |
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   155
        x even ifTrue:[
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   156
            lineIndex := lineIndex + 1.
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   157
            byte := bytes at:lineIndex.
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   158
            pixel := (byte bitShift:-4) bitAnd:16rF.
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   159
        ] ifFalse:[
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   160
            pixel := byte bitAnd:16rF.
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   161
        ].
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   162
        aPixelBuffer at:dstIdx put:pixel.
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   163
        dstIdx := dstIdx + 1
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   164
    ].
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   165
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   166
    "Created: 21.7.1997 / 18:04:00 / cg"
88716b7cc777 tuned row access
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   167
    "Modified: 21.7.1997 / 18:05:47 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
   168
! !
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
   169
2186
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   170
!Depth4Image methodsFor:'converting images'!
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   171
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   172
anyImageAsTrueColorFormOn:aDevice
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   173
    "return a true-color device-form for the palette-image receiver.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   174
     Supports true color devices with depths: 8, 16, 24 and 32"
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   175
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   176
    |depth 
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   177
     nColors "{ Class: SmallInteger }"
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   178
     colorValues 
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   179
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   180
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel 
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   181
     usedDevicePadding usedDeviceBytesPerRow padd n|
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   182
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   183
    depth := aDevice depth.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   184
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   185
    "/ gather r/g/b values for all colors in the map ...
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   186
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   187
    nColors := 1 bitShift:(self depth).
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   188
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   189
    "/ precompute scales to map from 0..100 into devices range
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   190
    "/ (this may be different for the individual components)
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   191
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   192
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   193
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   194
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   195
    redShift := aDevice shiftRed.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   196
    greenShift := aDevice shiftGreen.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   197
    blueShift := aDevice shiftBlue.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   198
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   199
    colorValues := Array uninitializedNew:nColors.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   200
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   201
    0 to:nColors-1 do:[:pixel |
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   202
        |clr rv gv bv v "{ Class: SmallInteger }" |
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   203
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   204
        clr := self colorFromValue:pixel.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   205
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   206
        rv := (clr red * scaleRed) rounded.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   207
        gv := (clr green * scaleGreen) rounded.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   208
        bv := (clr blue * scaleBlue) rounded.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   209
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   210
        v := rv bitShift:redShift.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   211
        v := v bitOr:(gv bitShift:greenShift).
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   212
        v := v bitOr:(bv bitShift:blueShift).
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   213
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   214
        colorValues at:(pixel+1) put:v.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   215
"/ clr print. ' ' print.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   216
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   217
"/ ' -> ' print. v printNL.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   218
    ].
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   219
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   220
    bestFormat := self bestSupportedImageFormatFor:aDevice.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   221
    usedDeviceDepth := bestFormat at:#depth.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   222
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   223
    usedDevicePadding := bestFormat at:#padding.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   224
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   225
    usedDeviceBytesPerRow := self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:usedDevicePadding.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   226
    padd := usedDeviceBytesPerRow -( self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:8).
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   227
    imageBits := ByteArray uninitializedNew:(usedDeviceBytesPerRow * height).
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   228
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   229
    "/ for now, only support some depths
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   230
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   231
    usedDeviceBitsPerPixel == 16 ifTrue:[
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   232
        "/ 16 bits/pixel
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   233
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   234
        "/ now, walk over the image and replace
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   235
        "/ colorMap indices by color values in the bits array
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   236
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   237
%{  
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   238
        if (__bothSmallInteger(_INST(height), _INST(width))
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   239
         && __isArray(colorValues)
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   240
         && __isByteArray(_INST(bytes))
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   241
         && __isByteArray(imageBits)) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   242
            int r,p;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   243
            int x, y, w, h, nPix;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   244
            int byte;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   245
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   246
            unsigned char *srcPtr = __ByteArrayInstPtr(_INST(bytes))->ba_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   247
            unsigned char *dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   248
            OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   249
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   250
            w = __intVal(_INST(width));
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   251
            h = __intVal(_INST(height));
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   252
            r = 0;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   253
            p = __intVal(padd);
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   254
            nPix = w * h;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   255
            while (nPix-- > 0) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   256
                unsigned idx, v;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   257
                OBJ clr;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   258
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   259
                if (r & 1) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   260
                    idx = byte & 0xF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   261
                } else {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   262
                    byte = *srcPtr++;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   263
                    idx = (byte>>4) & 0xF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   264
                }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   265
                clr = ap[idx];
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   266
                v = __intVal(clr);
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   267
#ifdef MSBFIRST
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   268
                ((short *)dstPtr)[0] = v;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   269
#else
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   270
                dstPtr[0] = (v>>8) & 0xFF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   271
                dstPtr[1] = (v) & 0xFF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   272
#endif
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   273
                dstPtr += 2;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   274
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   275
                if (++r == w) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   276
                    dstPtr += p;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   277
                    r = 0;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   278
                }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   279
            }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   280
        }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   281
%}.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   282
    ] ifFalse:[
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   283
        usedDeviceBitsPerPixel == 32 ifTrue:[
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   284
            "/ 32 bits/pixel
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   285
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   286
            "/ now, walk over the image and replace
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   287
            "/ colorMap indices by color values in the bits array
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   288
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   289
%{       
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   290
            if (__bothSmallInteger(_INST(height), _INST(width))
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   291
             && __isArray(colorValues)
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   292
             && __isByteArray(_INST(bytes))
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   293
             && __isByteArray(imageBits)) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   294
                int x, y, w, h, nPix;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   295
                int r,p;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   296
                int byte;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   297
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   298
                unsigned char *srcPtr = __ByteArrayInstPtr(_INST(bytes))->ba_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   299
                unsigned char *dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   300
                OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   301
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   302
                w = __intVal(_INST(width));
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   303
                h = __intVal(_INST(height));
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   304
                r = 0;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   305
                p = __intVal(padd);
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   306
                nPix = w * h;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   307
                while (nPix > 0) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   308
                    unsigned idx, v;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   309
                    OBJ clr;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   310
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   311
                    if (r & 1) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   312
                        byte = *srcPtr++;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   313
                        idx = (byte>>4) & 0xF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   314
                    } else {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   315
                        idx = byte & 0xF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   316
                    }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   317
                    clr = ap[idx];
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   318
                    v = __intVal(clr);
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   319
#ifdef MSBFIRST
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   320
                    ((long *)dstPtr)[0] = v;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   321
#else
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   322
                    dstPtr[0] = (v>>24) & 0xFF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   323
                    dstPtr[1] = (v>>16) & 0xFF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   324
                    dstPtr[2] = (v>>8) & 0xFF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   325
                    dstPtr[3] = (v) & 0xFF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   326
#endif
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   327
                    dstPtr += 4;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   328
                    nPix--;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   329
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   330
                    if (++r == w) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   331
                        dstPtr += p;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   332
                        r = 0;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   333
                    }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   334
                }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   335
            }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   336
%}.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   337
        ] ifFalse:[
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   338
            usedDeviceBitsPerPixel == 8 ifTrue:[
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   339
                "/ 8 bits/pixel
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   340
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   341
                "/ now, walk over the image and replace
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   342
                "/ colorMap indices by color values in the bits array
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   343
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   344
%{       
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   345
                if (__bothSmallInteger(_INST(height), _INST(width))
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   346
                 && __isArray(colorValues)
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   347
                 && __isByteArray(_INST(bytes))
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   348
                 && __isByteArray(imageBits)) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   349
                    int x, y, w, h, nPix;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   350
                    int r,p, byte;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   351
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   352
                    unsigned char *srcPtr = __ByteArrayInstPtr(_INST(bytes))->ba_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   353
                    unsigned char *dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   354
                    OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   355
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   356
                    w = __intVal(_INST(width));
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   357
                    h = __intVal(_INST(height));
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   358
                    r = 0;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   359
                    p = __intVal(padd);
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   360
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   361
                    nPix = w * h;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   362
                    while (nPix > 0) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   363
                        unsigned idx, v;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   364
                        OBJ clr;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   365
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   366
                        if (r & 1) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   367
                            byte = *srcPtr++;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   368
                            idx = (byte>>4) & 0xF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   369
                        } else {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   370
                            idx = byte & 0xF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   371
                        }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   372
                        clr = ap[idx];
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   373
                        v = __intVal(clr);
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   374
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   375
                        dstPtr[0] = v;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   376
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   377
                        dstPtr += 1;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   378
                        nPix--;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   379
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   380
                        if (++r == w) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   381
                            dstPtr += p;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   382
                            r = 0;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   383
                        }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   384
                    }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   385
                }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   386
%}.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   387
            ] ifFalse:[
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   388
                usedDeviceBitsPerPixel == 24 ifTrue:[
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   389
                    "/ 24 bits/pixel
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   390
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   391
                    "/ now, walk over the image and replace
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   392
                    "/ colorMap indices by color values in the bits array
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   393
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   394
%{       
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   395
                    if (__bothSmallInteger(_INST(height), _INST(width))
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   396
                     && __isArray(colorValues)
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   397
                     && __isByteArray(_INST(bytes))
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   398
                     && __isByteArray(imageBits)) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   399
                        int x, y, w, h, nPix;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   400
                        int r, p, byte;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   401
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   402
                        unsigned char *srcPtr = __ByteArrayInstPtr(_INST(bytes))->ba_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   403
                        unsigned char *dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   404
                        OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   405
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   406
                        w = __intVal(_INST(width));
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   407
                        h = __intVal(_INST(height));
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   408
                        r = 0;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   409
                        p = __intVal(padd);
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   410
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   411
                        nPix = w * h;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   412
                        while (nPix > 0) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   413
                            unsigned idx, v;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   414
                            OBJ clr;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   415
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   416
                            if (r & 1) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   417
                                byte = *srcPtr++;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   418
                                idx = (byte>>4) & 0xF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   419
                            } else {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   420
                                idx = byte & 0xF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   421
                            }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   422
                            clr = ap[idx];
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   423
                            v = __intVal(clr);
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   424
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   425
                            dstPtr[0] = (v>>16) & 0xFF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   426
                            dstPtr[1] = (v>>8) & 0xFF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   427
                            dstPtr[2] = (v) & 0xFF;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   428
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   429
                            dstPtr += 3;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   430
                            nPix--;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   431
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   432
                            if (++r == w) {
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   433
                                dstPtr += p;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   434
                                r = 0;
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   435
                            }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   436
                        }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   437
                    }
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   438
%}.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   439
                ] ifFalse:[
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   440
                    'Image [warning]: unimplemented trueColor depth in anyImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   441
                    ^ nil
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   442
                ]
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   443
            ]
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   444
        ]
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   445
    ].
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   446
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   447
    imageBits isNil ifTrue:[            
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   448
        ^ nil
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   449
    ].
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   450
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   451
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   452
    form isNil ifTrue:[^ nil].
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   453
    form initGC.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   454
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   455
    form
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   456
        copyBitsFrom:imageBits
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   457
        bitsPerPixel:usedDeviceBitsPerPixel
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   458
        depth:usedDeviceDepth
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   459
        padding:usedDevicePadding
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   460
        width:width height:height 
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   461
        x:0 y:0
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   462
        toX:0 y:0. 
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   463
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   464
    ^ form
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   465
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   466
    "Created: 20.10.1995 / 22:05:10 / cg"
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   467
    "Modified: 21.10.1995 / 19:30:26 / cg"
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   468
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   469
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   470
!
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   471
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   472
greyImageAsTrueColorFormOn:aDevice
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   473
    "return a true-color device-form for the grey-image receiver.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   474
     Supports true color devices with depths: 8, 16, 24 and 32"
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   475
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   476
    |f|
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   477
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   478
    f := self anyImageAsTrueColorFormOn:aDevice.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   479
    f notNil ifTrue:[^ f].
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   480
    ^ super greyImageAsTrueColorFormOn:aDevice
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   481
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   482
    "Created: / 24.7.1998 / 01:21:28 / cg"
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   483
!
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   484
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   485
paletteImageAsTrueColorFormOn:aDevice
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   486
    "return a true-color device-form for the palette-image receiver.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   487
     Supports true color devices with depths: 8, 16, 24 and 32"
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   488
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   489
    |f|
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   490
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   491
    f := self anyImageAsTrueColorFormOn:aDevice.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   492
    f notNil ifTrue:[^ f].
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   493
    ^ super paletteImageAsTrueColorFormOn:aDevice
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   494
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   495
    "Created: / 24.7.1998 / 01:20:46 / cg"
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   496
!
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   497
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   498
rgbImageAsTrueColorFormOn:aDevice
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   499
    "return a true-color device-form for the rgb-image receiver.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   500
     Supports true color devices with depths: 8, 16, 24 and 32"
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   501
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   502
    |f|
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   503
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   504
    f := self anyImageAsTrueColorFormOn:aDevice.
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   505
    f notNil ifTrue:[^ f].
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   506
    ^ super rgbImageAsTrueColorFormOn:aDevice
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   507
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   508
    "Created: / 24.7.1998 / 01:21:57 / cg"
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   509
! !
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   510
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   511
!Depth4Image methodsFor:'dither helpers'!
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   512
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1656
diff changeset
   513
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
806
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   514
    "return the bitmap for a dithered depth-bitmap from the image;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   515
     with a constant ditherMatrix, this can be used for thresholding.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   516
     Redefined to make use of knowing that pixels are 4-bit values."
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   517
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   518
    |dH nDither   
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   519
     greyLevels greyMap1 greyMap2
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   520
     bytesPerRow  "{Class: SmallInteger }"
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   521
     bytesPerOutRow  "{Class: SmallInteger }"
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   522
     pixelsPerByte   "{Class: SmallInteger }"
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   523
     outBits
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   524
     w               "{Class: SmallInteger }"
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   525
     h               "{Class: SmallInteger }" |
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   526
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   527
    nDither := ditherMatrix size.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   528
    dH := nDither / dW.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   529
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   530
    w := width.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   531
    h := height.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   532
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   533
    greyLevels := 1 bitShift:depth.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   534
    pixelsPerByte := 8 / depth.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   535
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   536
    bytesPerRow := self bytesPerRow.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   537
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   538
    bytesPerOutRow := (w * depth + 7) // 8.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   539
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   540
    (outBits isNil or:[bytes isNil]) ifTrue:[
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   541
        ^ nil
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   542
    ].
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   543
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   544
    greyMap1 := self greyMapForRange:(greyLevels-1).                    "/ the pixels
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   545
    greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   546
                                            0
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   547
                                        ] ifFalse:[
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   548
                                            b truncated
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   549
                                        ]
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   550
                                  ]) asByteArray.      
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   551
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   552
    greyMap2 := self greyMapForRange:(greyLevels-1).
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   553
    greyMap2 := (greyMap2 collect:[:el | 
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   554
                                        el isNil ifTrue:[
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   555
                                            0
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   556
                                        ] ifFalse:[
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   557
                                            ((el - el truncated)  "/ the error (0..1)
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   558
                                            * nDither) rounded
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   559
                                        ]]) asByteArray.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   560
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   561
%{
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   562
    int __dW = __intVal(dW);
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   563
    int __dH = __intVal(dH);
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   564
    int __byte;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   565
    int __dT, __dO;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   566
    int __depth = __intVal(depth);
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   567
    int __dstIdx = 0;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   568
    int __srcIdx = 0;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   569
    int __bitCnt;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   570
    int __inByte;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   571
    int __grey, __pixel;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   572
    int __w = __intVal(w);
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   573
    int __h = __intVal(h);
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   574
    int __x;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   575
    int __y;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   576
    int __oX, __oY, __dY;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   577
    int __nextDst;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   578
    int __nextSrc;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   579
    int __bytesPerRow = __intVal(bytesPerRow);
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   580
    int __bytesPerOutRow = __intVal(bytesPerOutRow);
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   581
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
   582
    unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element;
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   583
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
806
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   584
    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   585
    unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   586
    unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   587
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   588
    __oY = __dY = 0;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   589
    for (__y=0; __y<__h; __y++) {
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   590
        __nextDst = __dstIdx + __bytesPerOutRow;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   591
        __nextSrc = __srcIdx + __bytesPerRow;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   592
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   593
        __byte = 0;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   594
        __bitCnt = 8;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   595
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   596
        __oX = 0;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   597
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   598
        for (__x=0; __x<__w; __x++) {
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   599
            if (__x & 1) {
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   600
                /* odd */
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   601
                __grey = __inByte & 0xF;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   602
                __srcIdx++;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   603
            } else {
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   604
                __inByte = __bytes[__srcIdx];        
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   605
                __grey = (__inByte >> 4) & 0xF;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   606
            }
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   607
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   608
            __pixel = __greyMap1[__grey];            /* 0..(greyLevels-1) */
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   609
            __dO    = __greyMap2[__grey];            /* 0.. nDither-1) */
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   610
            __dT = __ditherMatrix[__dY + __oX];
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   611
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   612
            if (__dO > __dT)                         /* dither says: next pixel */
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   613
                __pixel++;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   614
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   615
            __oX++;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   616
            if (__oX == __dW) __oX = 0;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   617
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   618
            __byte = (__byte << __depth) | __pixel;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   619
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   620
            __bitCnt = __bitCnt - __depth;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   621
            if (__bitCnt == 0) {
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   622
                __outBits[__dstIdx] = __byte;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   623
                __dstIdx++;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   624
                __byte = 0;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   625
                __bitCnt = 8;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   626
            }
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   627
        }
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   628
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   629
        if (__bitCnt != 8) {
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   630
            __byte = __byte << __bitCnt;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   631
            __outBits[__dstIdx] = __byte;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   632
        }
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   633
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   634
        __oY++; __dY += __dW;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   635
        if (__oY == __dH) {
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   636
            __oY = 0;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   637
            __dY = 0;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   638
        }
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   639
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   640
        __srcIdx = __nextSrc;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   641
        __dstIdx = __nextDst;
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   642
    }
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   643
%}.
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   644
    ^ outBits
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   645
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   646
!
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 803
diff changeset
   647
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   648
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   649
    "return the dithered monochrome bits for the receiver image;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   650
     with a constant ditherMatrix, this can be used for thresholding.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   651
     Redefined to make use of knowing that pixels are 4-bit values."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   652
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   653
    |f dH nDither   
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   654
     greyMap monoBits
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   655
     bytesPerMonoRow "{Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   656
     bytesPerRow     "{Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   657
     w               "{Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   658
     h               "{Class: SmallInteger }"|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   659
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   660
    nDither := ditherMatrix size.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   661
    dH := nDither / dW.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   662
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   663
    w := width.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   664
    h := height.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   665
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   666
    bytesPerRow := self bytesPerRow.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   667
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   668
    bytesPerMonoRow := w + 7 // 8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   669
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   670
    (monoBits isNil or:[bytes isNil]) ifTrue:[
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   671
        ^ nil
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   672
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   673
803
899f7eb32ef2 support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
   674
    greyMap := self greyByteMapForRange:nDither.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   675
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   676
%{
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   677
    int __dW = __intVal(dW);
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   678
    int __dH = __intVal(dH);
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   679
    int __byte;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   680
    int __dT;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   681
    int __dstIdx = 0;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   682
    int __srcIdx = 0;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   683
    int __bitCnt;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   684
    int __inByte;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   685
    int __grey;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   686
    int __w = __intVal(w);
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   687
    int __h = __intVal(h);
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   688
    int __x;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   689
    int __y;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   690
    int __oX, __oY, __dY;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   691
    int __nextDst;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   692
    int __nextSrc;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   693
    int __bytesPerRow = __intVal(bytesPerRow);
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   694
    int __bytesPerMonoRow = __intVal(bytesPerMonoRow);
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   695
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
   696
    unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element;
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   697
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   698
    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   699
    unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   700
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   701
    __oY = __dY = 0;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   702
    for (__y=0; __y<__h; __y++) {
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   703
        __nextDst = __dstIdx + __bytesPerMonoRow;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   704
        __nextSrc = __srcIdx + __bytesPerRow;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   705
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   706
        __byte = 0;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   707
        __bitCnt = 8;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   708
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   709
        __oX = 0;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   710
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   711
        for (__x=0; __x<__w; __x++) {
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   712
            if (__x & 1) {
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   713
                /* odd */
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   714
                __grey = __inByte & 0xF;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   715
                __srcIdx++;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   716
            } else {
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   717
                __inByte = __bytes[__srcIdx];   /* 0..255 */
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   718
                __grey = (__inByte >> 4) & 0xF;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   719
            }
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   720
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   721
            __grey = __greyMap[__grey];
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   722
            __dT = __ditherMatrix[__dY + __oX];
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   723
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   724
            __oX++;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   725
            if (__oX == __dW) __oX = 0;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   726
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   727
            __byte = __byte << 1;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   728
            if (__grey > __dT) {
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   729
                __byte = __byte | 1;       /* white */
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   730
            }
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   731
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   732
            __bitCnt--;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   733
            if (__bitCnt == 0) {
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   734
                __monoBits[__dstIdx] = __byte;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   735
                __dstIdx++;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   736
                __byte = 0;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   737
                __bitCnt = 8;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   738
            }
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   739
        }
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   740
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   741
        if (__bitCnt != 8) {
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   742
            __byte = __byte << __bitCnt;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   743
            __monoBits[__dstIdx] = __byte;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   744
        }
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   745
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   746
        __oY++; __dY += __dW;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   747
        if (__oY == __dH) {
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   748
            __oY = 0;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   749
            __dY = 0;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   750
        }
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   751
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   752
        __srcIdx = __nextSrc;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   753
        __dstIdx = __nextDst;
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   754
    }
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   755
%}.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   756
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   757
    ^ monoBits
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   758
! !
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   759
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   760
!Depth4Image methodsFor:'enumerating'!
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
   761
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   762
colorsAtY:y from:xLow to:xHigh do:aBlock
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   763
    "perform aBlock for each pixel from x1 to x2 in row y.
304f026e10cd Initial revision
claus
parents:
diff changeset
   764
     The block is passed the color at each pixel.
304f026e10cd Initial revision
claus
parents:
diff changeset
   765
     This method allows slighly faster processing of an
304f026e10cd Initial revision
claus
parents:
diff changeset
   766
     image than using atX:y:, since some processing can be
304f026e10cd Initial revision
claus
parents:
diff changeset
   767
     avoided when going from pixel to pixel. However, for
304f026e10cd Initial revision
claus
parents:
diff changeset
   768
     real image processing, specialized methods should be written."
304f026e10cd Initial revision
claus
parents:
diff changeset
   769
304f026e10cd Initial revision
claus
parents:
diff changeset
   770
    |srcIndex "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   771
     byte     "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   772
     shift    "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   773
     value    "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   774
     x1       "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   775
     x2       "{ Class: SmallInteger }"
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   776
     colorArray p |
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   777
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   778
    (p := photometric) == #palette ifTrue:[
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   779
        colorArray := colorMap.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   780
    ] ifFalse:[
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   781
        colorArray := Array new:16.
803
899f7eb32ef2 support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
   782
        (p == #whiteIs0 or:[p == #blackIs0]) ifTrue:[
899f7eb32ef2 support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
   783
            0 to:15 do:[:i |
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   784
                colorArray at:(i+1) put:(Color gray:100 - (100 / 15 * i))
803
899f7eb32ef2 support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
   785
            ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   786
            p == #blackIs0 ifTrue:[
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   787
                colorArray reverse
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   788
            ]
803
899f7eb32ef2 support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
   789
        ] ifFalse:[
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   790
            0 to:15 do:[:i |
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   791
                colorArray at:(i+1) put:(self colorFromValue:i).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   792
            ].
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   793
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   794
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
   795
304f026e10cd Initial revision
claus
parents:
diff changeset
   796
    x1 := xLow.
304f026e10cd Initial revision
claus
parents:
diff changeset
   797
    x2 := xHigh.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   798
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   799
    srcIndex := (self bytesPerRow * y) + 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
   800
    srcIndex := srcIndex + (x1 // 2).
12
9f0995fac1fa *** empty log message ***
claus
parents: 4
diff changeset
   801
    x1 even ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   802
        shift := -4
12
9f0995fac1fa *** empty log message ***
claus
parents: 4
diff changeset
   803
    ] ifFalse:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   804
        shift := 0
12
9f0995fac1fa *** empty log message ***
claus
parents: 4
diff changeset
   805
    ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   806
304f026e10cd Initial revision
claus
parents:
diff changeset
   807
    x1 to:x2 do:[:x |
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   808
        shift == 0 ifTrue:[
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   809
            byte := bytes at:srcIndex.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   810
            value := byte bitAnd:16rF.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   811
            shift := -4.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   812
            srcIndex := srcIndex + 1.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   813
        ] ifFalse:[
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   814
            byte := bytes at:srcIndex.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   815
            value := (byte bitShift:-4) bitAnd:16rF.
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   816
            shift := 0
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   817
        ].
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   818
        aBlock value:x value:(colorArray at:(value + 1)).
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   819
    ]
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   820
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   821
    "Created: 7.6.1996 / 19:12:33 / cg"
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   822
    "Modified: 10.6.1996 / 10:29:39 / cg"
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   823
!
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   824
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   825
valuesAtY:y from:xLow to:xHigh do:aBlock
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   826
    "perform aBlock for each pixelValue from x1 to x2 in row y.
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   827
     The block is passed the pixelValue at each pixel.
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   828
     This method allows slighly faster processing of an
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   829
     image than using valueAtX:y:, since some processing can be
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   830
     avoided when going from pixel to pixel. However, for
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   831
     real image processing, specialized methods should be written."
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   832
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   833
    |srcIndex   "{ Class: SmallInteger }"
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   834
     byte       "{ Class: SmallInteger }"
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   835
     shift      "{ Class: SmallInteger }"
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   836
     pixelValue "{ Class: SmallInteger }"
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   837
     x1         "{ Class: SmallInteger }"
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   838
     x2         "{ Class: SmallInteger }"
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   839
     |
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   840
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   841
    x1 := xLow.
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   842
    x2 := xHigh.
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   843
    srcIndex := (self bytesPerRow * y) + 1.
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   844
    srcIndex := srcIndex + (x1 // 2).
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   845
    x1 even ifTrue:[
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   846
        shift := -4
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   847
    ] ifFalse:[
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   848
        shift := 0
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   849
    ].
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   850
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   851
    x1 to:x2 do:[:x |
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   852
        shift == 0 ifTrue:[
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   853
            byte := bytes at:srcIndex.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   854
            pixelValue := byte bitAnd:16rF.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   855
            shift := -4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   856
            srcIndex := srcIndex + 1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   857
        ] ifFalse:[
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   858
            byte := bytes at:srcIndex.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   859
            pixelValue := (byte bitShift:-4) bitAnd:16rF.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   860
            shift := 0
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   861
        ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   862
        aBlock value:x value:pixelValue.
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   863
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   864
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   865
    "Created: 7.6.1996 / 19:09:45 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   866
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
   867
304f026e10cd Initial revision
claus
parents:
diff changeset
   868
!Depth4Image methodsFor:'magnification'!
304f026e10cd Initial revision
claus
parents:
diff changeset
   869
304f026e10cd Initial revision
claus
parents:
diff changeset
   870
magnifyRowFrom:srcBytes offset:srcStart
2179
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   871
          into:dstBytes offset:dstStart factor:mX
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   872
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   873
    "magnify a single pixel row - can only magnify by integer factors.
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   874
     Specially tuned for factor 2."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   875
304f026e10cd Initial revision
claus
parents:
diff changeset
   876
%{
304f026e10cd Initial revision
claus
parents:
diff changeset
   877
    unsigned char *srcP, *dstP;
304f026e10cd Initial revision
claus
parents:
diff changeset
   878
    int _mag;
304f026e10cd Initial revision
claus
parents:
diff changeset
   879
    REGISTER int i;
304f026e10cd Initial revision
claus
parents:
diff changeset
   880
    REGISTER unsigned char _byte;
304f026e10cd Initial revision
claus
parents:
diff changeset
   881
    int _pixels;
304f026e10cd Initial revision
claus
parents:
diff changeset
   882
    REGISTER int outcnt, bits, bit;
97
dd6116883ac0 *** empty log message ***
claus
parents: 89
diff changeset
   883
    OBJ w = _INST(width);
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   884
97
dd6116883ac0 *** empty log message ***
claus
parents: 89
diff changeset
   885
    if (__bothSmallInteger(srcStart, dstStart)
dd6116883ac0 *** empty log message ***
claus
parents: 89
diff changeset
   886
     && __bothSmallInteger(w, mX)
35
f1a194c18429 *** empty log message ***
claus
parents: 23
diff changeset
   887
     && __isByteArray(srcBytes) && __isByteArray(dstBytes)) {
2179
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   888
        _mag = __intVal(mX);
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   889
        srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   890
        dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   891
        _pixels = __intVal(w);
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   892
2179
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   893
        switch (_mag) {
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   894
            case 1:
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   895
                break;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   896
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   897
            case 2:
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   898
                _byte = *srcP++;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   899
                while (_pixels) {
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   900
                    bit = (_byte >> 4) & 0xF;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   901
                    bits = (bit << 4) | bit;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   902
                    *dstP++ = bits;
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   903
2179
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   904
                    if (--_pixels) {
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   905
                        bit = _byte & 0xF;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   906
                        bits = (bit << 4) | bit;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   907
                        *dstP++ = bits;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   908
                        _byte = *srcP++;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   909
                        _pixels--;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   910
                    }
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   911
                }
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   912
                break;
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   913
2179
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   914
            default:
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   915
                bits = 0, outcnt = 0;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   916
                _byte = *srcP++;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   917
                while (_pixels) {
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   918
                    bit = (_byte >> 4) & 0xF;
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   919
2179
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   920
                    for (i=_mag; i>0; i--) {
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   921
                        bits = (bits << 4) | bit;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   922
                        outcnt++;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   923
                        if (outcnt == 2) {
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   924
                            *dstP++ = bits;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   925
                            bits = 0;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   926
                            outcnt = 0;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   927
                        }
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   928
                    }
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   929
2179
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   930
                    if (--_pixels) {
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   931
                        bit = _byte & 0xF;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   932
                        for (i=_mag; i>0; i--) {
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   933
                            bits = (bits << 4) | bit;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   934
                            outcnt++;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   935
                            if (outcnt == 2) {
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   936
                                *dstP++ = bits;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   937
                                bits = 0;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   938
                                outcnt = 0;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   939
                            }
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   940
                        }
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   941
                        _byte = *srcP++;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   942
                        _pixels--;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   943
                    }
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   944
                }
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   945
                if (outcnt) {
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   946
                    *dstP = bits << 4;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   947
                }
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   948
2179
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   949
                break;
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   950
        }
30461fd19cd5 fixed magnification by odd factor
tz
parents: 2044
diff changeset
   951
        RETURN (self);
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   952
    }
304f026e10cd Initial revision
claus
parents:
diff changeset
   953
%}
304f026e10cd Initial revision
claus
parents:
diff changeset
   954
.
304f026e10cd Initial revision
claus
parents:
diff changeset
   955
    self primitiveFailed
304f026e10cd Initial revision
claus
parents:
diff changeset
   956
! !
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   957
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   958
!Depth4Image methodsFor:'queries'!
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   959
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   960
bitsPerPixel
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   961
    "return the number of bits per pixel"
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   962
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   963
    ^ 4
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   964
!
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   965
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   966
bitsPerRow
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   967
    "return the number of bits in one scanline of the image"
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   968
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   969
    ^  width * 4
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   970
!
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   971
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   972
bytesPerRow
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   973
    "return the number of bytes in one scanline of the image"
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   974
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   975
    |nbytes|
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   976
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   977
    nbytes := width // 2.
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   978
    width odd ifTrue:[
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   979
	^ nbytes + 1
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   980
    ].
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   981
    ^ nbytes
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   982
!
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   983
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   984
usedValues
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   985
    "return a collection of color values used in the receiver."
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   986
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   987
    |useFlags usedValues|
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   988
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   989
    useFlags := Array new:16 withAll:false.
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   990
    width even ifFalse:[
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   991
        0 to:self height - 1 do:[:y |
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   992
            self valuesAtY:y from:0 to:self width - 1 do:[:x :pixel |
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   993
                useFlags at:(pixel + 1) put:true
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   994
            ]
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   995
        ].
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   996
    ] ifTrue:[
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   997
        bytes usedValues do:[:byte |
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   998
            useFlags at:(byte bitShift:-4)+1 put:true.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   999
            useFlags at:(byte bitAnd:2r1111)+1 put:true.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1000
        ].
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1001
    ].
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1002
    usedValues := OrderedCollection new.
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1003
    1 to:16 do:[:i | (useFlags at:i) ifTrue:[usedValues add:(i-1)]].
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1004
    ^ usedValues
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1005
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1006
    "Modified: 7.6.1996 / 19:09:14 / cg"
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1007
! !
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1008
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1009
!Depth4Image class methodsFor:'documentation'!
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1010
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1011
version
2186
4e4b6f9b0d27 tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
  1012
    ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.30 1998-07-27 08:18:11 cg Exp $'
280
c89f1cb9e8b9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
  1013
! !