Depth8Image.st
author Claus Gittinger <cg@exept.de>
Fri, 14 Jun 1996 21:34:11 +0200
changeset 859 34268959162d
parent 855 9b5aa569679f
child 875 b23541f72152
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
claus
parents: 1
diff changeset
     1
"
claus
parents: 1
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
71
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
     3
	      All Rights Reserved
5
claus
parents: 1
diff changeset
     4
claus
parents: 1
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 1
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 1
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 1
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 1
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 1
diff changeset
    10
 hereby transferred.
claus
parents: 1
diff changeset
    11
"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    12
304f026e10cd Initial revision
claus
parents:
diff changeset
    13
Image subclass:#Depth8Image
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    14
	instanceVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    15
	classVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    16
	poolDictionaries:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    17
	category:'Graphics-Images'
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    18
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    19
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    20
!Depth8Image class methodsFor:'documentation'!
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    21
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    22
copyright
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    23
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    24
 COPYRIGHT (c) 1993 by Claus Gittinger
71
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
    25
	      All Rights Reserved
5
claus
parents: 1
diff changeset
    26
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    27
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    28
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    30
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    31
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    32
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    33
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    34
!
5
claus
parents: 1
diff changeset
    35
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    36
documentation
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    37
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    38
    this class represents 256-color (8 bit / pixel) images (palette, greyscale ...).
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    39
    It mainly consists of methods already implemented in Image,
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    40
    reimplemented here for more performance.
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    41
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    42
    [author:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    43
        Claus Gittinger
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    44
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    45
    [see also:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    46
        Depth1Image Depth2Image Depth4Image Depth16Image Depth24Image
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    47
        ImageReader
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    48
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    49
! !
5
claus
parents: 1
diff changeset
    50
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
    51
!Depth8Image class methodsFor:'queries'!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
    52
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
    53
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    54
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    55
     this class - here we return 8"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    56
304f026e10cd Initial revision
claus
parents:
diff changeset
    57
    ^ 8
304f026e10cd Initial revision
claus
parents:
diff changeset
    58
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    59
    "Modified: 20.4.1996 / 23:40:22 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 75
diff changeset
    60
! !
4ba554473294 *** empty log message ***
claus
parents: 75
diff changeset
    61
4ba554473294 *** empty log message ***
claus
parents: 75
diff changeset
    62
!Depth8Image methodsFor:'accessing'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    63
304f026e10cd Initial revision
claus
parents:
diff changeset
    64
atX:x y:y
304f026e10cd Initial revision
claus
parents:
diff changeset
    65
    "retrieve a pixel at x/y; return a color.
304f026e10cd Initial revision
claus
parents:
diff changeset
    66
     Pixels start at x=0 , y=0 for upper left pixel, end at
304f026e10cd Initial revision
claus
parents:
diff changeset
    67
     x = width-1, y=height-1 for lower right pixel"
304f026e10cd Initial revision
claus
parents:
diff changeset
    68
38
2652fc96e660 *** empty log message ***
claus
parents: 35
diff changeset
    69
    |value "{ Class: SmallInteger }"
2652fc96e660 *** empty log message ***
claus
parents: 35
diff changeset
    70
     index "{ Class: SmallInteger }"|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    71
304f026e10cd Initial revision
claus
parents:
diff changeset
    72
    index := (width * y) + 1 + x.
304f026e10cd Initial revision
claus
parents:
diff changeset
    73
    value := bytes at:index.
304f026e10cd Initial revision
claus
parents:
diff changeset
    74
304f026e10cd Initial revision
claus
parents:
diff changeset
    75
    photometric == #whiteIs0 ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    76
        ^ Color gray:100 - (100 / 255 * value)
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    77
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
    78
    photometric == #blackIs0 ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    79
        ^ Color gray:(100 / 255 * value)
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    80
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
    81
    photometric ~~ #palette ifTrue:[
802
828038ff0e83 better multiplane dither
Claus Gittinger <cg@exept.de>
parents: 801
diff changeset
    82
        ^ self colorFromValue:value
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    83
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
    84
    index := value + 1.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
    85
    ^ colorMap at:index
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    86
802
828038ff0e83 better multiplane dither
Claus Gittinger <cg@exept.de>
parents: 801
diff changeset
    87
    "Modified: 8.6.1996 / 10:52:48 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    88
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    89
304f026e10cd Initial revision
claus
parents:
diff changeset
    90
atX:x y:y putValue:aPixelValue
304f026e10cd Initial revision
claus
parents:
diff changeset
    91
    "set the pixel at x/y to aPixelValue.
304f026e10cd Initial revision
claus
parents:
diff changeset
    92
     Pixels start at x=0 , y=0 for upper left pixel, end at
304f026e10cd Initial revision
claus
parents:
diff changeset
    93
     x = width-1, y=height-1 for lower right pixel"
304f026e10cd Initial revision
claus
parents:
diff changeset
    94
304f026e10cd Initial revision
claus
parents:
diff changeset
    95
    |index "{ Class: SmallInteger }"|
304f026e10cd Initial revision
claus
parents:
diff changeset
    96
304f026e10cd Initial revision
claus
parents:
diff changeset
    97
    index := (width * y) + 1 + x.
304f026e10cd Initial revision
claus
parents:
diff changeset
    98
    bytes at:index put:aPixelValue.
304f026e10cd Initial revision
claus
parents:
diff changeset
    99
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   100
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   101
valueAtX:x y:y
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   102
    "retrieve a pixel at x/y; return a pixelValue.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   103
     Pixels start at x=0 , y=0 for upper left pixel, end at
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   104
     x = width-1, y=height-1 for lower right pixel"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   105
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   106
    |index "{ Class: SmallInteger }"|
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   107
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   108
    index := (width * y) + 1 + x.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   109
    ^ bytes at:index.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   110
! !
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   111
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   112
!Depth8Image methodsFor:'converting palette images'!
304f026e10cd Initial revision
claus
parents:
diff changeset
   113
853
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   114
asGray8FormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   115
    "return an 8-bit greyForm from the 8-bit receiver image.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   116
     Redefined, since only a translation has to be done here."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   117
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   118
    |greyBits map
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   119
     mapSize "{ Class: SmallInteger }"|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   120
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   121
    greyBits := ByteArray uninitializedNew:(width * height).
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   122
304f026e10cd Initial revision
claus
parents:
diff changeset
   123
    map := ByteArray uninitializedNew:256.
304f026e10cd Initial revision
claus
parents:
diff changeset
   124
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   125
    1 to:256 do:[:i |
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   126
        map at:i put:((self colorFromValue:(i-1)) brightness * 255) rounded
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   127
    ].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   128
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   129
"/    mapSize := colorMap size.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   130
"/
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   131
"/    1 to:mapSize do:[:i |
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   132
"/        map at:i put:((colorMap at:i) brightness * 255) rounded
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   133
"/    ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   134
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   135
    bytes expandPixels:8         "xlate only"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   136
                width:width 
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   137
               height:height
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   138
                 into:greyBits
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   139
              mapping:map.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   140
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   141
    ^ self makeDeviceGrayPixmapOn:aDevice depth:8 fromArray:greyBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   142
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   143
    "Modified: 10.6.1996 / 20:10:14 / cg"
853
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   144
    "Created: 14.6.1996 / 15:23:09 / cg"
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   145
!
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   146
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   147
asGrayFormOn:aDevice
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   148
    "get a gray device form.
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   149
     Redefined, since we can do it with simple translate, 
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   150
     if the depth matches my depth."
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   151
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   152
    (aDevice visualType == #StaticGray) ifTrue:[
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   153
        (aDevice depth == 8) ifTrue:[
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   154
            ^ self asGray8FormOn:aDevice
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   155
        ].
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   156
    ].
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   157
    ^ super asGrayFormOn:aDevice
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   158
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   159
    "Created: 10.6.1996 / 18:51:19 / cg"
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   160
    "Modified: 10.6.1996 / 18:54:36 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   161
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   162
304f026e10cd Initial revision
claus
parents:
diff changeset
   163
paletteImageAsPseudoFormOn:aDevice
304f026e10cd Initial revision
claus
parents:
diff changeset
   164
    "return a pseudoForm from the palette picture. The main work is
304f026e10cd Initial revision
claus
parents:
diff changeset
   165
     in color reduction, when not all colors can be aquired."
304f026e10cd Initial revision
claus
parents:
diff changeset
   166
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   167
    |pseudoBits f gcRound has8BitImage deviceDepth
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   168
     imgMap newImage pxl
154
claus
parents: 151
diff changeset
   169
     usedColors usageCounts maxIndex map
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   170
     fit scale lastOK error 
154
claus
parents: 151
diff changeset
   171
     div 
claus
parents: 151
diff changeset
   172
     bitsPerRGB "{Class: SmallInteger }"
claus
parents: 151
diff changeset
   173
     shift      "{Class: SmallInteger }"
claus
parents: 151
diff changeset
   174
     m          "{Class: SmallInteger }" |
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   175
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   176
    Color fixColors notNil ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   177
        f := self
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   178
               asFloydSteinbergDitheredDepth8FormOn:aDevice 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   179
               colors:Color fixColors 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   180
               nRed:Color numFixRed
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   181
               nGreen:Color numFixGreen
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   182
               nBlue:Color numFixBlue.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   183
        f notNil ifTrue:[^ f].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   184
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   185
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   186
    "find used colors"
304f026e10cd Initial revision
claus
parents:
diff changeset
   187
154
claus
parents: 151
diff changeset
   188
    usedColors := bytes usedValues.    "gets us an array filled with used values"
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   189
                                       "(could use bytes asBag)"
154
claus
parents: 151
diff changeset
   190
    maxIndex := usedColors max + 1.
claus
parents: 151
diff changeset
   191
180
claus
parents: 158
diff changeset
   192
    usedColors size > 20 ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   193
        ('D8IMAGE: allocating ' , usedColors size printString , ' colors ...') infoPrintNL.
180
claus
parents: 158
diff changeset
   194
    ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   195
304f026e10cd Initial revision
claus
parents:
diff changeset
   196
    "sort by usage"
304f026e10cd Initial revision
claus
parents:
diff changeset
   197
    usageCounts := bytes usageCounts.
304f026e10cd Initial revision
claus
parents:
diff changeset
   198
    usageCounts := usedColors asArray collect:[:clr | usageCounts at:(clr + 1)].
304f026e10cd Initial revision
claus
parents:
diff changeset
   199
    usageCounts sort:[:a :b | a > b] with:usedColors.
304f026e10cd Initial revision
claus
parents:
diff changeset
   200
304f026e10cd Initial revision
claus
parents:
diff changeset
   201
    "allocate the colors (in order of usage count)"
304f026e10cd Initial revision
claus
parents:
diff changeset
   202
154
claus
parents: 151
diff changeset
   203
    imgMap := Array new:maxIndex.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   204
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   205
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   206
     first, try to get the exact colors ...
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   207
    "
154
claus
parents: 151
diff changeset
   208
    bitsPerRGB := aDevice bitsPerRGB.
claus
parents: 151
diff changeset
   209
    shift := (8 - bitsPerRGB) negated.
claus
parents: 151
diff changeset
   210
    m := (1 bitShift:bitsPerRGB) - 1.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   211
    div := m asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
   212
304f026e10cd Initial revision
claus
parents:
diff changeset
   213
    fit := true.
304f026e10cd Initial revision
claus
parents:
diff changeset
   214
    scale := 100.0 / div.       "to scale 0..255 into 0.0 .. 100.0"
304f026e10cd Initial revision
claus
parents:
diff changeset
   215
    lastOK := 0.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   216
    gcRound := 0.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   217
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   218
    usedColors do:[:aColorIndex |
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   219
        |devColor color
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   220
         r        "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   221
         g        "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   222
         b        "{Class: SmallInteger }"
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   223
         mapIndex "{Class: SmallInteger }"|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   224
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   225
        fit ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   226
            mapIndex := aColorIndex + 1.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   227
            color := colorMap at:mapIndex.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   228
            (color colorId notNil 
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   229
            and:[color device == aDevice]) ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   230
                "wow - an immediate hit"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   231
                devColor := color
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   232
            ] ifFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   233
                devColor := color exactOn:aDevice.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   234
                devColor isNil ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   235
                    "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   236
                     could not allocate color - on the first round, do a GC to flush 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   237
                     unused colors - this may help if some colors where locked by 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   238
                     already free images.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   239
                    "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   240
                    gcRound == 0 ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   241
                        ObjectMemory scavenge; finalize.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   242
                        devColor := color exactOn:aDevice.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   243
                        gcRound := 1
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   244
                    ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   245
                    devColor isNil ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   246
                        gcRound == 1 ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   247
                            CollectGarbageWhenRunningOutOfColors ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   248
                                'D8IMAGE: force GC for possible color reclamation.' infoPrintNL.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   249
                                ObjectMemory incrementalGC; finalize.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   250
                                devColor := color exactOn:aDevice.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   251
                            ].    
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   252
                            gcRound := 2
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   253
                        ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   254
                    ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   255
                ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   256
            ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   257
            (devColor notNil and:[devColor colorId notNil]) ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   258
                imgMap at:mapIndex put:devColor.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   259
                lastOK := lastOK + 1.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   260
            ] ifFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   261
                fit := false
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   262
            ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   263
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   264
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
   265
