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