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