304f026e10cd Initial revision
claus
parents:
diff changeset
   266
    fit ifFalse:[
157
claus
parents: 156
diff changeset
   267
"/        |tree|
claus
parents: 156
diff changeset
   268
"/
claus
parents: 156
diff changeset
   269
"/        "/ first, create an octTree containing colors which we got ...
claus
parents: 156
diff changeset
   270
"/        tree := ColorOctree new.
claus
parents: 156
diff changeset
   271
"/
claus
parents: 156
diff changeset
   272
"/        usedColors from:1 to:lastOK do:[:aColorIndex |
claus
parents: 156
diff changeset
   273
"/            tree insert:(colorMap at:aColorIndex + 1).
claus
parents: 156
diff changeset
   274
"/        ].
claus
parents: 156
diff changeset
   275
"/
claus
parents: 156
diff changeset
   276
"/        "/ then, remap remaining, using nearest from those already allocated
claus
parents: 156
diff changeset
   277
"/
claus
parents: 156
diff changeset
   278
"/        usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |      
claus
parents: 156
diff changeset
   279
"/            |mapIndex|
claus
parents: 156
diff changeset
   280
"/
claus
parents: 156
diff changeset
   281
"/            mapIndex := aColorIndex + 1.
claus
parents: 156
diff changeset
   282
"/            imgMap at:mapIndex put:(tree findBest:(colorMap at:mapIndex))
claus
parents: 156
diff changeset
   283
"/        ].
claus
parents: 156
diff changeset
   284
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   285
        fit ifFalse:[
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   286
            ('D8IMAGE: got %1 exact colors (out of %2)' bindWith:lastOK with:usedColors size) infoPrintCR.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   287
        ].
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   288
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   289
        "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   290
         again, this time allow wrong colors (loop while increasing allowed error)
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   291
        "
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   292
        error := 1.
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   293
        [fit] whileFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   294
            fit := true.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   295
            usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   296
                |devColor color
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   297
                 r        "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   298
                 g        "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   299
                 b        "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   300
                 mapIndex "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   301
                 rMask    "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   302
                 gMask    "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   303
                 bMask    "{Class: SmallInteger }"|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   304
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   305
                fit ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   306
                    gMask := bMask := rMask := m.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   307
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   308
                    mapIndex := aColorIndex + 1.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   309
                    color := colorMap at:mapIndex.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   310
                    r := (color red * 255 / 100.0) rounded.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   311
                    g := (color green * 255 / 100.0) rounded.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   312
                    b := (color blue * 255 / 100.0) rounded.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   313
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   314
                    color := Color red:((r bitShift:shift) bitAnd:rMask) * scale
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   315
                                 green:((g bitShift:shift) bitAnd:gMask) * scale
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   316
                                  blue:((b bitShift:shift) bitAnd:bMask) * scale.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   317
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   318
                    (color colorId notNil 
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   319
                    and:[color device == aDevice]) ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   320
                        "wow - an immediate hit"
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   321
                        devColor := color.
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   322
                    ] ifFalse:[
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   323
                        devColor := color nearestOn:aDevice.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   324
                        (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   325
                            devColor := nil
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   326
                        ].
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   327
                        devColor isNil ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   328
                            "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   329
                             no free color - on the first round, do a GC to flush unused
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   330
                             colors - this may help if some colors where locked by already
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   331
                             free images.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   332
                            "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   333
                            gcRound == 0 ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   334
                                ObjectMemory scavenge; finalize.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   335
                                devColor := color nearestOn:aDevice.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   336
                                (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   337
                                    devColor := nil
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   338
                                ].
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   339
                                gcRound := 1
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   340
                            ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   341
                            devColor isNil ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   342
                                gcRound == 1 ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   343
                                    CollectGarbageWhenRunningOutOfColors ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   344
                                        'D8IMAGE: force GC for possible color reclamation.' infoPrintNL.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   345
                                        ObjectMemory incrementalGC; finalize.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   346
                                        devColor := color nearestOn:aDevice.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   347
                                        (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   348
                                            devColor := nil
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   349
                                        ].
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   350
                                    ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   351
                                    gcRound := 2
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   352
                                ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   353
                            ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   354
                        ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   355
                    ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   356
                    (devColor notNil and:[devColor colorId notNil]) ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   357
                        imgMap at:mapIndex put:devColor.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   358
                        lastOK := lastOK + 1.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   359
                    ] ifFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   360
                        fit := false
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   361
                    ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   362
                ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   363
            ].
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   364
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   365
            fit ifTrue:[
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   366
                ('D8IMAGE: remaining colors with error <= %1' bindWith:error) infoPrintCR.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   367
            ].
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   368
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   369
            error := error * 2.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   370
            error > 100 ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   371
                "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   372
                 break out, if the error becomes too big.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   373
                "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   374
                'D8IMAGE: hard color allocation problem - revert to b&w' infoPrintNL.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   375
                "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   376
                 map to b&w as a last fallback.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   377
                 (should really do a dither here)
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   378
                "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   379
                usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   380
                    |color
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   381
                     mapIndex "{ Class: SmallInteger }"|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   382
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   383
                    mapIndex := aColorIndex + 1.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   384
                    color := colorMap at:mapIndex.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   385
                    color brightness > 0.4 ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   386
                        color := Color white.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   387
                    ] ifFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   388
                        color := Color black.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   389
                    ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   390
                    imgMap at:mapIndex put:(color on:aDevice).
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   391
                ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   392
                fit := true.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   393
            ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   394
        ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   395
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   396
        error > 10 ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   397
            'D8IMAGE: not enough colors for a reasonable image' infoPrintNL
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   398
        ] ifFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   399
            'D8IMAGE: not enough colors for exact picture' infoPrintNL.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   400
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   401
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
   402
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   403
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   404
     create translation map (from image colors to allocated colorIds)
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   405
    "
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   406
    map := ByteArray new:256.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   407
    1 to:imgMap size do:[:i |
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   408
        |clr|
154
claus
parents: 151
diff changeset
   409
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   410
        (clr := imgMap at:i) notNil ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   411
            map at:i put:clr colorId
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   412
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   413
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
   414
154
claus
parents: 151
diff changeset
   415
    "
claus
parents: 151
diff changeset
   416
     does the device support 8-bit images ?
claus
parents: 151
diff changeset
   417
    "
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   418
    deviceDepth := aDevice depth.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   419
    deviceDepth == 8 ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   420
        has8BitImage := true.
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   421
    ] ifFalse:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   422
        has8BitImage := false.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   423
        aDevice supportedImageFormats do:[:fmt |
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   424
            (fmt at:#bitsPerPixel) == 8 ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   425
                has8BitImage := true.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   426
            ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   427
        ]
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   428
    ].
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   429
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   430
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   431
     finally, create a form on the device and copy (& translate)
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   432
     the pixel values
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   433
    "
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   434
    has8BitImage ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   435
        pseudoBits := ByteArray uninitializedNew:(width * height).
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   436
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   437
        bytes expandPixels:8         "xlate only"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   438
                    width:width 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   439
                   height:height
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   440
                     into:pseudoBits
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   441
                  mapping:map.
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   442
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   443
        map := nil.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   444
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   445
        f := Form width:width height:height depth:deviceDepth on:aDevice.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   446
        f isNil ifTrue:[^ nil].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   447
        f colorMap:imgMap. 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   448
        f initGC.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   449
        aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth  
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   450
                   width:width height:height
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   451
                       x:0 y:0
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   452
                    into:(f id) x:0 y:0 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   453
                   width:width height:height with:(f gcId).
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   454
        ^ f
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   455
    ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   456
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   457
    "
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   458
     slow fall back: convert into appropriate depth image,
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   459
     by looping over each pixel individually
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   460
    "
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   461
    newImage := (Image implementorForDepth:deviceDepth) new.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   462
    newImage width:width.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   463
    newImage height:height.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   464
    newImage bits:(ByteArray uninitializedNew:(height * newImage bytesPerRow)).
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   465
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   466
    0 to:height-1 do:[:row |
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   467
        0 to:width-1 do:[:col |
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   468
            pxl := self valueAtX:col y:row.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   469
            newImage atX:col y:row putValue:(map at:pxl)
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   470
        ]
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   471
    ].
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   472
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   473
    f := Form width:width height:height depth:deviceDepth on:aDevice.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   474
    f isNil ifTrue:[^ nil].
