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