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