304f026e10cd Initial revision
claus
parents:
diff changeset
   475
    f colorMap:imgMap. 
304f026e10cd Initial revision
claus
parents:
diff changeset
   476
    f initGC.
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   477
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   478
    aDevice drawBits:(newImage bits) depth:deviceDepth width:width height:height
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   479
                   x:0 y:0
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   480
                into:(f id) x:0 y:0 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   481
               width:width height:height with:(f gcId).
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   482
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   483
    ^ f
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   484
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   485
    "Modified: 14.6.1996 / 20:47:29 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   486
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
   487
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   488
!Depth8Image methodsFor:'dither helpers'!
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   489
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   490
orderedDitheredBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   491
    "return the bitmap for a dithered depth-bitmap from the image;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   492
     with a constant ditherMatrix, this can be used for thresholding.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   493
     Redefined to make use of knowing that pixels are 8-bit values."
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   494
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   495
    |dH nDither   
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   496
     greyLevels greyMap1 greyMap2
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   497
     bytesPerRow  "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   498
     bytesPerOutRow  "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   499
     pixelsPerByte   "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   500
     outBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   501
     w               "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   502
     h               "{Class: SmallInteger }" |
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   503
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   504
    nDither := ditherMatrix size.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   505
    dH := nDither / dW.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   506
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   507
    w := width.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   508
    h := height.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   509
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   510
    greyLevels := 1 bitShift:depth.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   511
    pixelsPerByte := 8 / depth.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   512
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   513
    bytesPerRow := self bytesPerRow.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   514
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   515
    bytesPerOutRow := (w * depth + 7) // 8.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   516
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   517
    (outBits isNil or:[bytes isNil]) ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   518
        ^ nil
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   519
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   520
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   521
    greyMap1 := self greyMapForRange:(greyLevels-1).                    "/ the pixels
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   522
    greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   523
                                            0
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   524
                                        ] ifFalse:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   525
                                            b truncated
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   526
                                        ]
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   527
                                  ]) asByteArray.      
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   528
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   529
    greyMap2 := self greyMapForRange:(greyLevels-1).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   530
    greyMap2 := (greyMap2 collect:[:el | 
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   531
                                        el isNil ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   532
                                            0
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   533
                                        ] ifFalse:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   534
                                            ((el - el truncated)  "/ the error (0..1)
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   535
                                            * nDither) rounded
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   536
                                        ]]) asByteArray.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   537
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   538
%{
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   539
    int __dW = __intVal(dW);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   540
    int __dH = __intVal(dH);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   541
    int __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   542
    int __dT, __dO;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   543
    int __depth = __intVal(depth);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   544
    int __dstIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   545
    int __srcIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   546
    int __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   547
    int __grey, __pixel;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   548
    int __w = __intVal(w);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   549
    int __h = __intVal(h);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   550
    int __x;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   551
    int __y;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   552
    int __oX, __oY, __dY;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   553
    int __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   554
    int __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   555
    int __bytesPerRow = __intVal(bytesPerRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   556
    int __bytesPerOutRow = __intVal(bytesPerOutRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   557
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   558
    char *__outBits = __ByteArrayInstPtr(outBits)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   559
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   560
    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   561
    unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   562
    unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   563
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   564
    __oY = __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   565
    for (__y=0; __y<__h; __y++) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   566
        __nextDst = __dstIdx + __bytesPerOutRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   567
        __nextSrc = __srcIdx + __bytesPerRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   568
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   569
        __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   570
        __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   571
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   572
        __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   573
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   574
        for (__x=0; __x<__w; __x++) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   575
            __grey = __bytes[__srcIdx++];            /* 0..255 */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   576
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   577
            __pixel = __greyMap1[__grey];            /* 0..(greyLevels-1) */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   578
            __dO    = __greyMap2[__grey];            /* 0.. nDither-1) */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   579
            __dT = __ditherMatrix[__dY + __oX];
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   580
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   581
            if (__dO > __dT)                         /* dither says: next pixel */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   582
                __pixel++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   583
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   584
            __oX++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   585
            if (__oX == __dW) __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   586
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   587
            __byte = (__byte << __depth) | __pixel;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   588
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   589
            __bitCnt = __bitCnt - __depth;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   590
            if (__bitCnt == 0) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   591
                __outBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   592
                __dstIdx++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   593
                __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   594
                __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   595
            }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   596
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   597
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   598
        if (__bitCnt != 8) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   599
            __byte = __byte << __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   600
            __outBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   601
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   602
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   603
        __oY++; __dY += __dW;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   604
        if (__oY == __dH) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   605
            __oY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   606
            __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   607
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   608
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   609
        __srcIdx = __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   610
        __dstIdx = __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   611
    }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   612
%}.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   613
    ^ outBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   614
