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