!
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   615
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   616
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   617
    "return the dithered monochrome bits for the receiver image;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   618
     with a constant ditherMatrix, this can be used for thresholding.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   619
     Redefined to make use of knowing that pixels are 8-bit values."
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   620
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   621
    |f dH nDither   
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   622
     greyMap monoBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   623
     bytesPerMonoRow "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   624
     bytesPerRow     "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   625
     w               "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   626
     h               "{Class: SmallInteger }"|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   627
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   628
    nDither := ditherMatrix size.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   629
    dH := nDither / dW.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   630
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   631
    w := width.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   632
    h := height.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   633
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   634
    bytesPerRow := self bytesPerRow.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   635
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   636
    bytesPerMonoRow := w + 7 // 8.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   637
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   638
    (monoBits isNil or:[bytes isNil]) ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   639
        ^ nil
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   640
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   641
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   642
    greyMap := self greyByteMapForRange:nDither.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   643
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   644
%{
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   645
    int __dW = __intVal(dW);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   646
    int __dH = __intVal(dH);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   647
    int __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   648
    int __dT;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   649
    int __dstIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   650
    int __srcIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   651
    int __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   652
    int __grey;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   653
    int __w = __intVal(w);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   654
    int __h = __intVal(h);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   655
    int __x;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   656
    int __y;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   657
    int __oX, __oY, __dY;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   658
    int __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   659
    int __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   660
    int __bytesPerRow = __intVal(bytesPerRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   661
    int __bytesPerMonoRow = __intVal(bytesPerMonoRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   662
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   663
    char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   664
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   665
    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   666
    unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   667
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   668
    __oY = __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   669
    for (__y=0; __y<__h; __y++) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   670
        __nextDst = __dstIdx + __bytesPerMonoRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   671
        __nextSrc = __srcIdx + __bytesPerRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   672
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   673
        __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   674
        __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   675
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   676
        __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   677
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   678
        for (__x=__w; __x>0; __x--) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   679
            __grey = __bytes[__srcIdx];   /* 0..255 */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   680
            __srcIdx++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   681
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   682
            __grey = __greyMap[__grey];
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   683
            __dT = __ditherMatrix[__dY + __oX];
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   684
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   685
            __oX++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   686
            if (__oX == __dW) __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   687
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   688
            __byte = __byte << 1;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   689
            if (__grey > __dT) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   690
                __byte = __byte | 1;           /* white */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   691
            }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   692
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   693
            __bitCnt--;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   694
            if (__bitCnt == 0) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   695
                __monoBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   696
                __dstIdx++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   697
                __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   698
                __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   699
            }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   700
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   701
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   702
        if (__bitCnt != 8) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   703
            __byte = __byte << __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   704
            __monoBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   705
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   706
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   707
        __oY++; __dY += __dW;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   708
        if (__oY == __dH) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   709
            __oY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   710
            __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   711
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   712
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   713
        __srcIdx = __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   714
        __dstIdx = __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   715
    }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   716
%}.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   717
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   718
    ^ monoBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   719
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   720
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   721
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   722
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   723
     i := Image fromFile:'bitmaps/claus.gif'.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   724
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   725
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   726
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   727
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   728
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   729
     i := Image fromFile:'bitmaps/garfield.gif'.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   730
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   731
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   732
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   733
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   734
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   735
     i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   736
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   737
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   738
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   739
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   740
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   741
     i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   742
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   743
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   744
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   745
    "Created: 7.6.1996 / 10:48:06 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   746
    "Modified: 7.6.1996 / 11:08:50 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   747
! !
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   748
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   749
!Depth8Image methodsFor:'enumerating'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   750
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   751
colorsAtY:y from:xLow to:xHigh do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   752
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   753
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   754
     This method allows slighly faster processing of an
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   755
     image than using atX:y:, since some processing can be
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   756
     avoided when going from pixel to pixel. However, for
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   757
     real image processing, specialized methods should be written."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   758
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   759
    |srcIndex "{ Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   760
     value    "{ Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   761
     x1       "{ Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   762
     x2       "{ Class: SmallInteger }"
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   763
     color colorArray scale gr|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   764
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   765
    x1 := xLow.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   766
    x2 := xHigh.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   767
    srcIndex := (width * y) + 1 + x1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   768
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   769
    colorArray := Array new:256.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   770
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   771
    photometric == #blackIs0 ifTrue:[
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   772
        scale := 100.0 / 255.0.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   773
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   774
        x1 to:x2 do:[:x |
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   775
            value := bytes at:srcIndex.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   776
            srcIndex := srcIndex + 1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   777
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   778
            color := colorArray at:value+1.
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   779
            color isNil ifTrue:[
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   780
                color := Color gray:(value * scale).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   781
                colorArray at:value+1 put:color
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   782
            ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   783
            aBlock value:x value:color
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   784
        ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   785
        ^ self
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   786
    ].
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
    photometric == #whiteIs0 ifTrue:[
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   789
        scale := 100.0 / 255.0.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   790
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   791
        x1 to:x2 do:[:x |
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   792
            value := bytes at:srcIndex.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   793
            srcIndex := srcIndex + 1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   794
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   795
            color := colorArray at:value+1.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   796
            color isNil ifTrue:[
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   797
                gr := 255 - value.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   798
                color := Color gray:(gr * scale).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   799
                colorArray at:value+1 put:color
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   800
            ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   801
            aBlock value:x value:color
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   802
        ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   803
        ^ self
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   804
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   805
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   806
    photometric ~~ #palette ifTrue:[
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   807
        x1 to:x2 do:[:x |
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   808
            value := bytes at:srcIndex.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   809
            srcIndex := srcIndex + 1.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   811
            color := colorArray at:value+1.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   812
            color isNil ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   813
                color := self colorFromValue:value.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   814
                colorArray at:value+1 put:color
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   815
            ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   816
            aBlock value:x value:color
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   817
        ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   818
        ^ self
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   819
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   820
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   821
    colorArray := colorMap.
802
828038ff0e83 better multiplane dither
Claus Gittinger <cg@exept.de>
parents: 801
diff changeset
   822
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   823
    x1 to:x2 do:[:x |
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   824
        value := bytes at:srcIndex.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   825
        srcIndex := srcIndex + 1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   826
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   827
        color := colorArray at:(value+1).
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   828
        aBlock value:x value:color
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   829
    ]
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
   830
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   831
    "Created: 7.6.1996 / 19:12:35 / cg"
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   832
    "Modified: 10.6.1996 / 10:32:07 / cg"
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   833
!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   834
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   835
valuesAtY:y from:xLow to:xHigh do:aBlock
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   836
    "perform aBlock for each pixelValue from x1 to x2 in row y.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   837
     The block is passed the pixelValue at each pixel.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   838
     This method allows slighly faster processing of an
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   839
     image than using valueAtX:y:, since some processing can be
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   840
     avoided when going from pixel to pixel. However, for
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   841
     real image processing, specialized methods should be written."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   842
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   843
    |srcIndex   "{ Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   844
     pixelValue "{ Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   845
     x1         "{ Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   846
     x2         "{ Class: SmallInteger }"|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   847
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   848
    x1 := xLow.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   849
    x2 := xHigh.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   850
    srcIndex := (width * y) + 1 + x1.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   851
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   852
    x1 to:x2 do:[:x |
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   853
        pixelValue := bytes at:srcIndex.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   854
        srcIndex := srcIndex + 1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   855
        aBlock value:x value:pixelValue 
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   856
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   857
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   858
    "Created: 7.6.1996 / 19:09:47 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   859
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
   860
12
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   861
!Depth8Image methodsFor:'image manipulations'!
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   862
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   863
flipHorizontal
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   864
    "inplace horizontal flip"
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   865
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   866
    |index  "{Class: SmallInteger }"
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   867
     h      "{Class: SmallInteger }"
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   868
     w      "{Class: SmallInteger }"
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   869
     buffer |
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   870
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   871
    w := width - 1.
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   872
    h := height - 1.
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   873
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   874
    buffer := ByteArray new:width.
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   875
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   876
    index := 1.
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   877
    0 to:h do:[:row |
71
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
   878
	buffer replaceFrom:1 to:width with:bytes startingAt:index.
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
   879
	buffer reverse.
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
   880
	bytes replaceFrom:index to:index+w with:buffer startingAt:1.
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
   881
	index := index + w + 1.
12
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   882
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   883
    "flush device info"
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   884
    self restored
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   885
!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   886
134
claus
parents: 118
diff changeset
   887
hardMagnifiedBy:extent
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   888
    "return a new image magnified by extent, aPoint.
12
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
   889
     This is the general magnification method, handling non-integral values"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   890
304f026e10cd Initial revision
claus
parents:
diff changeset
   891
    |mX mY
304f026e10cd Initial revision
claus
parents:
diff changeset
   892
     newWidth  "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   893
     newHeight "{ Class: SmallInteger }"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   894
     w         "{ Class: SmallInteger }"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   895
     h         "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   896
     newImage newBytes
304f026e10cd Initial revision
claus
parents:
diff changeset
   897
     value     "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   898
     srcRowIdx "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   899
     srcIndex  "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   900
     dstIndex  "{ Class: SmallInteger }"|
304f026e10cd Initial revision
claus
parents:
diff changeset
   901
304f026e10cd Initial revision
claus
parents:
diff changeset
   902
    mX := extent x.
304f026e10cd Initial revision
claus
parents:
diff changeset
   903
    mY := extent y.
304f026e10cd Initial revision
claus
parents:
diff changeset
   904
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
304f026e10cd Initial revision
claus
parents:
diff changeset
   905
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
304f026e10cd Initial revision
claus
parents:
diff changeset
   906
304f026e10cd Initial revision
claus
parents:
diff changeset
   907
    newWidth := (width * mX) truncated.
304f026e10cd Initial revision
claus
parents:
diff changeset
   908
    newHeight := (height * mY) truncated.
304f026e10cd Initial revision
claus
parents:
diff changeset
   909
304f026e10cd Initial revision
claus
parents:
diff changeset
   910
    newBytes := ByteArray uninitializedNew:(newWidth * newHeight).
304f026e10cd Initial revision
claus
parents:
diff changeset
   911
304f026e10cd Initial revision
claus
parents:
diff changeset
   912
    newImage := self species new.
304f026e10cd Initial revision
claus
parents:
diff changeset
   913
    newImage bits:newBytes.
304f026e10cd Initial revision
claus
parents:
diff changeset
   914
    newImage width:newWidth.
304f026e10cd Initial revision
claus
parents:
diff changeset
   915
    newImage height:newHeight.
304f026e10cd Initial revision
claus
parents:
diff changeset
   916
    newImage photometric:photometric.
304f026e10cd Initial revision
claus
parents:
diff changeset
   917
    newImage samplesPerPixel:samplesPerPixel.
304f026e10cd Initial revision
claus
parents:
diff changeset
   918
    newImage bitsPerSample:#(8).
304f026e10cd Initial revision
claus
parents:
diff changeset
   919
    newImage colorMap:colorMap copy.
304f026e10cd Initial revision
claus
parents:
diff changeset
   920
304f026e10cd Initial revision
claus
parents:
diff changeset
   921
    "walk over destination image fetching pixels from source image"
304f026e10cd Initial revision
claus
parents:
diff changeset
   922
304f026e10cd Initial revision
claus
parents:
diff changeset
   923
    mY := mY asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
   924
    mX := mX asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
   925
%{
304f026e10cd Initial revision
claus
parents:
diff changeset
   926
    unsigned char *_dstP = _ByteArrayInstPtr(newBytes)->ba_element;
304f026e10cd Initial revision
claus
parents:
diff changeset
   927
    unsigned char *_srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element;
304f026e10cd Initial revision
claus
parents:
diff changeset
   928
    unsigned char *_srcRowP;
304f026e10cd Initial revision
claus
parents:
diff changeset
   929
    int _width = _intVal(_INST(width));
304f026e10cd Initial revision
claus
parents:
diff changeset
   930
    int _w = _intVal(newWidth) - 1;
304f026e10cd Initial revision
claus
parents:
diff changeset
   931
    int _h = _intVal(newHeight) - 1;
304f026e10cd Initial revision
claus
parents:
diff changeset
   932
    int _row, _col;
304f026e10cd Initial revision
claus
parents:
diff changeset
   933
    double _mX = _floatVal(mX);
304f026e10cd Initial revision
claus
parents:
diff changeset
   934
    double _mY = _floatVal(mY);
304f026e10cd Initial revision
claus
parents:
diff changeset
   935
304f026e10cd Initial revision
claus
parents:
diff changeset
   936
    for (_row = 0; _row <= _h; _row++) {
71
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
   937
	_srcRowP = _srcP + (_width * (int)((double)_row / _mY));
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
   938
	for (_col = 0; _col <= _w; _col++) {
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
   939
	    *_dstP++ = _srcRowP[(int)((double)_col / _mX)];
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
   940
	}
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   941
    }
304f026e10cd Initial revision
claus
parents:
diff changeset
   942
%}
304f026e10cd Initial revision
claus
parents:
diff changeset
   943
.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   944
"/   the above C-code is equivalent to:
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   945
"/
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   946
"/    dstIndex := 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   947
"/    w := newWidth - 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   948
"/    h := newHeight - 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   949
"/    0 to:h do:[:row |
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   950
"/        srcRowIdx := (width * (row // mY)) + 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   951
"/        0 to:w do:[:col |
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   952
"/            srcIndex := srcRowIdx + (col // mX).
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   953
"/            value := bytes at:srcIndex.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   954
"/            newBytes at:dstIndex put:value.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   955
"/            dstIndex := dstIndex + 1
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   956
"/        ]
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   957
"/    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   958
"/
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   959
304f026e10cd Initial revision
claus
parents:
diff changeset
   960
    ^ newImage
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   961
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   962
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   963
magnifyRowFrom:srcBytes offset:srcStart  
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   964
	  into:dstBytes offset:dstStart factor:mX
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   965
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   966
    "magnify a single pixel row - can only magnify by integer factors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   967
     Specially tuned for factors 2,3 and 4."
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   968
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   969
%{
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   970
    REGISTER unsigned char *srcP, *dstP;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   971
    REGISTER unsigned char _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   972
    int _mag;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   973
    REGISTER int i;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   974
    int _pixels;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   975
    OBJ w = _INST(width);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   976
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   977
    if (__bothSmallInteger(srcStart, dstStart)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   978
     && __bothSmallInteger(w, mX)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   979
     && __isByteArray(srcBytes) && __isByteArray(dstBytes)) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   980
	_mag = _intVal(mX);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   981
	srcP = _ByteArrayInstPtr(srcBytes)->ba_element - 1 + _intVal(srcStart);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   982
	dstP = _ByteArrayInstPtr(dstBytes)->ba_element - 1 + _intVal(dstStart);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   983
	_pixels = _intVal(w);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   984
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   985
	switch (_mag) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   986
	    case 1:
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   987
		break;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   988
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   989
	    case 2:
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   990
		/* special code for common case */
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   991
		while (_pixels--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   992
		    _byte = *srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   993
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   994
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   995
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   996
		break;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   997
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   998
	    case 3:
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   999
		/* special code for common case */
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1000
		while (_pixels--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1001
		    _byte = *srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1002
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1003
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1004
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1005
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1006
		break;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1007
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1008
	    case 4:
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1009
		/* special code for common case */
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1010
		while (_pixels--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1011
		    _byte = *srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1012
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1013
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1014
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1015
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1016
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1017
		break;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1018
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1019
	    default:
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1020
		while (_pixels--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1021
		    _byte = *srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1022
		    for (i=_mag; i>0; i--)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1023
			*dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1024
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1025
		break;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1026
	}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1027
	RETURN (self);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1028
    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1029
%}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1030
.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1031
    self primitiveFailed
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1032
! !
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1033
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1034
!Depth8Image methodsFor:'private'!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1035
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1036
dither1PlaneUsingMap:map on:aDevice
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1037
    "a helper for dithering palette and greyscale images"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1038
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1039
    |f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1040
     patterns formBytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1041
     pixel0bytes pixel1bytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1042
     clr ditherPattern
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1043
     nColors       "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1044
     w             "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1045
     h             "{Class: SmallInteger }"|
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1046
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1047
    nColors := map size.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1048
    w := width.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1049
    h := height.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1050
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1051
    formBytes := ByteArray uninitializedNew:(w + 7 // 8) * h.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1052
    patterns := Array new:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1053
    pixel0bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1054
    pixel1bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1055
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1056
    "
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1057
     extract dither patterns and values to use for 1/0 bits
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1058
     in those from the dithercolors
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1059
    "
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1060
    1 to:nColors do:[:i |
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1061
	clr := (map at:i) on:aDevice.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1062
	ditherPattern := clr ditherForm.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1063
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1064
	ditherPattern isNil ifTrue:[
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1065
	    patterns at:i put:#[2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1066
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1067
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1068
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1069
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1070
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1071
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1072
				2r11111111].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1073
	    pixel0bytes at:i put:clr colorId.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1074
	    pixel1bytes at:i put:clr colorId
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1075
	] ifFalse:[
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1076
	    patterns at:i put:(ditherPattern bits).
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1077
	    pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1078
	    pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1079
	].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1080
    ].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1081
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1082
%{
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1083
    unsigned char *_srcP, *_dstP;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1084
    OBJ _patternBytes;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1085
    unsigned char _mask = 0x80;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1086
    unsigned char _outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1087
    unsigned char _last, _v, _patternBits, _p0, _p1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1088
    int _h, _w;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1089
    int _patternOffset = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1090
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1091
    _srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1092
    _dstP = _ByteArrayInstPtr(formBytes)->ba_element;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1093
    for (_h = _intVal(h); _h; _h--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1094
	_last = -1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1095
	for (_w = _intVal(w); _w; _w--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1096
	    _v = *_srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1097
	    if (_v != _last) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1098
		_patternBytes = _ArrayInstPtr(patterns)->a_element[_v];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1099
		if (__isByteArray(_patternBytes)) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1100
		    _patternBits = _ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1101
		} else if (__isArray(_patternBytes)) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1102
		    _patternBits = _intVal(_ArrayInstPtr(_patternBytes)->a_element[_patternOffset]);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1103
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1104
		_p0 = _ByteArrayInstPtr(pixel0bytes)->ba_element[_v];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1105
		_p1 = _ByteArrayInstPtr(pixel1bytes)->ba_element[_v];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1106
		_last = _v;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1107
	    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1108
	    _outBits <<= 1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1109
	    if (_patternBits & _mask)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1110
		_outBits |= _p1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1111
	    else
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1112
		_outBits |= _p0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1113
	    _mask >>= 1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1114
	    if (_mask == 0) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1115
		_mask = 0x80;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1116
		*_dstP++ = _outBits;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1117
		_outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1118
	    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1119
	}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1120
	if (_mask != 0x80) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1121
	    while (_mask != 0) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1122
		_outBits <<= 1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1123
		_mask >>= 1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1124
	    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1125
	    *_dstP++ = _outBits;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1126
	    _mask = 0x80;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1127
	    _outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1128
	}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1129
	_patternOffset++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1130
	if (_patternOffset == 8)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1131
	    _patternOffset = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1132
    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1133
%}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1134
.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1135
    f := Form width:w height:h fromArray:formBytes.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1136
    ^ f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1137
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1138
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1139
dither2PlaneUsingMap:map on:aDevice
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1140
    "a helper for dithering palette and greyscale images"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1141
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1142
    |f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1143
     patterns formBytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1144
     pixel0bytes pixel1bytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1145
     clr ditherPattern
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1146
     nColors       "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1147
     w             "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1148
     h             "{Class: SmallInteger }"|
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1149
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1150
    nColors := map size.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1151
    w := width.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1152
    h := height.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1153
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1154
    formBytes := ByteArray uninitializedNew:(w * 2 + 7 // 8) * h.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1155
    patterns := Array new:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1156
    pixel0bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1157
    pixel1bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1158
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1159
    "extract dither patterns and values to use for 1/0 bits
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1160
     in those from the dithercolors"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1161
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1162
    1 to:nColors do:[:i |
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1163
	clr := (map at:i) on:aDevice.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1164
	ditherPattern := clr ditherForm.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1165
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1166
	ditherPattern isNil ifTrue:[
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1167
	    patterns at:i put:#[2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1168
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1169
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1170
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1171
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1172
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1173
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1174
				2r11111111].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1175
	    pixel0bytes at:i put:clr colorId.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1176
	    pixel1bytes at:i put:clr colorId
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1177
	] ifFalse:[
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1178
	    patterns at:i put:(ditherPattern bits).
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1179
	    pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1180
	    pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1181
	].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1182
    ].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1183
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1184
%{
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1185
    unsigned char *_srcP, *_dstP;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1186
    OBJ _patternBytes;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1187
    unsigned char _mask = 0x80;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1188
    unsigned char _outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1189
    unsigned char _last, _v, _patternBits, _p0, _p1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1190
    int _h, _w;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1191
    int _patternOffset = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1192
    int _outCount;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1193
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1194
    _srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1195
    _dstP = _ByteArrayInstPtr(formBytes)->ba_element;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1196
    for (_h = _intVal(h); _h; _h--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1197
	_last = -1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1198
	_outCount = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1199
	for (_w = _intVal(w); _w; _w--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1200
	    _v = *_srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1201
	    if (_v != _last) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1202
		_patternBytes = _ArrayInstPtr(patterns)->a_element[_v];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1203
		if (__isByteArray(_patternBytes)) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1204
		    _patternBits = _ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1205
		} else if (__isArray(_patternBytes)) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1206
		    _patternBits = _intVal(_ArrayInstPtr(_patternBytes)->a_element[_patternOffset]);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1207
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1208
		_p0 = _ByteArrayInstPtr(pixel0bytes)->ba_element[_v];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1209
		_p1 = _ByteArrayInstPtr(pixel1bytes)->ba_element[_v];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1210
		_last = _v;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1211
	    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1212
	    _outBits <<= 2;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1213
	    if (_patternBits & _mask)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1214
		_outBits |= _p1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1215
	    else
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1216
		_outBits |= _p0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1217
	    _mask >>= 1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1218
	    _outCount++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1219
	    if (_outCount == 4) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1220
		*_dstP++ = _outBits;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1221
		_outCount = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1222
		if (_mask == 0) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1223
		    _mask = 0x80;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1224
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1225
	    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1226
	}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1227
	if (_outCount) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1228
	    do {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1229
		_outBits <<= 2;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1230
	    } while (++_outCount != 4);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1231
	    *_dstP++ = _outBits;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1232
	}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1233
	_mask = 0x80;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1234
	_outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1235
	_patternOffset++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1236
	if (_patternOffset == 8)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1237
	    _patternOffset = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1238
    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1239
%}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1240
.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1241
    f := Form width:w height:h depth:2.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1242
    f initGC.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1243
    f device drawBits:formBytes depth:2 width:w height:h x:0 y:0
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1244
		 into:f id x:0 y:0 width:w height:h with:f gcId.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1245
    ^ f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1246
! !
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1247
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1248
!Depth8Image methodsFor:'queries'!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1249
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1250
bitsPerPixel
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1251
    "return the number of bits per pixel"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1252
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1253
    ^ 8
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1254
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1255
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1256
bitsPerRow
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1257
    "return the number of bits in one scanline of the image"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1258
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1259
    ^  width * 8
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1260
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1261
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1262
bytesPerRow
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1263
    "return the number of bytes in one scanline of the image"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1264
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1265
    ^ width
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1266
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1267
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1268
usedValues
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1269
    "return a collection of color values used in the receiver."
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1270
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1271
    ^ bytes usedValues
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1272
! !
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1273
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1274
!Depth8Image class methodsFor:'documentation'!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1275
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1276
version
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
  1277
    ^ '$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.51 1996-06-14 19:34:11 cg Exp $'
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1278
! !