Image.st
author Claus Gittinger <cg@exept.de>
Sat, 02 Nov 2002 15:59:00 +0100
changeset 3759 5b083b0ad909
parent 3729 d2cd7d8585a3
child 3760 dd2ae9dd870d
permissions -rw-r--r--
fixed stupid flood-fill algorithm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     1
"
6
7ee0cfde237d *** empty log message ***
claus
parents: 5
diff changeset
     2
 COPYRIGHT (c) 1991 by Claus Gittinger
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
     3
	      All Rights Reserved
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     4
48194c26a46c Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
48194c26a46c Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
48194c26a46c Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
48194c26a46c Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
48194c26a46c Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
48194c26a46c Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
48194c26a46c Initial revision
claus
parents:
diff changeset
    11
"
48194c26a46c Initial revision
claus
parents:
diff changeset
    12
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
    13
"{ Package: 'stx:libview' }"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
    14
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    15
Object subclass:#Image
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    16
	instanceVariableNames:'bytes width height bitsPerPixel depth colorMap maxPixelValue
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    17
		rowByteSize bitsPerSample samplesPerPixel photometric device
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    18
		deviceForm monoDeviceForm fullColorDeviceForm mask
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    19
		maskedPixelsAre0 fileName imageSequence'
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    20
	classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    21
		CollectGarbageWhenRunningOutOfColors ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    22
		ImageNotFoundQuerySignal BadImageFormatQuerySignal
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
    23
		ImageSaveErrorSignal ImageLoadErrorSignal FileCreationErrorSignal
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    24
		CannotRepresentImageSignal InformationLostQuerySignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    25
		UnrepresentableColorSignal'
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    26
	poolDictionaries:''
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    27
	category:'Graphics-Images'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    28
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    29
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
    30
!Image class methodsFor:'documentation'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    31
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    32
copyright
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    33
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    34
 COPYRIGHT (c) 1991 by Claus Gittinger
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
    35
	      All Rights Reserved
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    36
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    37
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    38
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    39
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    40
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    41
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    42
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    43
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    44
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    45
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    46
documentation
48194c26a46c Initial revision
claus
parents:
diff changeset
    47
"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    48
    this class provides (some time in the future) representation
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    49
    for all kinds of images (monochrome, greyscale and color)
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    50
    and will finally replace Form. 
622
565e2301c064 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    51
    For now (only ;-) depths of 1, 2, 4, 8, 16 and 24 are supported.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    52
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    53
    An Image keeps all of its information in a device independent way, 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    54
    but may be associated to a device. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    55
    The data held keeps all information which was originally present, 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    56
    even if the display-device has lower resolution.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    57
    Therefore, it is possible to process and manipulate images without loosing 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    58
    color information.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    59
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    60
    Images may be created manually (by providing a pixel array),
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    61
    by screen capture or by reading a file (using an ImageReader).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    62
    This gives a device independent image.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    63
    For display, a device representation is required, which can be
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    64
    aquired by sending the 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
    65
	'onDevice:aDevice' 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    66
    message to the image. This will create a (possibly dithered) device-form, 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    67
    representing the image using the currently available colors.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    68
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    69
    In rare cases, an explicit monochrome representation of the image is needed 
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    70
    (X servers take monochrome icons only), this can be created by sending
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    71
    it the message 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
    72
	'monochromeOn:aDevice'.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    73
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    74
    Also, it is planned to generate another hi-color resolution version,
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    75
    which uses its own colormap and allows the use of all 256 colors on an 8bit display 
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    76
    (this is not currently implemented).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    77
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    78
    An images pixel interpretation is controlled by the photometric instance variable
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    79
    and (if that is #palette) a colorMap.
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    80
    This is in contrast to the ST-80 way, where all of this info is in the colorMap
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    81
    (and using specialized colorMaps for b&w / greyScale images).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    82
    This may change in future versions for more application compatibility.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    83
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    84
    To convert pictures from/to external file-formats, image readers are used
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    85
    which have the file-format knowledge built in. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    86
    There are readers for most common formats available 
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    87
    (see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    88
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    89
    File formats are handled by subclasses of ImageReader, which understand
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    90
    a specific format. You can add more readers, by adding an association
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    91
    such as ('.jpg' -> JPEGReader) to the class variable 'FileFormats' 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    92
    (see the classes #initialize method, which sets up some default, and the
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    93
    patches/display.rc files, which add more).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    94
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    95
    Some algorithms used here (especially dithering & color allocation) are
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    96
    experimental and far from being perfect (some are very slow). 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    97
    For now, the most common cases have been optimized and perform reasonably
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    98
    fast - however, with uncommon depth/visualType combinations, you may
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    99
    run into slower fallback methods ...
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   100
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   101
    Much more work is needed if you plan to do heavy image processing and will
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   102
    (may) be done in the future if there is a demand for it ...
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   103
    Dithering can be controlled by the DitherAlgorithm classVariable:
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   104
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   105
       DitherAlgorithm:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   106
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   107
       nil                  a simple threshold algorithm
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   108
			    (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   109
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   110
       #pattern             patterned dither
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   111
			    (for p, take dithered color to fill pixel;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   112
			     uses dithering in color-class)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   113
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   114
       #error               error diffusion dither (Floyd-Steinberg)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   115
			    planned - not yet implemented.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   116
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   117
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   118
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   119
    [instance variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   120
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   121
	width               <Integer>       the width in pixels
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   122
	height              <Integer>       the height in pixels
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   123
	bytes               <ByteArray>     the full image information
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   124
	photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   125
	samplesPerPixel     <Integer>       the number of planes
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   126
	bitsPerSample       <Array>         the number of bits per plane
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   127
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   128
	colorMap            <Array>         only if photometric is #palette;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   129
					    maps pixel values to r/g/b values.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   130
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   131
	device              <Workstation>   the device on which deviceForm,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   132
					    monoDeviceForm and lowResDeviceForm are
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   133
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   134
	deviceForm          <Form>          the device form which gives the best
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   135
					    possible aproximation of the image on
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   136
					    device using standard colors.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   137
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   138
	monoDeviceForm      <Form>          the device form which gives a monochrome
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   139
					    aproximation of the image on device.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   140
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   141
	fullColorDeviceForm <Form>          the device form which gives the best
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   142
					    possible aproximation of the image on
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   143
					    device using private colors.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   144
					    (not yet implemented)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   145
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   146
	mask                <ImageMask>     an optional mask;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   147
					    if non-nil, only pixels for which the
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   148
					    corresponding mask bit is non-zero
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   149
					    are drawn.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   150
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   151
	maskedPixelsAre0    <Boolean>       a hint for image processors and drawers
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   152
					    if true, masked pixels are known to be
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   153
					    zero in the pixel bytes.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   154
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   155
	fileName            <String>        the name of the file from which the
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   156
					    image was loaded - nil otherwise.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   157
					    Useful for image save functions
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   158
					    and for the UIPainter utility.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   159
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   160
	imageSequence                       the imageSequence, of which the
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   161
					    instance is a frame or nil, 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   162
					    if its not part of a sequence.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   163
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   164
	bitsPerPixel                        not used in ST/X
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   165
	depth                               - these have been added in instVar-slots
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   166
	maxPixelValue                       - according to the ST-80's image class.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   167
	rowByteSize                         - to allow loading of st-80 images
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   168
					    - (which are stored as instVarAt:put: expressions)
1288
9af08a658acc added ST-80 dummy instVars - allows ST-80 images stored via #storeOn:
Claus Gittinger <cg@exept.de>
parents: 1279
diff changeset
   169
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   170
    [class variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   171
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   172
	Lobby               <Registry>      keeps track of known images
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   173
					    (for resource freeing with garbage collector)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   174
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   175
	DitherAlgorithm     <Symbol>        defines how to dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   176
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   177
	NumberOfDitherColors <Integer>      defines, how many dither colors to use
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   178
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   179
	FileFormats         <Dictionary>    associates filename extensions to
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   180
					    image reader classes (now set-up in startup-file)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   181
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   182
	CollectGarbageWhenRunningOutOfColors
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   183
			    <Boolean>       if true, and we run out of available
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   184
					    device colors during creation of a
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   185
					    device image, collect garbage for
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   186
					    possible image reclamation.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   187
					    If false, proceed immediately.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   188
					    Default is true.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   189
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   190
	ImageNotFoundQuerySignal
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   191
			    <QuerySignal>   raised, if an image could not be loaded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   192
					    from a file. The parameter is the images
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   193
					    fileName. 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   194
					    A handler may return a replacement
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   195
					    image or proceed with nil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   196
					    If unhandled, a nil is returned from the
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   197
					    image creation.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   198
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   199
	BadImageFormatQuerySignal
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   200
			    <QuerySignal>   raised, if an image could not be loaded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   201
					    from a file due to a file error or
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   202
					    unsupported format. 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   203
					    A handler may return a replacement
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   204
					    image or proceed with nil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   205
					    If unhandled, a nil is returned from the
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   206
					    image creation.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   207
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   208
	ImageSaveErrorSignal
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   209
			    <Signal>        parent of errors below.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   210
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   211
	FileCreationErrorSignal
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   212
			    <Signal>        file could not be created when saving an
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   213
					    image.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   214
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   215
	CannotRepresentImageSignal
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   216
			    <Signal>        the specified ImageReader cannot represent
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   217
					    the given image.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   218
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   219
	InformationLostQuerySignal
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   220
			    <Signal>        the specified ImageReader can represent
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   221
					    the given image, but some information
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   222
					    (typically color resolution) is lost.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   223
					    If unhandled, the save proceeds as usual.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   224
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   225
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   226
    todo:
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   227
	support alpha masks
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   228
	cleanup the dithering & conversion code
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   229
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   230
    [See also:]
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   231
	Form Icon ImageReader
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   232
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   233
    [author:]
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   234
	Claus Gittinger
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   235
"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
   236
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   237
!
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   238
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   239
examples
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   240
"
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   241
    reading from a file (many formats are supported):
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   242
    (notice, that the bitmaps directory is searched for along
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   243
     the system path - therefore, you may add your own bitmap
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   244
     directory to the beginning of the path and thus override
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   245
     any default bitmaps, or make certain that your application
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   246
     finds its bitmaps - even if they are in a separate directory)
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   247
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   248
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   249
	(Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   250
									[exEnd]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   251
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   252
	(Image fromFile:'libtool/bitmaps/SmalltalkX.xbm') inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   253
									[exEnd]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   254
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   255
	(Image fromFile:'goodies/bitmaps/winBitmaps/okSmily_up.bmp') inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   256
									[exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   257
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   258
    The following examples demonstrate various depth
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   259
    and colorMap variations ...
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   260
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   261
    inline image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   262
      default: depth=1 & #blackIs0
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   263
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   264
	(Image width:8 height:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   265
	       fromArray:#( 2r11111111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   266
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   267
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   268
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   269
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   270
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   271
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   272
			    2r11111111 )) inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   273
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   274
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   275
      with #whiteIs0 photometric
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   276
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   277
	((Image width:8 height:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   278
	       fromArray:#( 2r11111111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   279
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   280
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   281
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   282
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   283
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   284
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   285
			    2r11111111 ))
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   286
	    photometric:#whiteIs0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   287
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   288
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   289
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   290
      with a colorMap
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   291
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   292
	((Image width:8 height:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   293
	       fromArray:#( 2r11111111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   294
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   295
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   296
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   297
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   298
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   299
			    2r10000001
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   300
			    2r11111111 ))
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   301
	    colorMap:(Array with:(Color red)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   302
			    with:(Color yellow)))
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   303
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   304
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   305
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   306
      a depth4 greyScale image:
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   307
      (default photometric is #blackIs0)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   308
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   309
	(Depth4Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   310
	     width:8 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   311
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   312
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   313
			    16r00 16r11 16r22 16r33
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   314
			    16r44 16r55 16r66 16r77
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   315
			    16r88 16r99 16raa 16rbb
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   316
			    16rcc 16rdd 16ree 16rff 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   317
			]) inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   318
									[exEnd]
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   319
      the same, magnified:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   320
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   321
	((Depth4Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   322
	     width:4 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   323
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   324
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   325
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   326
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   327
			    16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   328
			    16rcd 16ref 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   329
			])
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   330
	    magnifiedBy:30)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   331
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   332
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   333
      the following has the same effect:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   334
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   335
	((Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   336
	     width:4 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   337
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   338
	     depth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   339
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   340
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   341
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   342
			    16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   343
			    16rcd 16ref 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   344
			])
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   345
	    magnifiedBy:30)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   346
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   347
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   348
      with reverse grey-interpretation:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   349
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   350
	((Depth4Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   351
	     width:4 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   352
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   353
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   354
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   355
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   356
			    16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   357
			    16rcd 16ref 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   358
			])
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   359
	    photometric:#whiteIs0;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   360
	    magnifiedBy:30)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   361
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   362
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   363
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   364
      with 1-bit-per-pixel rgb interpretation:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   365
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   366
	((Depth4Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   367
	     width:4 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   368
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   369
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   370
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   371
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   372
			    16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   373
			    16rcd 16ref 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   374
			])
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   375
	    photometric:#rgb;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   376
	    samplesPerPixel:3;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   377
	    bitsPerSample:#(1 1 1);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   378
	    magnifiedBy:30)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   379
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   380
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   381
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   382
      with 1/2/1 rgb interpretation:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   383
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   384
	((Depth4Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   385
	     width:4 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   386
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   387
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   388
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   389
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   390
			    16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   391
			    16rcd 16ref 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   392
			])
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   393
	    photometric:#rgb;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   394
	    samplesPerPixel:3;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   395
	    bitsPerSample:#(1 2 1);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   396
	    magnifiedBy:30)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   397
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   398
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   399
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   400
      a 2/2/0 rgb image (i.e. no blue):
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   401
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   402
	 |i|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   403
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   404
	 i := Depth4Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   405
		    width:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   406
		    height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   407
		    fromArray:#[ 16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   408
				 16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   409
				 16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   410
				 16rcd 16ref ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   411
	 i photometric:#rgb.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   412
	 i samplesPerPixel:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   413
	 i bitsPerSample:#(2 2 0).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   414
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   415
	 i := i magnifiedBy:30.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   416
	 i inspect.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   417
									[exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   418
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   419
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   420
      a 0/0/4 rgb image (i.e. no red or green):
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   421
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   422
	 |i|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   423
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   424
	 i := Depth4Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   425
		    width:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   426
		    height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   427
		    fromArray:#[ 16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   428
				 16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   429
				 16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   430
				 16rcd 16ref ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   431
	 i photometric:#rgb.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   432
	 i samplesPerPixel:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   433
	 i bitsPerSample:#(0 0 4).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   434
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   435
	 i := i magnifiedBy:30.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   436
	 i inspect.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   437
									[exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   438
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   439
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   440
      a 2plane greyscale image:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   441
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   442
	((Depth2Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   443
	     width:4 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   444
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   445
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   446
			    4r0123
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   447
			    4r1230
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   448
			    4r2301
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   449
			    4r3012 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   450
			])
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   451
	    magnifiedBy:30)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   452
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   453
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   454
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   455
      with colors:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   456
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   457
	((Depth2Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   458
	     width:4 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   459
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   460
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   461
			    4r0123
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   462
			    4r1230
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   463
			    4r2301
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   464
			    4r3012 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   465
			])
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   466
	    colorMap:(Array with:(Color black)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   467
			    with:(Color red)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   468
			    with:(Color green)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   469
			    with:(Color blue));
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   470
	    magnifiedBy:30)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   471
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   472
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   473
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   474
      depth8 image with 3/3/2 rgb interpretation:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   475
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   476
	((Depth8Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   477
	     width:16 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   478
	     height:16
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   479
	     fromArray:(ByteArray withAll:(0 to:16rFF)))
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   480
	    photometric:#rgb;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   481
	    samplesPerPixel:3;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   482
	    bitsPerSample:#(3 3 2);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   483
	    magnifiedBy:10)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   484
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   485
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   486
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   487
      depth8 image with 2/2/2 rgb interpretation:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   488
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   489
	((Depth8Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   490
	     width:8 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   491
	     height:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   492
	     fromArray:(ByteArray withAll:(0 to:16r3F)))
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   493
	    photometric:#rgb;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   494
	    samplesPerPixel:3;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   495
	    bitsPerSample:#(2 2 2);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   496
	    magnifiedBy:10)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   497
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   498
									[exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   499
2760
94d2d524081b example added (24-bit image)
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   500
      trueColor image:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   501
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   502
	((Depth24Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   503
	     width:4 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   504
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   505
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   506
		    16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   507
		    16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   508
		    16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   509
		    16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   510
			])
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   511
	    photometric:#rgb;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   512
	    samplesPerPixel:3;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   513
	    bitsPerSample:#(8 8 8);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   514
	    magnifiedBy:30)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   515
		 inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   516
									[exEnd]
2760
94d2d524081b example added (24-bit image)
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   517
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   518
    storing - only a few formats (TIFF, XBM, XPM) currently support storing:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   519
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   520
	|img|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   521
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   522
	img := Image fromFile:'goodies/bitmaps/winBitmaps/okSmily_up.bmp'.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   523
	img saveOn:'myImage.tiff'.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   524
	(Image fromFile:'myImage.tiff') inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   525
									[exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   526
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   527
    magnifying (any factor):
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   528
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   529
	((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   530
	    magnifiedTo:(48@48))
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   531
		inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   532
									[exEnd]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   533
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   534
	((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   535
	    magnifiedBy:0.7)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   536
		inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   537
									[exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   538
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   539
    rotating:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   540
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   541
	((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   542
	    rotated:90)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   543
		inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   544
									[exEnd]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   545
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   546
	(((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   547
	    magnifiedBy:0.3@0.7) rotated:270)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   548
		inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   549
									[exEnd]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   550
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   551
	(((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   552
	    ) rotated:30)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   553
		inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   554
									[exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   555
    negative:
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   556
									[exBegin]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   557
	((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   558
	    negative)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   559
		inspect
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   560
									[exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   561
"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   562
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   563
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   564
!Image class methodsFor:'initialization'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   565
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   566
addReader:aReaderClass suffix:aSuffix
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   567
    "register an additional image reader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   568
     This is provided for subclasses, to regster themself when
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   569
     loaded (or from the startup scripts)"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   570
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   571
    self obsoleteMethodWarning.
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   572
    self addReader:aReaderClass suffix:aSuffix mimeType:nil
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   573
!
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   574
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   575
addReader:aReaderClass suffix:aSuffix mimeType:mimeType
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   576
    "register an additional image reader.
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   577
     This interface is kept for backward compatibility.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   578
     The knowledge has been concentrated in MIMETypes"
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   579
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   580
    self obsoleteMethodWarning.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   581
    MIMETypes
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   582
	defineImageType:mimeType suffix:aSuffix reader:aReaderClass
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   583
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   584
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   585
     Image addReader:GIFReader suffix:'gif'
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   586
     Image addReader:GIFReader suffix:'gif' mimeType:'image/gif'
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   587
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   588
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   589
    "Modified: 30.6.1997 / 21:59:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   590
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   591
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   592
fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   593
    "return the collection of supported file formats.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   594
     The returned dictionary maps file-extensions to image reader classes."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   595
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   596
    ^ MIMETypes fileSuffixToImageReaderMapping
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   597
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   598
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   599
     Image fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   600
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   601
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   602
    "Modified: 30.6.1997 / 22:05:58 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   603
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   604
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   605
flushDeviceImages
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   606
    "simply release all deviceForms"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   607
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   608
    Lobby do:[:anImage |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   609
	anImage restored
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   610
    ]
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   611
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   612
    "Modified: 15.6.1996 / 15:45:02 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   613
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   614
48194c26a46c Initial revision
claus
parents:
diff changeset
   615
initialize
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   616
    "initialize class constants"
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   617
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   618
    "setup tracker of known pictures"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   619
    Lobby isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   620
	Lobby := Registry new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   621
	ObjectMemory addDependent:self.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   622
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   623
	"/ define the algorithm to use for dithering - 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   624
	"/ supported values are:
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   625
	"/      #threshold
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   626
	"/      #ordered
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   627
	"/      #floydSteinberg
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   628
	"/      #burkes
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   629
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   630
	DitherAlgorithm := #floydSteinberg.   
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   631
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   632
	(Display notNil and:[Display hasGrayscales]) ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   633
	    NumberOfDitherColors := 64
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   634
	] ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   635
	    "as far as I remember, this is about the number of grey values, the eye can distinguish"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   636
	    NumberOfDitherColors := 100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   637
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   638
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   639
	"define reader classes"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   640
	self initializeFileFormatTable.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   641
	self initializeMIMETable.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   642
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   643
	CollectGarbageWhenRunningOutOfColors := false.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   644
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   645
	ImageErrorSignal := ErrorSignal newSignalMayProceed:true.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   646
	ImageErrorSignal nameClass:self message:#imageErrorSignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   647
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   648
	ImageSaveErrorSignal := ImageErrorSignal newSignalMayProceed:true.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   649
	ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   650
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   651
	FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   652
	FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   653
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   654
	CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   655
	CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   656
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   657
	ImageLoadErrorSignal := QuerySignal new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   658
	ImageLoadErrorSignal nameClass:self message:#imageLoadErrorSignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   659
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   660
	ImageNotFoundQuerySignal := QuerySignal new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   661
	ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   662
	ImageNotFoundQuerySignal parent:ImageLoadErrorSignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   663
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   664
	InformationLostQuerySignal := QuerySignal new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   665
	InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   666
	InformationLostQuerySignal parent:ImageLoadErrorSignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   667
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   668
	BadImageFormatQuerySignal := QuerySignal new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   669
	BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   670
	BadImageFormatQuerySignal parent:ImageLoadErrorSignal.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   671
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   672
	UnrepresentableColorSignal := ImageErrorSignal newSignalMayProceed:true.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   673
	UnrepresentableColorSignal nameClass:self message:#unrepresentableColorSignal.
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
   674
    ]
748
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   675
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
   676
    "Modified: / 18.5.1999 / 15:50:03 / cg"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   677
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   678
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   679
initializeFileFormatTable
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   680
    "initialize a default table to map from file extension to reader class.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   681
     The mapping here is a default needed for proper operation of ST/X;
1593
a88f08caacef commentary
Claus Gittinger <cg@exept.de>
parents: 1591
diff changeset
   682
     see the 'smalltalk.rc'/'display.rc' startup files for a real (full) map."
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   683
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   684
    MIMETypes notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   685
	MIMETypes autoload.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   686
	MIMETypes imageReaderForSuffix:'xbm'  put:XBMReader.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   687
	MIMETypes imageReaderForSuffix:'tiff' put:TIFFReader.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   688
	MIMETypes imageReaderForSuffix:'gif'  put:GIFReader.
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   689
    ].
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   690
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   691
    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   692
     Image initializeFileFormatTable
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   693
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   694
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   695
    "Modified: 30.6.1997 / 22:07:28 / cg"
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   696
!
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   697
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   698
initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   699
    "initialize a default table to map from mime type to reader class.
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   700
     The mapping here is a default needed for proper operation of ST/X;
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   701
     see the 'smalltalk.rc'/'display.rc' startup files for a real (full) map."
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   702
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   703
    MIMETypes notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   704
	MIMETypes autoload.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   705
	MIMETypes mimeTypeForSuffix:'gif'       put:'image/gif'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   706
	MIMETypes mimeTypeForSuffix:'tiff'      put:'image/tiff'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   707
	MIMETypes mimeTypeForSuffix:'tif'       put:'image/tiff'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   708
	MIMETypes mimeTypeForSuffix:'xbm'       put:'image/x-xbitmap'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   709
	MIMETypes mimeTypeForSuffix:'xpm'       put:'image/x-xpixmap'.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   710
    ].
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   711
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   712
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   713
     Image initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   714
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   715
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   716
    "Created: 27.6.1997 / 16:43:48 / cg"
1815
50212910fc13 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   717
    "Modified: 21.7.1997 / 17:33:59 / cg"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   718
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   719
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   720
update:something with:aParameter from:changedObject
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   721
    "flush all device specific stuff when restarted from a snapshot"
48194c26a46c Initial revision
claus
parents:
diff changeset
   722
48194c26a46c Initial revision
claus
parents:
diff changeset
   723
    (something == #restarted) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   724
	self flushDeviceImages
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   725
    ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   726
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   727
    "Created: 21.6.1996 / 19:47:43 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   728
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   729
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   730
!Image class methodsFor:'instance creation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   731
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   732
extent:ext
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   733
    "create a new image, given extent. 
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   734
     Assume a depth of 1, unless an explicit imageClass is the receiver."
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   735
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   736
    ^ self width:(ext x) height:(ext y)
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   737
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   738
    "Created: / 30.9.1998 / 22:31:26 / cg"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   739
    "Modified: / 30.9.1998 / 22:32:48 / cg"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   740
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   741
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   742
extent:ext depth:d
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   743
    "ST-80 compatibility"
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   744
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   745
    ^ self width:ext x height:ext y depth:d 
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   746
!
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   747
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   748
extent:ext depth:d bits:bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   749
    "ST-80 compatibility; assume 32-bit padding"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   750
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   751
    ^ self extent:ext depth:d bits:bits pad:32
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   752
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   753
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   754
extent:ext depth:d bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   755
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   756
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   757
    ^ self width:ext x height:ext y depth:d fromArray:bits pad:padding
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   758
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   759
1276
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   760
extent:ext depth:d bitsPerPixel:bpp palette:aColormap usingBits:bits
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   761
    "ST-80 compatibility"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   762
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   763
    |img|
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   764
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   765
    img := self width:ext x height:ext y depth:bpp fromArray:bits pad:32.
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   766
    img colorMap:aColormap.
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   767
    ^ img
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   768
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   769
    "Created: 25.1.1997 / 03:50:22 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   770
    "Modified: 25.1.1997 / 12:27:35 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   771
!
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   772
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   773
extent:ext depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   774
    "create & return a blank image of the given size.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   775
     ST-80 compatibility"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   776
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   777
    |newImage emptyBits|
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   778
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   779
    newImage := (self implementorForDepth:d) new.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   780
    newImage width:ext x height:ext y depth:d palette:aColormap.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   781
    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   782
    newImage bits:emptyBits.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   783
    ^ newImage
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   784
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   785
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   786
     Image extent:16@16 depth:8 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   787
     Image extent:16@16 depth:4 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   788
     Image extent:16@16 depth:2 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   789
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   790
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   791
    "Created: 6.3.1997 / 15:24:01 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   792
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   793
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   794
extent:ext depth:d palette:aColormap bits:bits
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   795
    "ST-80 compatibility"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   796
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   797
    ^ self extent:ext depth:d palette:aColormap bits:bits pad:16
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   798
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   799
    "Modified: 7.10.1996 / 11:32:16 / cg"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   800
!
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   801
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   802
extent:ext depth:d palette:aColormap bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   803
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   804
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   805
    |img|
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   806
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   807
    img := self width:ext x height:ext y depth:d fromArray:bits pad:padding.
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   808
    img colorMap:aColormap.
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   809
    ^ img
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   810
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   811
    "Modified: 7.10.1996 / 11:32:00 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   812
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   813
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   814
extent:ext fromArray:bits offset:offset
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   815
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   816
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   817
    ^ self width:ext x height:ext y fromArray:bits
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   818
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   819
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   820
fromForm:aForm
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   821
    "create & return an Image given a aForm"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   822
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   823
    ^ self fromSubForm:(0@0 extent:aForm extent) in:aForm
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   824
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   825
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   826
     |f|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   827
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   828
     f := Form width:16 height:16.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   829
     f clear.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   830
     f displayLineFromX:0 y:0 toX:15 y:15.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   831
     f inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   832
     (Image fromForm:f) inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   833
    "
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   834
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   835
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   836
     |f|
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   837
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   838
     f := Form width:16 height:16 depth:(Display depth) on:Display.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   839
     f clear.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   840
     f paint:(Color red).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   841
     f displayLineFromX:0 y:0 toX:15 y:15.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   842
     f paint:(Color green).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   843
     f displayLineFromX:15 y:0 toX:0 y:15.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   844
     f inspect.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   845
     (Image fromForm:f) inspect
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   846
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   847
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   848
    "Modified: 11.7.1996 / 11:21:42 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   849
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   850
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   851
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   852
    "create & return an Image given another image. This can be used to
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   853
     convert an image to another depth."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   854
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   855
    ^ self fromImage:anImage photometric:nil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   856
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   857
    "
3448
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   858
     |i i2 idx|
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   859
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   860
     i := Image fromFile:'/home/cg/work/stx/goodies/bitmaps/xpmBitmaps/QUESTION.xpm'.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   861
     i2 := i deepCopy.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   862
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   863
     idx := i2 colorMap indexOfPaintNearest:(Color green).
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   864
     i2 colorMap at:idx put:Color red.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   865
     i2 inspect.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   866
     i inspect.
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   867
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   868
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   869
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   870
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   871
    "create & return an Image given another image. This can be used to
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   872
     convert an image to another depth."
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   873
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   874
    (self == Image 
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   875
    or:[anImage class == self 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   876
	and:[photometricOrNil isNil or:[photometricOrNil == anImage photometric]]]) ifTrue:[^ anImage].
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   877
    ^ self new fromImage:anImage photometric:photometricOrNil.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   878
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   879
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   880
     |i1 i8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   881
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
   882
     i1 := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   883
     i8 := Depth8Image fromImage:i1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   884
     i8 inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   885
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   886
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   887
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   888
fromSubForm:aRectangle in:aForm
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   889
    "create & return an subImage given a aForm"
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   890
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   891
    |depth device vis img|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   892
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   893
    depth := aForm depth.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   894
    device := aForm device.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   895
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   896
    (device notNil and:[depth == device depth]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   897
	"/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   898
	"/ for truecolor displays, return a Depth24Image
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   899
	"/ (must do this for depth15 & depth16 displays, since
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   900
	"/  Depth16Image has no way to specify r/g/b masks ...)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   901
	"/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   902
	vis := device visualType.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   903
	(vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   904
	    depth > 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   905
		depth := 24.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   906
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   907
	].
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   908
    ].
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   909
    img := self newForDepth:depth.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   910
    device isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   911
	^ img from:aForm in:aRectangle.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   912
    ].
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   913
    ^ img from:aForm in:aRectangle
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   914
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   915
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   916
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   917
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   918
     f := Form width:16 height:16.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   919
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   920
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   921
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   922
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   923
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   924
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   925
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   926
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   927
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   928
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   929
     f := Form width:16 height:16 depth:(Display depth) on:Display.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   930
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   931
     f paint:(Color red).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   932
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   933
     f paint:(Color green).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   934
     f displayLineFromX:15 y:0 toX:0 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   935
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   936
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   937
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   938
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   939
!
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   940
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   941
fromSubImage:anImage in:aRectangle
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   942
    "create & return an Image from a rectangular area in another image. 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   943
     This can also be used to get a subimage in another depth."
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   944
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
   945
    |cls newImage|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   946
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   947
    self == Image ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   948
	cls := (self implementorForDepth:anImage depth).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   949
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   950
	cls := self.
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
   951
    ].
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
   952
    newImage := cls new.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   953
    ^ newImage fromSubImage:anImage in:aRectangle.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   954
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   955
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   956
     |i1 i8|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   957
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
   958
     i1 := Image fromFile:'goodies/bitmaps/garfield.gif'.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   959
     i8 := Depth8Image fromSubImage:i1 in:(0@0 corner:20@20).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   960
     i8 inspect
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   961
    "
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   962
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   963
     |i1 i8|
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   964
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
   965
     i1 := Image fromFile:'goodies/bitmaps/claus.gif'.
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   966
     i8 := Depth8Image fromSubImage:i1 in:(70@50 extent:50@50).
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   967
     i8 inspect
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   968
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   969
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   970
     |i1 i8|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   971
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
   972
     i1 := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   973
     i8 := Image fromSubImage:i1 in:(70@50 extent:50@50).
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   974
     i8 inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   975
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   976
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   977
    "Created: 20.9.1995 / 01:05:43 / claus"
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
   978
    "Modified: 24.4.1997 / 23:13:02 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   979
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   980
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   981
new
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   982
    "create a new image. Redefined to set the photometric to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   983
     greyScale with black being 0 as default."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   984
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   985
    ^ super new photometric:(self defaultPhotometric)
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   986
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   987
    "Modified: 10.6.1996 / 18:08:37 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   988
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   989
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   990
newForDepth:depth
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   991
    "create a new image. Redefined to set the photometric to
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   992
     greyScale with black being 0 as default."
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   993
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   994
    |cls|
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   995
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   996
    cls := self implementorForDepth:depth.
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   997
    ^ cls new photometric:(cls defaultPhotometric)
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   998
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   999
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1000
     Image newForDepth:8
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1001
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1002
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1003
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1004
width:w height:h
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1005
    "create a new image, given width, height.
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1006
     Assume a depth of 1, unless an explicit imageClass is the receiver."
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1007
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1008
    |cls|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1009
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1010
    cls := self.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1011
    cls == Image ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1012
	cls := self implementorForDepth:1
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1013
    ].
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1014
    ^ cls new width:w height:h depth:1
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1015
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1016
    "Modified: / 30.9.1998 / 22:31:40 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1017
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1018
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1019
width:w height:h depth:d
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1020
    "create a new image, given width, height and depth"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1021
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1022
    ^ (self newForDepth:d)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1023
	width:w height:h depth:d
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1024
!
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1025
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1026
width:w height:h depth:d fromArray:pixelData
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1027
    "create a new image, given width, height, depth and data.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1028
     Data must be a ByteArray containing correctly aligned bits for the specified
134
claus
parents: 132
diff changeset
  1029
     depth (8-bit padded)."
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1030
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1031
    ^ (self newForDepth:d) 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1032
	width:w height:h depth:d fromArray:pixelData
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1033
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1034
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1035
     Image width:8 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1036
	   height:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1037
	   depth:1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1038
	   fromArray:#[2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1039
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1040
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1041
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1042
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1043
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1044
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1045
		       2r00110011].
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1046
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1047
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1048
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1049
     Image width:8 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1050
	   height:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1051
	   depth:2 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1052
	   fromArray:#[4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1053
		       4r0011 4r0011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1054
		       4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1055
		       4r0011 4r0011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1056
		       4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1057
		       4r0011 4r0011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1058
		       4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1059
		       4r0011 4r0011].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1060
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1061
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1062
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1063
     Image width:8 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1064
	   height:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1065
	   depth:4 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1066
	   fromArray:#[16r00 16r01 16rf0 16rf1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1067
		       16r02 16r03 16rf2 16rf3
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1068
		       16r04 16r05 16rf4 16rf5
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1069
		       16r06 16r07 16rf6 16rf7
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1070
		       16r08 16r09 16rf8 16rf9
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1071
		       16r0a 16r0b 16rfa 16rfb
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1072
		       16r0c 16r0d 16rfc 16rfd
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1073
		       16r0e 16r0f 16rfe 16rff].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1074
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1075
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1076
    "Modified: 10.6.1996 / 18:18:10 / cg"
132
claus
parents: 125
diff changeset
  1077
!
claus
parents: 125
diff changeset
  1078
134
claus
parents: 132
diff changeset
  1079
width:w height:h depth:d fromArray:pixelData pad:padding
claus
parents: 132
diff changeset
  1080
    "create a new image, given width, height, depth and data.
claus
parents: 132
diff changeset
  1081
     Data must be a ByteArray containing correctly aligned bits for the specified
claus
parents: 132
diff changeset
  1082
     depth."
claus
parents: 132
diff changeset
  1083
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1084
    |img newBits 
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1085
     srcRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1086
     dstRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1087
     nextDstIndex "{ Class: SmallInteger }"
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1088
     srcIndex "{ Class: SmallInteger }"
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1089
     dstIndex "{ Class: SmallInteger }" |
134
claus
parents: 132
diff changeset
  1090
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1091
    img := (self newForDepth:d) width:w height:h depth:d .
134
claus
parents: 132
diff changeset
  1092
claus
parents: 132
diff changeset
  1093
    padding ~~ 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1094
	"must repad; ST/X uses byte padding, while ST-80 uses longword
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1095
	 padding. This is stupid, and may be changed in ST/X with future versions.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1096
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1097
	dstRowBytes := img bytesPerRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1098
	srcRowBytes := ((w * d + padding - 1) bitShift:-5) bitShift:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1099
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1100
	newBits := ByteArray new:(dstRowBytes * h).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1101
	srcIndex := 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1102
	dstIndex := 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1103
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1104
	1 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1105
	    nextDstIndex := dstIndex + dstRowBytes.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1106
	    newBits replaceFrom:dstIndex 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1107
			     to:(nextDstIndex - 1)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1108
			   with:pixelData
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1109
		     startingAt:srcIndex.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1110
	    srcIndex := srcIndex + srcRowBytes.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1111
	    dstIndex := nextDstIndex.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1112
	].
134
claus
parents: 132
diff changeset
  1113
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1114
	pixelData class isBytes ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1115
	    newBits := ByteArray withAll:pixelData
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1116
	] ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1117
	    newBits := pixelData
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1118
	]
134
claus
parents: 132
diff changeset
  1119
    ].
claus
parents: 132
diff changeset
  1120
    img bits:newBits.
claus
parents: 132
diff changeset
  1121
    ^ img
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1122
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1123
    "Modified: 8.6.1996 / 10:07:47 / cg"
134
claus
parents: 132
diff changeset
  1124
!
claus
parents: 132
diff changeset
  1125
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1126
width:w height:h fromArray:anArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1127
    "create a new image, given width, height. Assume a depth of 1 of the
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1128
     receiving class is Image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1129
     Data must be a ByteArray containing correctly aligned bits for depth 1
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1130
     (i.e. 8 bits per byte)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1131
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1132
    |cls d pixels|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1133
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1134
    cls := self.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1135
    cls == Image ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1136
	cls := self implementorForDepth:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1137
	d := 1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1138
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1139
	d := cls imageDepth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1140
    ].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1141
    anArray class isBytes ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1142
	pixels := ByteArray withAll:anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1143
    ] ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1144
	pixels := anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1145
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1146
    ^ cls new width:w height:h depth:d fromArray:pixels
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1147
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1148
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1149
     Image width:8 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1150
	   height:8 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1151
	   fromArray:#[2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1152
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1153
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1154
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1155
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1156
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1157
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1158
		       2r00110011].
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1159
    "
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1160
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1161
    "Modified: 8.6.1996 / 10:07:26 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1162
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1163
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1164
!Image class methodsFor:'Signal constants'!
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1165
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1166
badImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1167
    "return the (query-) signal, which is raised if some
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1168
     bitmap-image could not be loaded due to an unrecognized format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1169
     If unhandled, the image-load returns nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1170
     Otherwise, it returns whatever the handler proceeds with.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1171
     The exception gets either the images fileName or an input stream
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1172
     as parameter"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1173
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1174
    ^ BadImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1175
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1176
    "Created: 1.2.1997 / 14:40:29 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1177
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1178
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1179
cannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1180
    "return the signal, which is raised if some
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1181
     bitmap-image could not be saved in the requested format.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1182
     This happens for example, if a true color image is saved in
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1183
     xpm format or a color image saved in xbm format.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1184
     Applications should either ask the class before saving
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1185
     (via #canRepresent:) or handle the error and use an alternative
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1186
     format then."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1187
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1188
    ^ CannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1189
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1190
    "Created: 27.2.1997 / 12:24:43 / cg"
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1191
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1192
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1193
fileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1194
    "return the signal which is raised if a file could not be
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1195
     created in an image-save operation."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1196
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1197
    ^ FileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1198
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1199
    "Created: 27.2.1997 / 12:32:59 / cg"
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1200
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1201
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1202
imageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1203
    "return the parent of all image signals"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1204
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1205
    ^ ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1206
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1207
    "Created: / 30.9.1998 / 21:59:08 / cg"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1208
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1209
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1210
imageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1211
    "return the parent of all image load error signals"
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1212
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1213
    ^ ImageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1214
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1215
    "Created: / 18.5.1999 / 15:42:05 / cg"
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1216
!
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1217
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1218
imageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1219
    "return the (query-) signal, which is raised if some
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1220
     bitmap-image could not be loaded from a file.
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1221
     If unhandled, the image-load returns nil.
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1222
     Otherwise, it returns whatever the handler proceeds with.
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1223
     The exception gets the images fileName as parameter"
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1224
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1225
    ^ ImageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1226
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1227
    "Created: 7.1.1997 / 16:04:49 / cg"
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1228
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1229
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1230
imageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1231
    "return the parent signal of all image-save errors."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1232
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1233
    ^ ImageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1234
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1235
    "Created: 27.2.1997 / 12:32:23 / cg"
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1236
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1237
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1238
informationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1239
    "return the (query-) signal, which is raised if some
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1240
     bitmap-image is saved in a format which cannot represent
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1241
     the full image (for example: the images mask).
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1242
     If unhandled, the image-save proceeds.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1243
     Otherwise, the handler may show a warn box or whatever and decide
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1244
     to proceed or abort the saving."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1245
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1246
    ^ InformationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1247
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1248
    "Created: 27.2.1997 / 12:43:50 / cg"
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1249
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1250
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1251
unrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1252
    "return the signal, which is raised if some color is not
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1253
     representable in the image (when storing a pixel)."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1254
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1255
    ^ UnrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1256
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1257
    "Created: 1.2.1997 / 14:40:29 / cg"
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1258
! !
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1259
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1260
!Image class methodsFor:'cleanup'!
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1261
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1262
releaseResourcesOnDevice:aDevice
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1263
    "this is sent when a display connection is closed,
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1264
     to release all cached Images from that device"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1265
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1266
    Lobby 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1267
	unregisterAllForWhich:[:anImage | 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1268
		|ok|
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1269
		ok := anImage graphicsDevice == aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1270
		ok ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1271
		    anImage quickRelease
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1272
		].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1273
		ok
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1274
	]
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1275
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1276
    "Created: 16.1.1997 / 19:30:44 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1277
    "Modified: 16.1.1997 / 19:33:49 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1278
! !
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1279
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1280
!Image class methodsFor:'file reading'!
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1281
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1282
fromFile:aFileName
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1283
    "read an image from a file - this methods tries to find
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1284
     out the file format itself (by the extension and by contents)
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1285
     and lets the appropriate reader read the file.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1286
     Also, all bitmap directories along the searchPath are checked
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1287
     for the file; thus, you can place your private images into a
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1288
     separate directory, thereby overriding system bitmaps easily.
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1289
     If the file is unreadable or does not contain an appropriate image,
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1290
     the ImageNotFoundQuerySignal is raised, which may be handled to
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1291
     proceed with some replacement image. If unhandled, nil is returned."
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1292
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1293
    |image name pathName fn nm inStream suffix readerClass 
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1294
     mustDecompress inPipe readersErrorMsg|
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1295
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1296
    "
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1297
     before trying each reader, check if the file is readable
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1298
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1299
    name := aFileName asFilename name.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1300
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1301
    inStream := Smalltalk systemFileStreamFor:name.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1302
    inStream isNil ifTrue:[
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1303
        inStream := Smalltalk bitmapFileStreamFor:name.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1304
        inStream isNil ifTrue:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1305
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1306
            "/ this signal is a query - if noone seems to
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1307
            "/ care, return nil.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1308
            "/ However, a handler may provide a replacement.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1309
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1310
"/            ('IMAGE: ' , aFileName , ' does not exist or is not readable') infoPrintCR.
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1311
            ^ ImageNotFoundQuerySignal
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1312
                        raiseRequestWith:aFileName
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1313
                        errorString:('IMAGE [warning]: ''' , aFileName asFilename pathName, ''' does not exist or is not readable').
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1314
        ].
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1315
        name := 'bitmaps/' , name.
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1316
    ].
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1317
    inStream notNil ifTrue:[pathName := inStream pathName].
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1318
    inStream close.
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1319
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1320
    nm := name.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1321
    fn := nm asFilename.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1322
    suffix := fn suffix.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1323
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1324
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1325
    "/ handle compressed-suffix
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1326
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1327
    (#('Z' 'gz') includes:suffix) ifTrue:[
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1328
        fn := fn withoutSuffix.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1329
        nm := fn name.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1330
        suffix := fn suffix.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1331
        mustDecompress := true.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1332
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1333
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1334
    suffix isEmpty ifTrue:[
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1335
        suffix := nm.
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1336
    ].
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1337
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1338
    "/ get the imageReader class from the files extension
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1339
    "/ and ask it first
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1340
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1341
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1342
    readerClass notNil ifTrue:[
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1343
        mustDecompress == true ifTrue:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1344
            inPipe := PipeStream readingFrom:'gunzip <' , pathName.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1345
            inPipe notNil ifTrue:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1346
                [
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1347
                    image := readerClass fromStream:inPipe.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1348
                ] ensure:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1349
                    inPipe close
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1350
                ].
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1351
                image notNil ifTrue:[^ image].
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1352
            ]
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1353
        ] ifFalse:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1354
            BadImageFormatQuerySignal handle:[:ex |
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1355
                (readersErrorMsg := ex errorString) infoPrintCR.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1356
                image := nil.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1357
                ex return.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1358
            ] do:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1359
                image := readerClass fromFile:name.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1360
            ].
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1361
            image notNil ifTrue:[^ image].
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1362
        ]
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1363
    ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1364
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1365
    "
2415
fe524aa9ad5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2380
diff changeset
  1366
     no known extension (or wrong extension)
fe524aa9ad5b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2380
diff changeset
  1367
     - ask all readers if they know this format ...
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1368
     ... these look into the file, and investigate the header.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1369
     therefore, it takes a bit longer.
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1370
    "
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1371
    MIMETypes imageReaderClasses do:[:mimeReaderClass |
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1372
        (mimeReaderClass notNil 
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1373
        and:[mimeReaderClass ~~ readerClass]) ifTrue:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1374
           (mimeReaderClass isValidImageFile:name) ifTrue:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1375
                image := mimeReaderClass fromFile:name.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1376
                image notNil ifTrue:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1377
                    ^ image
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1378
                ]
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1379
            ]
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1380
        ]
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1381
    ].
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1382
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1383
    "/ nope - unknown format
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1384
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1385
    "/ this signal is a query - if noone seems to
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1386
    "/ care, return nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1387
    "/ However, a handler may provide a replacement.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1388
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1389
"/    'IMAGE: unknown image file format: ' infoPrint. aFileName infoPrintNL.
3656
11670e0e6fcb invalid format notification fixed
Claus Gittinger <cg@exept.de>
parents: 3623
diff changeset
  1390
    ^ BadImageFormatQuerySignal
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1391
                raiseRequestWith:aFileName                                                                                            
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1392
                errorString:(readersErrorMsg ? ('IMAGE [warning]: unknown image file format: ''' , aFileName asFilename pathName , '''')).
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1393
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1394
    "
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1395
     Image fromFile:'goodies/bitmaps/gifImages/claus.gif'
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1396
     Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1397
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1398
     Image fromFile:'goodies/bitmaps/winBitmaps/a11.ico'
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1399
     Image fromFile:'czech.xpm.gz'
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1400
     Image fromFile:'goodies/bitmaps/hello_world.icon'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1401
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1402
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1403
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1404
     Image fromFile:'fooBar'
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1405
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1406
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1407
    "giving a message for non-existing images:
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1408
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1409
     Image imageNotFoundQuerySignal 
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1410
     handle:[:ex |
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1411
        Transcript showCR:ex errorString.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1412
        ex proceedWith:nil
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1413
     ] do:[
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1414
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1415
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1416
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1417
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1418
    "giving a replacement for non-existing images:
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1419
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1420
     Image imageNotFoundQuerySignal 
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1421
     answer:(Image fromFile:'bitmaps/SmalltalkX.xbm')
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1422
     do:[
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
  1423
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1424
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1425
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1426
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1427
    "Modified: / 18.5.1999 / 15:48:20 / cg"
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1428
!
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1429
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1430
fromFile:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1431
    "read an image for a package from a file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1432
     The filename is assumed to be package-relative (i.e. bitmaps/filename).
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1433
     This methods tries to find out the file format itself (by the extension and by contents)
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1434
     and lets the appropriate reader read the file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1435
     Also, all bitmap directories along the searchPath are checked
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1436
     for the file; thus, you can place your private images into a
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1437
     separate directory, thereby overriding system bitmaps easily.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1438
     If the file is unreadable or does not contain an appropriate image,
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1439
     the ImageNotFoundQuerySignal is raised, which may be handled to
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1440
     proceed with some replacement image. If unhandled, nil is returned."
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1441
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1442
    ^ Smalltalk imageFromFileNamed:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1443
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1444
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1445
     Image fromFile:'goodies/bitmaps/SBrowser.xbm'
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1446
     Image fromFile:'bitmaps/SBrowser.xbm' inPackage:'stx:libtool'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1447
     Image fromFile:'garfield.gif' inPackage:'stx:goodies/bitmaps/gifImages'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1448
    "
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1449
!
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1450
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1451
fromFile:aFileName on:aDevice
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1452
    "read an image from a file and prepare a device representation.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1453
     Return nil (or whatever a handler returned), 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1454
     if the file is unreadable or does not contain an appropriate image."
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1455
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1456
    |img|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1457
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1458
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1459
    img notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1460
	^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1461
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1462
    ^ nil
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1463
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1464
    "Modified: 1.2.1997 / 14:48:07 / cg"
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1465
!
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1466
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1467
fromFile:aFileName resolution:res
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1468
    "read an image from a file and (if required) scale the image
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1469
     as appropriate (only req'd for very high resolution displays).
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1470
     Return nil (or whatever a handler returned), 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1471
     if the file is unreadable or does not contain an appropriate image."
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1472
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1473
    ^ self fromFile:aFileName resolution:res on:nil
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1474
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1475
    "Created: 19.12.1996 / 14:02:13 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1476
    "Modified: 1.2.1997 / 14:48:16 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1477
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1478
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1479
fromFile:aFileName resolution:dpi on:aDevice
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1480
    "read an image from a file and (if required) scale the image
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1481
     as appropriate (only req'd with very high resolution displays).
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1482
     Prepare a device representation.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1483
     Return nil (or whatever a handler returned), 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1484
     if the file is unreadable or does not contain an appropriate image."
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1485
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1486
    |img dev dpiH mag|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1487
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1488
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1489
    img isNil ifTrue:[^ nil].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1490
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1491
    "if the devices resolution is within +- 50% of dpi, no magnify is needed"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1492
    dev := aDevice.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1493
    dev isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1494
	"should not happen ..."
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1495
	dev := Screen current
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1496
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1497
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1498
    dev notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1499
	dpiH := dev horizontalPixelPerInch.
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1500
    ] ifFalse:[
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1501
	dpiH := 90
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1502
    ].
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1503
    ((dpi >= (dpiH * 0.75)) and:[dpi <= (dpiH * 1.5)]) ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1504
    mag := (dpiH / dpi) rounded.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1505
    mag = 0 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1506
    mag = 1 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1507
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1508
    img := img magnifiedBy:(mag @ mag).
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1509
    aDevice notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1510
	^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1511
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1512
    ^ img
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1513
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1514
    "Modified: 1.2.1997 / 14:48:20 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1515
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1516
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1517
fromStream:aStream
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1518
    "read an image from a stream - this methods tries to find
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1519
     out the file format itself (by contents)
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1520
     and lets the appropriate reader read the file.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1521
     To do this, the stream must be positionable.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1522
     Return nil (or whatever a handler returned), 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1523
     if the stream does not contain an appropriate image."
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1524
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1525
    |image|
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1526
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1527
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1528
     ask all readers if they know
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1529
     this format ...
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1530
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1531
    MIMETypes imageReaderClasses do:[:readerClass |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1532
	readerClass notNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1533
	    image := readerClass fromStream:aStream.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1534
	    image notNil ifTrue:[^ image].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1535
	]
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1536
    ].
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1537
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1538
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1539
     nope - unknown format
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1540
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1541
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1542
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1543
    ^ ImageNotFoundQuerySignal
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1544
		raiseRequestWith:aStream
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1545
		errorString:('IMAGE [warning]: unknown image file format in stream').
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1546
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1547
    "
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1548
     Image fromFile:'goodies/bitmaps/dano.tiff'
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1549
     Image fromFile:'goodies/bitmaps/test.fax'
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1550
     Image fromFile:'goodies/bitmaps/voice.tiff'
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1551
     Image fromFile:'goodies/voice.tiff'
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1552
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1553
     Image fromFile:'../fileIn/bitmaps/claus.gif'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1554
     Image fromFile:'../fileIn/bitmaps/garfield.gif'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1555
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1556
     Image fromFile:'../fileIn/bitmaps/founders.im8'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1557
     Image fromFile:'../goodies/faces/next.com/steve.face'
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1558
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1559
     Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico'
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1560
     Image fromFile:'goodies/bitmaps/globe1.xbm'
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1561
     Image fromFile:'goodies/bitmaps/globe1.xbm.Z'
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1562
     Image fromFile:'goodies/bitmaps/hello_world.icon'
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1563
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1564
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1565
    "Created: 13.9.1996 / 18:06:00 / cg"
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1566
    "Modified: 30.6.1997 / 22:03:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1567
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1568
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1569
fromStream:aStream using:aReaderClass
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1570
    "read an image from a stream, given an imageReaderClass.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1571
     Use this, if you know the files format, but it has an invalid
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1572
     extension (or non-definite header), so #fromStream: could not
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1573
     find out the images format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1574
     Return nil (or whatever a handler returned), 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1575
     if the stream does not contain an appropriate image."
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1576
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1577
    |image|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1578
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1579
    image := aReaderClass fromStream:aStream.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1580
    image notNil ifTrue:[^ image].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1581
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1582
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1583
     nope - unknown format
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1584
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1585
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1586
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1587
    ^ ImageNotFoundQuerySignal
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1588
		raiseRequestWith:aStream
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1589
		errorString:('IMAGE: unknown image file format in stream').
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1590
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1591
    "Created: 1.2.1997 / 14:46:20 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1592
    "Modified: 1.2.1997 / 14:48:53 / cg"
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1593
! !
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1594
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1595
!Image class methodsFor:'misc'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1596
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1597
ditherAlgorithm
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1598
    "return the way we dither - 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1599
	#threshold, or nil        -> no dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1600
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1601
	#error or #floydSteinberg -> errorDiffusion; much better
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1602
	#burkes                   -> errorDiffusion; even better."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1603
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1604
    ^ DitherAlgorithm
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1605
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1606
    "Created: 17.6.1996 / 18:57:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1607
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1608
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1609
ditherAlgorithm:aSymbol
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1610
    "define how to dither - 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1611
	#threshold, or nil        -> no dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1612
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1613
	#error or #floydSteinberg -> errorDiffusion; much better
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1614
	#burkes                   -> errorDiffusion; even better."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1615
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1616
    DitherAlgorithm := aSymbol
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1617
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1618
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1619
     Image dither:#pattern
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1620
     Image dither:#floydSteinberg
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1621
     Image dither:#burkes
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1622
     Image dither:nil
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1623
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1624
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1625
    "Modified: 10.6.1996 / 12:27:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1626
    "Created: 17.6.1996 / 18:57:19 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1627
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1628
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1629
numberOfDitherColors:n
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1630
    "define how many colors (i.e. patterns) to use when
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1631
     doing a pattern dither"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1632
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1633
    NumberOfDitherColors := n
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1634
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1635
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1636
orderedDitherMatrixOfSize:sz
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1637
    sz == 2 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1638
	^ #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1639
		0 2 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1640
		3 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1641
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1642
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1643
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1644
    sz == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1645
	^ #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1646
		 0  8  2 10
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1647
		12  4 14  6
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1648
		 3 11  1  9
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1649
		15  7 13  5
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1650
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1651
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1652
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1653
    sz == 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1654
	^  #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1655
		0 32  8 40    2 34 10 42
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1656
	       48 16 56 24   50 18 58 26
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1657
	       12 44  4 36   14 46  6 38    
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1658
	       60 28 52 20   62 30 54 22
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1659
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1660
		3 35 11 43    1 33  9 41
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1661
	       51 19 59 27   49 17 57 25
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1662
	       15 47  7 39   13 45  5 37    
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1663
	       63 31 55 23   61 29 53 21
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1664
	    ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1665
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1666
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1667
    ^ nil
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1668
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1669
    "Created: 7.6.1996 / 14:15:05 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1670
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1671
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1672
!Image class methodsFor:'queries'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1673
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1674
bytesPerRowForWidth:width depth:bitsPerPixel padding:padding
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1675
    "helper - return the number of bytes in one scanline of an image,
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1676
     if scanlines are to be padded to padding-bits and the depth of the image is d."
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1677
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1678
    |bitsPerRow paddedUnitsPerRow|
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1679
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1680
    bitsPerRow := width * bitsPerPixel.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1681
    paddedUnitsPerRow := bitsPerRow // padding.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1682
    ((bitsPerRow \\ padding) ~~ 0) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1683
	paddedUnitsPerRow := paddedUnitsPerRow + 1
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1684
    ].
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1685
    ^ paddedUnitsPerRow * (padding // 8)
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1686
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1687
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1688
!
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1689
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1690
defaultPhotometric
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1691
    "return the default photometric pixel interpretation"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1692
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1693
    ^ #blackIs0
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1694
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1695
    "Modified: 20.4.1996 / 23:40:41 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1696
    "Created: 10.6.1996 / 18:08:12 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1697
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1698
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1699
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1700
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1701
     this class.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1702
     Must be redefined in concrete subclasses"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1703
2913
c51ac85e9aa2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2891
diff changeset
  1704
    ^ self subclassResponsibility
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1705
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1706
    "Modified: 20.4.1996 / 23:40:41 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1707
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1708
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1709
imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1710
    "return a collection of suffixes which are recognized as image-file suffix"
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1711
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1712
    ^ MIMETypes imageFileSuffixes
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1713
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1714
    "
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1715
     Image imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1716
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1717
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1718
    "Modified: 30.6.1997 / 22:04:39 / cg"
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1719
!
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1720
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1721
imageReaderClassForMIME:mimeType
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1722
    "return an appropriate imageReader class for a given mime type;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1723
     nil if there is none (or it did not install itself)"
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1724
1801
3dff7fb2bd59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1800
diff changeset
  1725
    ^ MIMETypes imageReaderForType:mimeType
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1726
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1727
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1728
     Image imageReaderClassForMIME:'image/tiff'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1729
     Image imageReaderClassForMIME:'image/x-portable-pixmap'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1730
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1731
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1732
    "Created: 24.6.1997 / 22:32:27 / cg"
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1733
    "Modified: 30.6.1997 / 21:54:10 / cg"
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1734
!
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1735
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1736
imageReaderClassForSuffix:aSuffix
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1737
    "return an appropriate imageReader class for a given file-suffix;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1738
     nil if there is none (or it did not install itself)"
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1739
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1740
    ^ MIMETypes imageReaderForSuffix:aSuffix
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1741
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1742
    "
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1743
     Image imageReaderClassForSuffix:'tiff'
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1744
     Image imageReaderClassForSuffix:'foo'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1745
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1746
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1747
    "Modified: 30.6.1997 / 22:05:14 / cg"
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1748
!
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1749
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  1750
implementorForDepth:depth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1751
    "return the class, which best implements images of depth"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1752
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1753
    depth == 1 ifTrue:[^ Depth1Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1754
    depth == 2 ifTrue:[^ Depth2Image].
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1755
    depth <= 4 ifTrue:[^ Depth4Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1756
    depth <= 8 ifTrue:[^ Depth8Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1757
    depth <= 16 ifTrue:[^ Depth16Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1758
    depth <= 24 ifTrue:[^ Depth24Image].
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1759
    depth <= 32 ifTrue:[^ Depth32Image].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1760
    ^ self
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1761
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1762
    "Modified: 24.4.1997 / 19:04:52 / cg"
1611
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1763
!
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1764
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1765
isImageFileSuffix:aSuffix
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1766
    "return true, if the given suffix is known to be an image files suffix"
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1767
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1768
     ^ self imageFileSuffixes includes:(aSuffix asLowercase)
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1769
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1770
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1771
     Image isImageFileSuffix:'gif'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1772
     Image isImageFileSuffix:'xbm'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1773
     Image isImageFileSuffix:'foo'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1774
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1775
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1776
    "Created: 18.4.1997 / 14:55:28 / cg"
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1777
!
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1778
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1779
mimeTypeFromSuffix:suffix
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1780
    "search my suffix information for a mime type and
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1781
     return it; return nil if unknown"
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1782
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1783
    ^ MIMETypes mimeTypeForSuffix:suffix
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1784
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1785
    "
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1786
     Image mimeTypeFromSuffix:'gif'      
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1787
     Image mimeTypeFromSuffix:'tiff'    
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1788
     Image mimeTypeFromSuffix:'foobar'  
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1789
    "
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1790
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1791
    "Modified: 1.7.1997 / 00:17:27 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1792
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1793
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1794
!Image class methodsFor:'screen capture'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1795
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1796
fromScreen
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1797
    "return an image of the full screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1798
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1799
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1800
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1801
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1802
    |display|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1803
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1804
    display := Screen current.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1805
    ^ self 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1806
	fromScreen:(0@0 corner:(display width @ display height))
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1807
	on:display
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1808
	grab:true
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1809
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1810
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1811
     Image fromScreen
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1812
     Image fromScreen inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1813
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1814
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1815
    "Modified: 26.3.1997 / 10:44:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1816
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1817
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1818
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1819
    "return an image of a part of the screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1820
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1821
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1822
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1823
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1824
    ^ self 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1825
	fromScreen:aRectangle 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1826
	on:Screen current
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1827
	grab:true
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1828
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1829
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1830
     Image fromScreen:(0@0 corner:100@100)
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1831
     (Image fromScreen:(0@0 corner:100@100)) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1832
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1833
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1834
    "Modified: 26.3.1997 / 10:45:02 / cg"
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1835
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1836
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1837
fromScreen:aRectangle on:aDevice
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1838
    "return an image of a part of a screen, which may be on
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1839
     another display device.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1840
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1841
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1842
	      (use #fromScreen:on:grab: with a false grabArg then)."
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1843
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1844
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1845
	fromScreen:aRectangle 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1846
	on:aDevice 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1847
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1848
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1849
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1850
     Image fromScreen:(0@0 corner:100@100)
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1851
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1852
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1853
    "get a snapshot of your friends screen ...
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1854
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1855
     |dpy2|
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1856
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1857
     dpy2 := XWorkstation new initializeFor:'idefix:0'.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1858
     (Image fromScreen:(dpy2 bounds) on:dpy2) inspect
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1859
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1860
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1861
    "Modified: 26.3.1997 / 10:45:08 / cg"
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1862
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1863
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1864
fromScreen:aRectangle on:aDisplay grab:doGrab
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1865
    "return an image of a part of the screen, which may be on
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1866
     another Display. If the doGrab argument is true, the display
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1867
     is grabbed (i.e. blocked for others) and a camera cursor is
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1868
     shown while the readout is done.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1869
     WARNING: with doGrab true, this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1870
	      and it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1871
	      (use with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1872
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1873
    |depth vis img|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1874
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1875
    depth := aDisplay depth.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1876
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1877
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1878
    "/ for truecolor displays, return a Depth24Image
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1879
    "/ (must do this for depth15 & depth16 displays, since
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1880
    "/  Depth16Image has no way to specify r/g/b masks ...)
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1881
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1882
    vis := aDisplay visualType.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1883
    (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1884
	depth > 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1885
	    depth := 24.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1886
	]
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1887
    ].
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1888
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1889
    img := self newForDepth:depth.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1890
    ^ img fromScreen:aRectangle on:aDisplay grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1891
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
  1892
    "Modified: / 26.1.1998 / 22:23:08 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1893
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1894
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1895
fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1896
    "return an image of a part of the screen; 
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1897
     let user specify screen area.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1898
     This is the same as #fromUser - kept for backward compatibility.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1899
     Use #fromUser for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1900
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1901
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1902
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1903
2102
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1904
    |r|
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1905
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1906
    [Screen current leftButtonPressed] whileTrue:[Delay waitForSeconds:0.05].
2102
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1907
    r := Rectangle fromUser.
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1908
    r width == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1909
    r height == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1910
    ^ self fromScreen:r
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1911
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1912
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1913
     Image fromScreenArea
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1914
     Image fromScreenArea inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1915
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1916
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1917
    "Modified: / 10.9.1998 / 15:59:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1918
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1919
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1920
fromUser
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1921
    "return an image of a part of the screen; let user specify screen area.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1922
     Same as fromScreenArea, for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1923
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1924
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1925
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1926
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1927
    ^ self fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1928
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1929
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1930
     Image fromUser
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1931
     Image fromUser inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1932
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1933
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1934
    "Modified: 26.3.1997 / 10:45:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1935
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1936
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1937
fromView:aView
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1938
    "return an image taken from a views contents as currently
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1939
     on the screen. The returned image has the same depth and photometric
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1940
     as the Display. 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1941
     Notice, that for invisible or partial covered views, 
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1942
     the returned Image is NOT correct. 
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1943
     You may want to raise the view before using this method.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1944
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1945
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1946
	      (use #fromView:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1947
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1948
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1949
	fromView:aView 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1950
	grab:true
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1951
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1952
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1953
     Image fromView:(Launcher allInstances first window topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1954
     Image fromView:(BrowserView allInstances first topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1955
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1956
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1957
    "get a snapshot from whichever view is active:
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1958
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1959
     |active|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1960
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1961
     active := WindowGroup activeGroup topViews first.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1962
     (Image fromView:active) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1963
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1964
1043
0688425d02c9 Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents: 1041
diff changeset
  1965
    "Modified: 9.9.1996 / 22:41:01 / stefan"
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1966
    "Modified: 26.3.1997 / 10:45:40 / cg"
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1967
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1968
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1969
fromView:aView grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1970
    "return an image taken from a views contents as currently
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1971
     on the screen. If the doGrab argument is true, the display
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1972
     is grabbed (i.e. blocked for others) and a camera cursor is
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1973
     shown while the readout is done.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1974
     The returned image has the same depth and photometric
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1975
     as the Display. 
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1976
     Notice, that for invisible or partial covered views, 
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1977
     the returned Image is NOT correct. 
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1978
     You may want to raise the view before using this method.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1979
     WARNING: with doGrab true, this temporarily grabs the display
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1980
	      and it may not work from within a buttonMotion
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1981
	      (use with a false grabArg then)."
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  1982
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  1983
    |org device|
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  1984
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  1985
    device := aView graphicsDevice.
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  1986
    org := device translatePoint:(0@0) fromView:aView toView:nil.
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  1987
    ^ self fromScreen:(org extent:aView extent) on:device grab:doGrab
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  1988
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  1989
    "Created: / 26.3.1997 / 10:34:20 / cg"
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  1990
    "Modified: / 10.10.2001 / 14:13:29 / cg"
157
claus
parents: 154
diff changeset
  1991
! !
claus
parents: 154
diff changeset
  1992
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  1993
!Image methodsFor:'Compatibility - Squeak'!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  1994
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  1995
boundingBox
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  1996
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  1997
    ^ self bounds
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  1998
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  1999
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2000
colormapIfNeededForDepth:d
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2001
    ^ nil
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2002
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2003
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2004
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2005
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2006
fill:aRectangle fillColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2007
    "fill the rectangular area specified by aRectangle with the given color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2008
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2009
    self fillRectangle:aRectangle withColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2010
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2011
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2012
fillBlack:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2013
    "fill the rectangular area specified by aRectangle with the black color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2014
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2015
    self fillRectangle:aRectangle withColor:Color black
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2016
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2017
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2018
     |img|
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2019
     img := Image extent:100@100 depth:24.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2020
     img photometric:#rgb.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2021
     img data:(ByteArray new:100*100*3).   
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2022
     img fillWhite:(0@0 corner:100@100).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2023
     img fillBlack:(10@10 corner:90@90).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2024
     img inspect.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2025
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2026
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2027
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2028
fillWhite:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2029
    "fill the rectangular area specified by aRectangle with the white color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2030
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2031
    self fillRectangle:aRectangle withColor:Color white
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2032
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2033
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2034
isTransparentAt:aPoint
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2035
    mask isNil ifTrue:[ ^ false].
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2036
    ^ (mask pixelAt:aPoint) == 0
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2037
! !
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2038
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2039
!Image methodsFor:'Compatibility - VW'!
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2040
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2041
asCachedImage
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2042
    "return the receiver associated to the current screens device.
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2043
     For ST-80 compatibility 
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2044
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2045
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2046
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2047
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2048
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2049
!
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2050
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2051
asRetainedMedium
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2052
    "return the receiver associated to the current screens device.
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2053
     For ST-80 compatibility 
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2054
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2055
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2056
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2057
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2058
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2059
    "Created: 27.1.1997 / 15:49:08 / cg"
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2060
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2061
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2062
bounds:newBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2063
    ^ self
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2064
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2065
    "Created: 10.2.1997 / 12:44:46 / cg"
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2066
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2067
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2068
containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2069
    "in st-80, images are visualComponents ..."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2070
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2071
    ^ self bounds containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2072
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2073
    "Created: 6.3.1997 / 15:24:12 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2074
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2075
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2076
convertToPalette:aColormap renderedBy:anImageRenderer
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2077
    "this does not really mimicri the corresponding ST-80 functionality"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2078
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2079
    |monoBits convertedImage|
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2080
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2081
    aColormap size == 2 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2082
	anImageRenderer class == OrderedDither ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2083
	    monoBits := self orderedDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2084
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2085
	    monoBits := self floydSteinbergDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2086
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2087
	(((aColormap at:1) = Color black)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2088
	and:[(aColormap at:2) = Color white]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2089
	    "/ ok
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2090
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2091
	    (((aColormap at:1) = Color white)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2092
	    and:[(aColormap at:2) = Color black]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2093
		monoBits invert
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2094
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2095
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2096
	convertedImage := Depth1Image width:width height:height fromArray:monoBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2097
	convertedImage palette:aColormap.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2098
	^ convertedImage
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2099
    ].
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2100
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2101
    self error:'unimplemented operation'.
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2102
    ^ self
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2103
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2104
    "Modified: 1.3.1997 / 17:25:50 / cg"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2105
!
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2106
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2107
paintBasis
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2108
    "huh - whats that;
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2109
     I guess, I have to return Color for images without a mask,
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2110
     and CoverageValue for those with a mask; for now, always return Color"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2111
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2112
    ^ ColorValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2113
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2114
    "Created: 6.3.1997 / 15:24:19 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2115
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2116
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2117
preferredBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2118
    ^ self bounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2119
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2120
    "Created: 10.2.1997 / 12:42:36 / cg"
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2121
! !
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2122
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2123
!Image methodsFor:'accessing'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2124
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2125
bitsPerSample
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2126
    "return the number of bits per sample.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2127
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2128
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2129
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2130
    ^ Array with:self depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2131
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2132
    "Modified: 10.6.1996 / 18:04:21 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2133
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2134
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2135
colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2136
    "return the colormap"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2137
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2138
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2139
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2140
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2141
colorMap:aColorMap
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2142
    "set the colorMap; this also set the photometric to a useful default."
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2143
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2144
    |newSize "{ Class: SmallInteger }"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2145
     oldSize "{ Class: SmallInteger }"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2146
     sameColors|
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2147
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2148
    (aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2149
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2150
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2151
	"/ any change at all ?
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2152
	(newSize := aColorMap size) >= (oldSize := colorMap size) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2153
	    sameColors := true.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2154
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2155
	    1 to:oldSize do:[:idx |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2156
		(aColorMap at:idx) = (colorMap at:idx) ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2157
		    sameColors := false.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2158
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2159
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2160
	    sameColors ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2161
		colorMap := aColorMap.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2162
		^ self
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2163
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2164
	].
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2165
    ].
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2166
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2167
    colorMap := aColorMap.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2168
    colorMap notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2169
	photometric := #palette.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2170
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2171
	(photometric == #palette) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2172
	    photometric := #blackIs0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2173
	]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2174
    ].
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2175
    deviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2176
	self release
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2177
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2178
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2179
    "Modified: / 31.8.1995 / 03:05:59 / claus"
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2180
    "Modified: / 22.8.1998 / 12:29:58 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2181
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2182
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2183
colorMapFromArray: anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2184
    "set the colorMap by reading colors from an array with rgb-byte values.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2185
     The (byte-)Array argument should be of the form:
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2186
	#( red0 green0 blue0  red1 green1 blue1 ... redN greenN blueN)
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2187
     where each component must be a byteValue in 0..255."
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2188
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2189
    |colors|
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2190
    colors := OrderedCollection new.
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2191
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2192
    1 to: anArray size by: 3 do:
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2193
    [:i|
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2194
	colors add: (Color redByte: (anArray at: i) greenByte: (anArray at: i + 1) blueByte: (anArray at: i + 2))
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2195
    ].
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2196
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2197
    self colorMap: colors
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2198
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2199
    "Modified: / 22.8.1998 / 12:28:43 / cg"
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2200
!
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2201
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2202
colorMapFromRGBValueArray: anArray
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2203
    "set the colorMap by reading colors from an array with rgb-integer values.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2204
     The (integer-)Array argument should be of the form:
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2205
	#( rgb0 rgb1  ... rgbN)
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2206
     where each element must be an rgbValue in 0..FFFFFF."
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2207
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2208
    |colors|
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2209
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2210
    colors := OrderedCollection new.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2211
    anArray do:[:rgb|
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2212
	colors add: (Color rgbValue:rgb).
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2213
    ].
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2214
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2215
    self colorMap: colors
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2216
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2217
    "Created: / 22.8.1998 / 12:27:16 / cg"
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2218
    "Modified: / 22.8.1998 / 12:30:22 / cg"
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2219
!
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2220
757
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2221
container:aVisualContainer
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2222
    "ignored here - added to allow images to be used like
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2223
     VisualComponents (later, Image should inherit from it)"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2224
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2225
    "Created: 28.5.1996 / 23:43:49 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2226
    "Modified: 29.5.1996 / 10:22:23 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2227
!
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2228
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2229
depth
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2230
    "return the depth of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2231
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2232
    ^ self bitsPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2233
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2234
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2235
device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2236
    "return the device, the receiver is associated with.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2237
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2238
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2239
    ^ device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2240
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2241
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2242
extent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2243
    "return the images extent"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2244
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2245
    ^ width@height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2246
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2247
1950
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2248
fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2249
    "return the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2250
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2251
    ^ fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2252
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2253
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2254
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2255
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2256
fileName:something
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2257
    "set the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2258
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2259
    fileName := something.
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2260
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2261
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2262
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2263
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2264
fullColorId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2265
    "return the id of the full color image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2266
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2267
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2268
    fullColorDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2269
    ^ fullColorDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2270
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2271
728
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2272
graphicsDevice
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2273
    "same as #device - for ST-80 compatibility"
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2274
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2275
    ^ device
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2276
!
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
  2277
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2278
height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2279
    "return the height of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2280
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2281
    ^ height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2282
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2283
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2284
id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2285
    "return the id of the image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2286
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2287
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2288
    deviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2289
    ^ deviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2290
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2291
2081
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2292
imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2293
    "return the frameSequence of which this image is a part of;
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2294
     nil if it is not part of a sequence."
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2295
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2296
    ^ imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2297
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2298
    "Created: / 1.4.1998 / 14:43:00 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2299
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2300
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2301
imageSequence:aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2302
    "private entry for imageReaders - set the frameSequence of which
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2303
     this image is a part of"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2304
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2305
    imageSequence := aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2306
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2307
    "Created: / 1.4.1998 / 14:42:36 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2308
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2309
896
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2310
mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2311
    ^ mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2312
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2313
    "Created: 21.6.1996 / 12:57:44 / cg"
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2314
!
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2315
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2316
mask:anotherImage
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2317
    "set the images mask - currently, this may be nil or a Depth1Image.
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2318
     (it is planned to support alpha information in a Depth8 maskImage in
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2319
      the near future).
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2320
     For depth1 masks: each pixel of the image where a corresponding
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2321
		       1-bit is present in the mask will be drawn;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2322
		       0-bit mask pixels lead to transparent pixels.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2323
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2324
     For depth8 masks: (future):
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2325
		       each pixel specifies the alpha value (0..255),
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2326
		       which specifies the transparency of that pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2327
		       0 means completely transparent, 255 means completely
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2328
		       opaque. The 1-plane mask is a special case of this,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2329
		       interpreting a 0 as a 0 alpha value and 1's as an
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2330
		       alpha value of 255."
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2331
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2332
    mask := anotherImage.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2333
    maskedPixelsAre0 := false.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2334
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2335
    "Created: 27.6.1996 / 17:45:22 / cg"
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2336
    "Modified: 12.4.1997 / 12:04:39 / cg"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2337
!
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2338
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2339
maskedPixelsAre0
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2340
    "return true if masked pixels have been cleared to zero"
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2341
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2342
    ^ maskedPixelsAre0 == true
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2343
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2344
    "Modified: / 22.8.1998 / 11:27:22 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2345
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2346
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2347
maskedPixelsAre0:aBoolean
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2348
    "set/clear the flag which states if masked pixels
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2349
     have been set to zero. Knowing this to be true allows
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2350
     faster drawing of the image later; (however, not setting
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2351
     it will still produce correct output).
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2352
     This flag is typically set by image readers."
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2353
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2354
    maskedPixelsAre0 := aBoolean
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2355
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2356
    "Modified: 12.4.1997 / 12:08:42 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2357
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2358
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2359
monochromeId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2360
    "return the id of the monochrome image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2361
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2362
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2363
    monoDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2364
    ^ monoDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2365
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2366
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2367
palette 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2368
    "return the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2369
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2370
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2371
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2372
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2373
palette:aColormap 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2374
    "set the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2375
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2376
    self colorMap:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2377
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2378
    "Created: 1.2.1996 / 15:09:25 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2379
    "Modified: 8.6.1996 / 09:54:02 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2380
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2381
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2382
photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2383
    "return the photometric, a symbol such as #palette, #rgb etc."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2384
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2385
    ^ photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2386
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2387
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2388
samplesPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2389
    "return the number of samples per pixel in the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2390
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2391
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2392
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2393
    ^ 1
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2394
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2395
    "Modified: 10.6.1996 / 18:03:30 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2396
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2397
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2398
width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2399
    "return the width of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2400
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2401
    ^ width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2402
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2403
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  2404
!Image methodsFor:'accessing-pixels'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2405
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2406
at:aPoint
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2407
    "WARNING: for now, this returns a pixels color 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2408
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2409
     In the future, this will return a pixel value (ST-80 compatibility)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2410
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2411
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2412
     retrieve the pixel at aPoint; return a color.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2413
     Pixels start at 0@0 for upper left pixel, end at
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2414
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2415
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2416
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2417
     (it is meant to access individual pixels - for example, in a bitmap editor)"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2418
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2419
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2420
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2421
    self obsoleteMethodWarning:'Image [warning]: the Image>>at: will change semantics soon; use #colorAt:'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2422
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2423
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2424
    "Modified: / 21.6.1997 / 13:10:17 / cg"
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2425
    "Modified: / 9.1.1998 / 20:33:52 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2426
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2427
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2428
at:aPoint put:aColor
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2429
    "WARNING: for now, this expects a pixels color 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2430
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2431
     In the future, this will expect a pixel value (ST-80 compatibility)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2432
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2433
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2434
     set the pixel at aPoint to aColor.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2435
     Pixels start at 0@0 for the upper left pixel, end at
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2436
     (width-1)@(height-1) for lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2437
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2438
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2439
     (it is meant to access individual pixels - for example, in a bitmap editor)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2440
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2441
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2442
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2443
    self obsoleteMethodWarning:'Image [warning]: the Image>>at:put: will change semantics soon; use #colorAt:put:'.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2444
    ^ self colorAtX:aPoint x y:aPoint y put:aColor
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2445
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2446
    "Modified: / 21.6.1997 / 13:16:02 / cg"
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2447
    "Modified: / 9.1.1998 / 20:34:15 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2448
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2449
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2450
atImageAndMask:aPoint put:aColorOrPixelOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2451
    "set the pixel at x/y to aColor.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2452
     If aColor is a mask color (i.e. Color noColor) the mask pixel will be set to 0 (transparent),
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2453
     otherwise to 1. Nil is treated like noColor.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2454
     (used by the bitmap editor)"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2455
2523
4c197af8cc50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2502
diff changeset
  2456
    |maskVal|
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2457
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2458
    (aColorOrPixelOrNil notNil and:[aColorOrPixelOrNil ~= Color noColor]) ifTrue:[   
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2459
	maskVal := 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2460
	aColorOrPixelOrNil isInteger ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2461
	    self pixelAt:aPoint put:aColorOrPixelOrNil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2462
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2463
	    self colorAt:aPoint put:aColorOrPixelOrNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2464
	]
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2465
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2466
	maskVal := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2467
	self pixelAt:aPoint put:0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2468
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2469
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2470
	mask pixelAt:aPoint put:maskVal
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2471
    ].  
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2472
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2473
    "Modified: / 30.9.1998 / 22:42:44 / cg"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2474
!
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2475
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2476
atImageAndMask:aPoint putValue:aPixelValueOrNil
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2477
    "set the pixel at x/y to aColor.
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2478
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2479
     otherwise to 1.
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2480
     (used by the bitmap editor)"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2481
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2482
    |pixVal maskVal|
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2483
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2484
    aPixelValueOrNil notNil ifTrue:[   
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2485
	pixVal := aPixelValueOrNil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2486
	maskVal := 1.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2487
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2488
	pixVal := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2489
	maskVal := 0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2490
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2491
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2492
	mask pixelAt:aPoint put:maskVal
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2493
    ].  
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2494
    self pixelAt:aPoint put:pixVal
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2495
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2496
    "Modified: / 30.9.1998 / 22:42:44 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2497
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2498
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2499
atPoint:aPoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2500
    "ST-80 compatibility: return the pixelValue at:aPoint."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2501
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2502
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2503
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2504
    "Modified: 24.4.1997 / 16:18:44 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2505
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2506
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2507
atPoint:aPoint put:aPixelValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2508
    "ST-80 compatibility: set the pixelValue at:aPoint."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2509
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2510
    ^ self pixelAtX:aPoint x y:aPoint y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2511
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2512
    "Modified: 24.4.1997 / 17:17:59 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2513
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2514
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2515
atX:x y:y
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2516
    "WARNING: for now, this returns a pixels color 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2517
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2518
     In the future, this will return a pixel value (ST-80 compatibility)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2519
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2520
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2521
     Retrieve a pixel at x/y; return a color.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2522
     Pixels start at 0@0 for upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2523
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2524
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2525
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2526
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2527
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2528
    'Image [warning]: the Image>>atX:y: will change semantics soon; use #colorAtX:y:' infoPrintCR.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2529
    ^ self colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2530
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2531
    "Modified: 21.6.1997 / 13:10:32 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2532
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2533
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2534
atX:x y:y put:aColor
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2535
    "WARNING: for now, this expects a pixels color 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2536
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2537
     In the future, this will expect a pixel value (ST-80 compatibility)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2538
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2539
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2540
     set the pixel at x/y to aColor.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2541
     Pixels start at 0@0 for the upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2542
     (width-1)@(height-1) for the lower right pixel.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2543
     This method checks if the color can be stored in the image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2544
     (i.e. if the receiver is a palette image, the color must be present in there).
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2545
     You should not use this method for image-processing, it is very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2546
     (it is meant to access individual pixels - for example, in a bitmap editor)"
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2547
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2548
    'Image [warning]: the Image>>atX:y:put: will change semantics soon; use #colorAtX:y:put:' infoPrintCR.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2549
    ^ self colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2550
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2551
    "Modified: 21.6.1997 / 13:10:44 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2552
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2553
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2554
atX:x y:y putValue:aPixelValue
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2555
    "set the pixel at x/y to aPixelValue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2556
     The interpretation of the pixelValue depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2557
     and the colormap. (see also: Image>>atX:y:put:)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2558
     Pixels start at 0@0 for the upper left pixel, end at
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2559
     (width-1) @ (height-1) for the lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2560
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2561
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2562
     (it is meant to access individual pixels - for example, in a bitmap editor)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2563
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2564
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2565
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2566
    self obsoleteMethodWarning:'use #pixelAtX:y:put:'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2567
    ^ self pixelAtX:x y:y put:aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2568
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2569
    "Modified: 24.4.1997 / 17:15:45 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2570
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2571
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2572
bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2573
    "return the raw image data; depending on the photometric,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2574
     this has to be interpreted as monochrome, greyscale,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2575
     palette or rgb data. It is also packed to be dense, so
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2576
     a 4 bitPerSample palette image will store 2 pixels per byte."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2577
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2578
    ^ bytes
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2579
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2580
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2581
colorAt:aPoint
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2582
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2583
     Pixels start at 0@0 for upper left pixel, end at
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2584
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2585
     You should not use this method for image-processing, its
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2586
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2587
     (it is meant to access individual pixels - for example, in a bitmap editor)"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2588
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2589
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2590
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2591
    "Created: 24.4.1997 / 17:02:31 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2592
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2593
1962
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2594
colorAt: aPoint put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2595
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2596
    self colorAtX: aPoint x y: aPoint y put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2597
!
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2598
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2599
colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2600
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2601
     Pixels start at 0@0 for upper left pixel, end at
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2602
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2603
     You should not use this method for image-processing, its
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2604
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2605
     (it is meant to access individual pixels - for example, in a bitmap editor)"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2606
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2607
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2608
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2609
    pixel := self pixelAtX:x y:y.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2610
    ^ self colorFromValue:pixel
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2611
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2612
    "Modified: 24.4.1997 / 16:18:53 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2613
    "Created: 24.4.1997 / 17:00:52 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2614
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2615
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2616
colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2617
    "set the pixel at x/y to aColor.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2618
     Pixels start at 0@0 for the upper left pixel, end at
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2619
     (width-1)@(height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2620
     This method checks if the color can be stored in the image.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2621
     (i.e. if the receiver is a palette image, the color must be present in there).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2622
     You should not use this method for image-processing, it is very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2623
     (it is meant to access individual pixels - for example, in a bitmap editor)"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2624
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2625
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2626
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2627
    pixel := self valueFromColor:aColor.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2628
    pixel isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2629
	^ UnrepresentableColorSignal raiseErrorString:'cannot store color - not in colormap'.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2630
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2631
    self pixelAtX:x y:y put:pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2632
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2633
    "Modified: 24.4.1997 / 17:36:20 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2634
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2635
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2636
data
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2637
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2638
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2639
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2640
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2641
    self obsoleteMethodWarning:'use #bits'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2642
    ^ bytes
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2643
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2644
    "Modified: 24.4.1997 / 17:37:57 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2645
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2646
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2647
data:aByteArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2648
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2649
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2650
    self obsoleteMethodWarning.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2651
    bytes := aByteArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2652
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2653
    "Modified: 24.4.1997 / 17:38:18 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2654
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2655
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2656
maskAt:aPoint
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2657
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2658
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2659
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2660
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2661
    ^ self maskAtX:aPoint x y:aPoint y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2662
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2663
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2664
maskAt:aPoint put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2665
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2666
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2667
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2668
    ^ self maskAtX:aPoint x y:aPoint y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2669
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2670
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2671
maskAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2672
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2673
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2674
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2675
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2676
    mask isNil ifTrue:[^ 1].
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2677
    ^ mask pixelAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2678
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2679
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2680
maskAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2681
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2682
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2683
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2684
    mask isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  2685
	maskValue == 1 ifTrue:[^ self].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  2686
	self error:'image has no mask'.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2687
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2688
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2689
    ^ mask pixelAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2690
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2691
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2692
pixelAt:aPoint
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2693
    "retrieve a pixel at x/y; return a pixel value.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2694
     Pixels start at 0@0 for upper left pixel, end at
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2695
     (width-1)@(height-1) for lower right pixel.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2696
     You should not use this method for image-processing, its
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2697
     very slow ...
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2698
     (it is meant to access individual pixels - for example, in a bitmap editor)"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2699
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2700
    ^ self pixelAtX:(aPoint x) y:(aPoint y)
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2701
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2702
    "Created: / 29.7.1998 / 02:48:52 / cg"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2703
!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2704
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2705
pixelAt:aPoint put:aPixelValue
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2706
    "set the pixel at x/y to aPixelValue.
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2707
     The interpretation of the pixelValue depends on the photometric
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2708
     and the colormap. (see also: Image>>atX:y:put:)
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2709
     Pixels start at 0@0 for the upper left pixel, end at
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2710
     (width-1) @ (height-1) for the lower right pixel.
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2711
     You should not use this method for image-processing, its
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2712
     very slow ...
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2713
     (it is meant to access individual pixels - for example, in a bitmap editor)"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2714
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2715
    ^ self pixelAtX:aPoint x y:aPoint y put:aPixelValue
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2716
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2717
    "Created: / 30.9.1998 / 22:40:43 / cg"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2718
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2719
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2720
pixelAtX:x y:y
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2721
    "retrieve the pixelValue at aPoint; return an integer number.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2722
     Pixels start at 0/0 for upper left pixel, and end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2723
     width-1@height-1 for lower right pixel.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2724
     The returned numbers interpretation depends on the photometric
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2725
     and the colormap. (see also Image>>at: and Image>>atX:y:)
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2726
     You should not use this method for image-processing of
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2727
     big images, its very slow ... 
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2728
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2729
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2730
    ^ self subclassResponsibility
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2731
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2732
    "Created: 24.4.1997 / 16:06:56 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2733
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2734
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2735
pixelAtX:x y:y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2736
    "set the pixel at x/y to aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2737
     The interpretation of the pixelValue depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2738
     and the colormap. (see also: Image>>atX:y:put:)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2739
     Pixels start at 0@0 for the upper left pixel, end at
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2740
     (width-1) @ (height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2741
     You should not use this method for image-processing, its
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2742
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2743
     (it is meant to access individual pixels - for example, in a bitmap editor)"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2744
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2745
    ^ self subclassResponsibility
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2746
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2747
    "Created: 24.4.1997 / 17:05:11 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2748
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2749
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2750
rowAt:rowIndex
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2751
    "retrieve an array filled with pixel values from
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2752
     a single row.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2753
     Notice: row indexing starts at 0.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2754
     This is a slow fallBack method, which works with any depth;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2755
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2756
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2757
    |pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2758
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2759
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2760
    self rowAt:rowIndex into:pixelArray startingAt:1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2761
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2762
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2763
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2764
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2765
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  2766
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2767
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2768
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2769
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2770
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2771
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  2772
     i := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2773
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2774
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2775
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2776
    "Modified: 24.4.1997 / 15:51:24 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2777
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2778
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2779
rowAt:rowIndex into:aPixelBuffer
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2780
    "fill aBuffer with pixel values retrieved from a single row.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2781
     Notice: row indexing starts at 0."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2782
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2783
    ^ self rowAt:rowIndex into:aPixelBuffer startingAt:1
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2784
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2785
    "Created: 24.4.1997 / 15:44:46 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2786
    "Modified: 24.4.1997 / 15:51:35 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2787
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2788
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2789
rowAt:rowIndex into:aPixelBuffer startingAt:startIndex
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2790
    "fill aBuffer with pixel values retrieved from a single row.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2791
     Notice: row indexing starts at 0.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2792
     This is a slow fallBack method, which works with any depth;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2793
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2794
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2795
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2796
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2797
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2798
    0 to:w do:[:col |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2799
	aPixelBuffer at:(col + startIndex) put:(self pixelAtX:col y:rowIndex)
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2800
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2801
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2802
    "Created: 24.4.1997 / 15:05:21 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2803
    "Modified: 24.4.1997 / 16:52:43 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2804
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2805
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2806
rowAt:rowIndex putAll:pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2807
    "store a single rows pixels from bits in the argument;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2808
     Notice: row indexing starts at 0.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2809
     This is a slow fallBack method, which works with any depth;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2810
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2811
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2812
    ^ self rowAt:rowIndex putAll:pixelArray startingAt:1
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2813
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2814
    "Modified: 24.4.1997 / 15:51:58 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2815
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2816
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2817
rowAt:rowIndex putAll:pixelArray startingAt:startIndex
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2818
    "store a single rows pixels from bits in the pixelArray argument;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2819
     return the pixelArray.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2820
     Notice: row indexing starts at 0.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2821
     This is a slow fallBack method, which works with any depth;
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2822
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2823
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2824
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2825
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2826
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2827
    0 to:w do:[:col |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2828
	self pixelAtX:col y:rowIndex put:(pixelArray at:(col + startIndex))
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2829
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2830
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2831
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2832
    "Modified: 24.4.1997 / 17:05:57 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2833
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2834
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2835
valueAt:aPoint
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2836
    "WARNING: for now, this returns a pixels value 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2837
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2838
     In the future, this will return a color (ST-80 compatibility)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2839
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2840
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2841
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2842
     Pixels start at 0@0 for upper left pixel, end at
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2843
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2844
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2845
     and the colormap. (see also Image>>at: and Image>>atX:y:)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2846
     You should not use this method for image-processing, its
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2847
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2848
     (it is meant to access individual pixels - for example, in a bitmap editor)"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2849
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2850
    'Image [warning]: the Image>>valueAt: will change semantics soon; use #pixelAt:' infoPrintCR.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2851
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2852
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2853
    "Modified: 21.6.1997 / 13:11:19 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2854
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2855
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2856
valueAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2857
    "WARNING: for now, this returns a pixels value 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2858
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2859
     In the future, this will return a color (ST-80 compatibility)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2860
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2861
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2862
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2863
     Pixels start at 0/0 for upper left pixel, and end at
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2864
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2865
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2866
     and the colormap. (see also Image>>at: and Image>>atX:y:)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2867
     You should not use this method for image-processing of
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2868
     big images, its very slow ... 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2869
     (it is meant to access individual pixels - for example, in a bitmap editor)"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2870
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2871
    'Image [warning]: the Image>>valueAtX:y: will change semantics soon; use #pixelAtX:y' infoPrintCR.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2872
    ^ self pixelAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2873
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2874
    "Modified: 21.6.1997 / 13:11:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2875
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2876
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  2877
!Image methodsFor:'accessing-private'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2878
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2879
bits:aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2880
    "set the raw data.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2881
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2882
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2883
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2884
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2885
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2886
    bytes := aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2887
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2888
    "Modified: 23.4.1996 / 11:08:28 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2889
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2890
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2891
bitsPerSample:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2892
    "set the number of bits per sample. 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2893
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2894
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2895
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2896
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2897
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2898
    bitsPerSample := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2899
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2900
    "Modified: 23.4.1996 / 11:08:31 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2901
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2902
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2903
depth:d
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2904
    "set the depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2905
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2906
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2907
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2908
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2909
1362
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  2910
    depth := self depth.
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  2911
    bitsPerPixel := d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2912
    d == 24 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2913
	samplesPerPixel := 3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2914
	bitsPerSample := #(8 8 8)
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2915
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2916
	samplesPerPixel := 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2917
	bitsPerSample := Array with:d 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2918
    ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2919
1362
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  2920
    "Modified: 20.2.1997 / 14:39:10 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2921
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2922
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2923
extent:anExtent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2924
    "set the images extent.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2925
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2926
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2927
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2928
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2929
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2930
    width := anExtent x.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2931
    height := anExtent y
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2932
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2933
    "Modified: 23.4.1996 / 11:08:38 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2934
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2935
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2936
height:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2937
    "set the height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2938
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2939
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2940
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2941
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2942
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2943
    height := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2944
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2945
    "Modified: 23.4.1996 / 11:08:40 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2946
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2947
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2948
photometric:aSymbol
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2949
    "set the photometric interpretation of the pixel values.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2950
     The argument, aSymbol is one of:
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2951
	#blackIs0, #whiteIs0, #palette, #rgb
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2952
     See TIFF documentation, from which the photometric concept is borrowed.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2953
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2954
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2955
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2956
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2957
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2958
    |b|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2959
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2960
    photometric := aSymbol.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2961
    bitsPerSample isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2962
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2963
	    b := self class imageDepth // 3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2964
	    bitsPerSample := Array with:b with:b with:b
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2965
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2966
	    bitsPerSample := Array with:(self class imageDepth)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2967
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2968
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2969
    samplesPerPixel isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2970
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2971
	    samplesPerPixel := 3
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2972
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2973
	    samplesPerPixel := 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2974
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2975
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2976
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2977
    "Modified: 10.6.1996 / 18:21:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2978
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2979
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2980
samplesPerPixel:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2981
    "set the array of samples per pixel.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2982
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2983
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2984
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2985
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2986
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2987
    samplesPerPixel := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2988
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2989
    "Modified: 23.4.1996 / 11:08:45 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2990
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2991
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2992
width:aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2993
    "set the width of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2994
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2995
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2996
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2997
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2998
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2999
    width := aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3000
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3001
    "Modified: 23.4.1996 / 11:08:48 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3002
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3003
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3004
width:w height:h 
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3005
    "set the width and height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3006
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3007
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3008
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3009
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3010
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3011
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3012
    height := h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3013
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3014
    "Modified: 23.4.1996 / 11:08:53 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3015
!
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3016
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3017
width:w height:h depth:d
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3018
    "set the width, height and depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3019
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3020
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3021
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3022
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3023
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3024
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3025
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3026
    self depth:d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3027
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3028
    "Modified: 23.4.1996 / 11:08:56 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3029
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3030
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3031
width:w height:h depth:d fromArray:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3032
    "set the width, height, depth and pixels of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3033
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3034
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3035
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3036
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3037
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3038
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3039
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3040
    self depth:d.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3041
    bytes := bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3042
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3043
    "Modified: 23.4.1996 / 11:08:59 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3044
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3045
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3046
width:w height:h depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3047
    "set the width, height and depth of the image.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3048
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3049
     This interface is only to be used when initializing
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3050
     instances or by image readers. Calling for a change of an
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3051
     existing image may confuse later pixel interpretation."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3052
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3053
    width := w.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3054
    height := h.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3055
    self depth:d.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3056
    colorMap := aColormap.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3057
    aColormap notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3058
	photometric := #palette
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3059
    ]
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3060
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3061
    "Modified: 23.4.1996 / 11:08:56 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3062
    "Created: 6.3.1997 / 15:23:57 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3063
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3064
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3065
width:w height:h photometric:p samplesPerPixel:spp bitsPerSample:bps colorMap:cm bits:pixels
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3066
    "set all relevant internal state of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3067
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3068
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3069
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3070
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3071
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3072
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3073
	width:w 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3074
	height:h 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3075
	photometric:p 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3076
	samplesPerPixel:spp 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3077
	bitsPerSample:bps 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3078
	colorMap:cm 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3079
	bits:pixels 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3080
	mask:nil
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3081
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3082
    "Modified: 20.6.1996 / 17:10:24 / cg"
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3083
!
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3084
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3085
width:w height:h photometric:p samplesPerPixel:spp bitsPerSample:bps colorMap:cm bits:pixels mask:m
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3086
    "set all relevant internal state of the image.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3087
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3088
     This interface is only to be used when initializing
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3089
     instances or by image readers. Calling for a change of an
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3090
     existing image may confuse later pixel interpretation."
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3091
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3092
    width := w.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3093
    height := h.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3094
    photometric := p.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3095
    samplesPerPixel := spp.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3096
    bitsPerSample := bps.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3097
    colorMap := cm.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3098
    bytes := pixels.
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3099
    mask := m.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3100
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3101
    "Modified: 23.4.1996 / 11:09:02 / cg"
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3102
    "Created: 20.6.1996 / 17:09:53 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3103
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  3104
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3105
!Image methodsFor:'binary storage'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3106
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3107
readBinaryContentsFrom: stream manager: manager
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3108
    "read a binary representation of an image from stream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3109
     Redefined to flush any device data."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3110
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3111
    super readBinaryContentsFrom: stream manager: manager.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3112
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3113
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3114
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3115
    fullColorDeviceForm := nil.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3116
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3117
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3118
storeBinaryDefinitionOn: stream manager: manager
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3119
    "store a binary representation of the receiver on stream.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3120
     This is an internal interface for binary storage mechanism.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3121
     Redefined to not store the device form (which is recreated at
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3122
     load time anyway)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3123
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3124
    |tDevice tDeviceForm tMonoDeviceForm tFullColorDeviceForm|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3125
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3126
    tDevice := device.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3127
    tDeviceForm := deviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3128
    tMonoDeviceForm := monoDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3129
    tFullColorDeviceForm := fullColorDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3130
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3131
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3132
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3133
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3134
    fullColorDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3135
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3136
    super storeBinaryDefinitionOn: stream manager: manager.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3137
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3138
    device := tDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3139
    deviceForm := tDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3140
    monoDeviceForm := tMonoDeviceForm.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3141
    fullColorDeviceForm := tFullColorDeviceForm.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3142
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3143
    "Modified: 23.4.1996 / 09:30:50 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3144
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  3145
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3146
!Image methodsFor:'conversion helpers'!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3147
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3148
rgbColormapFor:aDevice
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3149
    "helper for conversion to rgb format"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3150
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3151
    |nColors    "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3152
     scaleRed scaleGreen scaleBlue
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3153
     redShift   "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3154
     greenShift "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3155
     blueShift  "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3156
     colorValues|
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3157
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3158
    "/ gather r/g/b values for all colors in the map ...
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3159
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3160
    nColors := 1 bitShift:(self depth).
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3161
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3162
    "/ precompute scales to map from 0..100 into devices range
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3163
    "/ (this may be different for the individual components)
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3164
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3165
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3166
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3167
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3168
    redShift := aDevice shiftRed.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3169
    greenShift := aDevice shiftGreen.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3170
    blueShift := aDevice shiftBlue.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3171
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3172
    colorValues := Array uninitializedNew:nColors.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3173
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3174
    0 to:nColors-1 do:[:pixel |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3175
	|clr rv gv bv v "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3176
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3177
	clr := self colorFromValue:pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3178
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3179
	rv := (clr red * scaleRed) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3180
	gv := (clr green * scaleGreen) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3181
	bv := (clr blue * scaleBlue) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3182
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3183
	v := rv bitShift:redShift.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3184
	v := v bitOr:(gv bitShift:greenShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3185
	v := v bitOr:(bv bitShift:blueShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3186
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3187
	colorValues at:(pixel+1) put:v.
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3188
"/ clr print. ' ' print.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3189
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3190
"/ ' -> ' print. v printNL.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3191
    ].
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3192
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3193
    ^ colorValues
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3194
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3195
    "Modified: / 29.7.1998 / 00:34:56 / cg"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3196
! !
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3197
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3198
!Image methodsFor:'converting'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3199
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3200
asBurkesDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3201
    "return a burkes dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3202
     Depending on the images contents, this may or may not look better than
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3203
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3204
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3205
     error diffusion is done and due to being specially tuned."
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3206
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3207
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3208
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3209
    monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3210
    ^ Depth1Image width:width height:height fromArray:monoBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3211
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3212
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3213
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3214
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3215
     i := Image fromFile:'garfield.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3216
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3217
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3218
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3219
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3220
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3221
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3222
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3223
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3224
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3225
     i := Image fromFile:'claus.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3226
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3227
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3228
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3229
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3230
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3231
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3232
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3233
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3234
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3235
     i := Depth4Image
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3236
	     width:4 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3237
	     height:4
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3238
	     fromArray:#[ 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3239
			    16r01 16r23
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3240
			    16r45 16r67
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3241
			    16r89 16rab
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3242
			    16rcd 16ref 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3243
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3244
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3245
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3246
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3247
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3248
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3249
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3250
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3251
    "Created: 10.6.1996 / 12:34:44 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3252
    "Modified: 12.6.1996 / 13:58:16 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3253
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3254
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3255
asDitheredImageUsing:colors
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3256
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3257
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3258
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3259
    ^ self asDitheredImageUsing:colors depth:self depth
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3260
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3261
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3262
asDitheredImageUsing:colors depth:d
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3263
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3264
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3265
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3266
    |newBits|
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3267
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3268
    newBits := self floydSteinbergDitheredDepth8BitsColors:colors map:(0 to:colors size - 1).
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3269
    ^ self class extent:(self extent) depth:d palette:colors bits:newBits
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3270
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3271
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3272
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3273
asErrorDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3274
    "return an error-diffusion dithered monochrome image from the receiver image."
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3275
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3276
    DitherAlgorithm == #burkes ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3277
	^ self asBurkesDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3278
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3279
    DitherAlgorithm == #stevensonArce ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3280
	^ self asStevensonArgceDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3281
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3282
    ^ self asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3283
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3284
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3285
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3286
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3287
     i := Image fromFile:'garfield.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3288
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3289
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3290
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3291
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3292
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3293
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3294
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3295
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3296
     i := Image fromFile:'claus.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3297
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3298
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3299
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3300
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3301
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3302
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3303
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3304
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3305
     i := Depth4Image
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3306
	     width:4 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3307
	     height:4
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3308
	     fromArray:#[ 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3309
			    16r01 16r23
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3310
			    16r45 16r67
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3311
			    16r89 16rab
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3312
			    16rcd 16ref 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3313
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3314
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3315
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3316
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3317
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3318
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3319
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3320
    "Modified: 10.6.1996 / 14:22:30 / cg"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3321
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3322
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3323
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors 
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3324
    "return a floyd-steinberg dithered pseudoForm from the picture. 
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3325
     Use the colors in the fixColors array.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3326
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3327
     also be used to dither an 8bit image into a smaller number of colors,
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3328
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3329
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3330
    |pseudoBits f deviceDepth map|
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3331
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3332
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3333
    deviceDepth == 8 ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3334
	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3335
	    ^ nil.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3336
	]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3337
    ].
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3338
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3339
    pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3340
    pseudoBits isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3341
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3342
    f := Form width:width height:height depth:deviceDepth on:aDevice.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3343
    f isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3344
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3345
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3346
    "/ have to create a funny colorMap, where
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3347
    "/ color at:index == color colorId:index
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3348
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3349
    map := Array new:256.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3350
    fixColors do:[:clr |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3351
	map at:clr colorId + 1 put:clr
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3352
    ].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3353
    f colorMap:map. 
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3354
    f initGC.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3355
    f bits:pseudoBits.
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3356
    aDevice 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3357
	drawBits:pseudoBits 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3358
	bitsPerPixel:8 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3359
	depth:deviceDepth  
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3360
	padding:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3361
	width:width height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3362
	x:0 y:0
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3363
	into:(f id) x:0 y:0 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3364
	width:width height:height 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3365
	with:(f gcId).
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3366
    ^ f
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3367
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3368
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3369
     example: 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3370
	color reduction from Depth8 to Depth4 (dithering) can be done by:
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3371
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3372
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3373
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3374
     map := #( 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3375
		  (0     0   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3376
		  (0     0 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3377
		  (0    50   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3378
		  (0    50 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3379
		  (0   100   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3380
		  (0   100 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3381
		  (100   0   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3382
		  (100   0 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3383
		  (100  50   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3384
		  (100  50 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3385
		  (100 100   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3386
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3387
						      green:(rgb at:2)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3388
						       blue:(rgb at:3)) on:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3389
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3390
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3391
     form := img8 paletteImageAsDitheredPseudoFormOn:Display 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3392
		      colors:map 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3393
			nRed:2
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3394
		      nGreen:3
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3395
		       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3396
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3397
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3398
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3399
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3400
    "Modified: 14.6.1996 / 16:52:34 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3401
    "Created: 23.6.1997 / 15:25:37 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3402
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3403
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3404
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue 
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3405
    "return a floyd-steinberg dithered pseudoForm from the palette picture. 
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3406
     Use the colors in the fixColors array, which must be fixR x fixG x fixB
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3407
     colors assigned to aDevice, such as the preallocated colors of the
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3408
     Color class. 
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3409
     By passing the ditherColors as extra array, this method can
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3410
     also be used to dither an 8bit image into a smaller number of colors,
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3411
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3412
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3413
    |pseudoBits f deviceDepth map|
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3414
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3415
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3416
    deviceDepth == 8 ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3417
	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3418
	    ^ nil
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3419
	]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3420
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3421
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3422
    pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3423
    pseudoBits isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3424
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3425
    f := Form width:width height:height depth:deviceDepth on:aDevice.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3426
    f isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3427
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3428
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3429
    "/ have to create a funny colorMap, where
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3430
    "/ color at:index == color colorId:index
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3431
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3432
    map := Array new:256.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3433
    fixColors do:[:clr |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3434
	map at:clr colorId + 1 put:clr
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3435
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3436
    f colorMap:map. 
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3437
    f initGC.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3438
    f bits:pseudoBits.
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3439
    aDevice 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3440
	drawBits:pseudoBits 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3441
	bitsPerPixel:8 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3442
	depth:deviceDepth  
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3443
	padding:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3444
	width:width height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3445
	x:0 y:0
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3446
	into:(f id) x:0 y:0 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3447
	width:width height:height 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3448
	with:(f gcId).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3449
    ^ f
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3450
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3451
    "
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3452
     example: 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3453
	color reduction from Depth8 to Depth4 (dithering) can be done by:
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3454
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3455
     |img8 reducedImg8 img4 map form|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3456
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3457
     map := #( 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3458
		  (0     0   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3459
		  (0     0 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3460
		  (0    50   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3461
		  (0    50 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3462
		  (0   100   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3463
		  (0   100 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3464
		  (100   0   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3465
		  (100   0 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3466
		  (100  50   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3467
		  (100  50 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3468
		  (100 100   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3469
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3470
						      green:(rgb at:2)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3471
						       blue:(rgb at:3)) on:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3472
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3473
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3474
     form := img8 paletteImageAsDitheredPseudoFormOn:Display 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3475
		      colors:map 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3476
			nRed:2
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3477
		      nGreen:3
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3478
		       nBlue:2.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3479
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3480
     img4 := Depth4Image fromImage:img8.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3481
    "
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3482
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3483
    "Modified: 14.6.1996 / 16:52:34 / cg"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3484
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3485
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3486
asFloydSteinbergDitheredGrayFormOn:aDevice
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3487
    "return a dithered depth-x grey form from the receiver image."
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3488
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3489
    |depth bits|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3490
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3491
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3492
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3493
    or:[aDevice hasGrayscales not]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3494
	"/ for monochrome, there is specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3495
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3496
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3497
	bits := self floydSteinbergDitheredMonochromeBits.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3498
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3499
	bits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3500
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3501
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3502
    ^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3503
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3504
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3505
     |i|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3506
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3507
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3508
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3509
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3510
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3511
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3512
     |i|
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3513
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3514
     i := Image fromFile:'bitmaps/granite.tiff'.
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3515
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3516
    "
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3517
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3518
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3519
    "Modified: 17.4.1997 / 01:11:54 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3520
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3521
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3522
asFloydSteinbergDitheredGrayImageDepth:depth
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3523
    "return a floyd-steinberg dithered image from the receiver image."
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3524
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3525
    |ditheredBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3526
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3527
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3528
	^ self asFloydSteinbergDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3529
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3530
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1778
diff changeset
  3531
    ditheredBits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3532
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3533
	width:width height:height fromArray:ditheredBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3534
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3535
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3536
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3537
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3538
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3539
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3540
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3541
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3542
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3543
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3544
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3545
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3546
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3547
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3548
     i := Depth24Image width:4 height:1
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3549
	  fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3550
	    16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3551
	    16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3552
	    16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3553
	    16rFF 16r00 16r00   16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00].
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3554
     i := i magnifiedBy:4@1.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3555
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3556
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3557
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3558
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3559
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3560
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3561
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3562
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3563
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3564
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3565
     i := Depth24Image width:4 height:6
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3566
	  fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3567
	    16r00 16r00 16r00   16r00 16r00 16r80  16r00 16r00 16rff  16r00 16r80 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3568
	    16r00 16r80 16r80   16r00 16rFF 16r00  16r00 16rFF 16r80  16r00 16rFF 16rFF
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3569
	    16r80 16r00 16r00   16r80 16r00 16r80  16r80 16r00 16rff  16r80 16r80 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3570
	    16r80 16r80 16r80   16r80 16rFF 16r00  16r80 16rFF 16r80  16r80 16rFF 16rFF
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3571
	    16rFF 16r00 16r00   16rFF 16r00 16r80  16rFF 16r00 16rff  16rFF 16r80 16r00
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3572
	    16rFF 16r80 16r80   16rFF 16rFF 16r00  16rFF 16rFF 16r80  16rFF 16rFF 16rFF].
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3573
     i := i magnifiedBy:30.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3574
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3575
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3576
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3577
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3578
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3579
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3580
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3581
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3582
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3583
     i := Image fromFile:'granite.tiff'.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3584
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3585
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3586
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3587
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3588
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3589
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3590
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3591
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3592
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3593
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3594
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3595
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3596
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3597
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3598
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3599
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3600
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3601
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3602
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3603
     i := Depth4Image
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3604
	     width:4 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3605
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3606
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3607
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3608
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3609
			    16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3610
			    16rcd 16ref 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3611
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3612
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3613
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3614
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3615
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3616
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3617
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3618
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3619
    "Created: 10.6.1996 / 12:33:47 / cg"
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  3620
    "Modified: 19.10.1997 / 04:09:04 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3621
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3622
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3623
asFloydSteinbergDitheredMonochromeFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3624
    "return a dithered moncohrome form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3625
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3626
    |monoBits|
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3627
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3628
    monoBits := self floydSteinbergDitheredMonochromeBits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3629
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3630
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3631
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3632
     |i f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3633
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3634
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3635
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3636
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3637
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3638
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3639
     |i f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3640
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3641
     i := Depth2Image width:8 height:8
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3642
	  fromArray:#[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3643
			4r0000 4r0000
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3644
			4r0000 4r0000
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3645
			4r1111 4r1111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3646
			4r1111 4r1111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3647
			4r2222 4r2222
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3648
			4r2222 4r2222
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3649
			4r3333 4r3333
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3650
			4r3333 4r3333
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3651
		     ].
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3652
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3653
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3654
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3655
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3656
    "Modified: 17.4.1997 / 01:14:02 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3657
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3658
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3659
asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3660
    "return a floyd-steinberg dithered monochrome image from the receiver image."
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3661
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3662
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3663
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3664
    monoBits := self floydSteinbergDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3665
    ^ Depth1Image width:width height:height fromArray:monoBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3666
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3667
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3668
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3669
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3670
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3671
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3672
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3673
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3674
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3675
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3676
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3677
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3678
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3679
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3680
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3681
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3682
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3683
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3684
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3685
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3686
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3687
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3688
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3689
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3690
     i := Depth4Image
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3691
	     width:4 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3692
	     height:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3693
	     fromArray:#[ 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3694
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3695
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3696
			    16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3697
			    16rcd 16ref 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3698
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3699
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3700
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3701
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3702
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3703
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3704
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3705
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3706
    "Created: 10.6.1996 / 12:33:47 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3707
    "Modified: 17.4.1997 / 01:15:28 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3708
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3709
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3710
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3711
    "return a floyd-steinberg dithered pseudoForm from the picture,
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3712
     using colors in colors for dithering."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3713
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3714
    |pseudoBits pseudoBits8 f has8BitImage deviceDepth map d|
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3715
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3716
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3717
    has8BitImage := (deviceDepth == 8)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3718
		    or:[ (aDevice supportedImageFormatForDepth:8) notNil ].
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3719
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3720
    has8BitImage ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3721
	deviceDepth == 4 ifFalse:[^ nil].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3722
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3723
	pseudoBits8 := self nfloydSteinbergDitheredDepth8BitsColors:colors.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3724
	pseudoBits8 isNil ifTrue:[^ nil].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3725
	"/ convert to devices depth
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3726
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3727
	pseudoBits := ByteArray new:(width*4+7//8 * height).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3728
	pseudoBits8 compressPixels:4 width:width height:height into:pseudoBits mapping:nil.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3729
	d := 4.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3730
    ] ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3731
	pseudoBits := self nfloydSteinbergDitheredDepth8BitsColors:colors.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3732
	pseudoBits isNil ifTrue:[^ nil].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3733
	d := 8.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3734
    ].
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3735
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3736
    f := Form width:width height:height depth:deviceDepth on:aDevice.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3737
    f isNil ifTrue:[^ nil].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3738
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3739
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3740
    "/ have to create a funny colorMap, where
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3741
    "/ color at:index == color colorId:index
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3742
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3743
    map := Array new:256 withAll:0.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3744
    colors do:[:clr |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3745
	clr notNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3746
	    map at:clr colorId + 1 put:clr
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3747
	]
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3748
    ].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3749
    f colorMap:map. 
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3750
    f initGC.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3751
    f bits:pseudoBits.
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3752
    aDevice 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3753
	drawBits:pseudoBits 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3754
	bitsPerPixel:d 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3755
	depth:deviceDepth  
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3756
	padding:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3757
	width:width height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3758
	x:0 y:0
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3759
	into:(f id) x:0 y:0 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3760
	width:width height:height 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3761
	with:(f gcId).
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3762
    ^ f
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3763
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3764
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3765
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3766
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3767
     i := Image fromFile:'goodies/bitmaps/garfield.gif'.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3768
     (i asFloydSteinbergDitheredPseudoFormUsing:(Smalltalk at:#'Color:DitherColors') on:Display) inspect
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3769
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3770
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3771
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3772
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3773
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3774
     (i asFloydSteinbergDitheredPseudoFormUsing:(Smalltalk at:#'Color:DitherColors') on:Display) inspect
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3775
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3776
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3777
    "Created: 17.6.1996 / 12:13:35 / cg"
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3778
    "Modified: 5.9.1996 / 19:42:57 / cg"
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3779
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3780
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3781
asFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3782
    "get a device form, with best possible approximation.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3783
     remember it in case someone asks again."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3784
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3785
    |form visual|
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3786
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3787
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3788
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  3789
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3790
	mask := mask onDevice:aDevice
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  3791
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  3792
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3793
    (aDevice depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3794
    or:[aDevice hasGrayscales not]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3795
	form := self asMonochromeFormOn:aDevice.
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  3796
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3797
	((visual := aDevice visualType) == #StaticGray) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3798
	    form := self asGrayFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3799
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3800
	    (visual == #PseudoColor
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3801
	     or:[visual == #StaticColor]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3802
		form := self asPseudoFormQuickOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3803
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3804
	]
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  3805
    ].
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  3806
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  3807
    form isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3808
	(photometric == #palette) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3809
	    form := self paletteImageAsFormOn:aDevice
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3810
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3811
	    (photometric == #rgb) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3812
		form := self rgbImageAsFormOn:aDevice
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3813
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3814
		(photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3815
		    form := self rgbImageAsFormOn:aDevice
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3816
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3817
		    form := self greyImageAsFormOn:aDevice
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3818
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3819
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3820
	].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3821
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3822
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3823
    (device isNil or:[aDevice == device]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3824
	"remember this form in the receiver ..."
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3825
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3826
	form notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3827
	    deviceForm := form.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3828
	    maskedPixelsAre0 := nil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3829
	    device isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3830
		device := aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3831
		Lobby register:self
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3832
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3833
		Lobby registerChange:self
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3834
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3835
	    "
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3836
	     can save space, by not keeping the images data-bits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3837
	     twice (here and in the device form)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3838
	    "
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3839
	    form forgetBits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3840
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3841
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  3842
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3843
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3844
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  3845
    "Modified: / 22.8.1998 / 13:34:04 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3846
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3847
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3848
asGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3849
    "get a gray device form"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3850
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3851
    ^ self asGrayFormOn:aDevice dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3852
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3853
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3854
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3855
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3856
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3857
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3858
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3859
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3860
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3861
    "Created: 10.6.1996 / 18:44:42 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3862
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3863
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3864
asGrayFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3865
    "get a greyscale device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3866
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3867
    |depth|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3868
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3869
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3870
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3871
    or:[aDevice hasGrayscales not]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3872
	^ self asMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3873
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3874
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3875
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3876
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3877
	^ self asThresholdGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3878
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3879
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3880
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3881
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3882
	^ self asOrderedDitheredGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3883
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3884
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3885
    ^ self asFloydSteinbergDitheredGrayFormOn:aDevice.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3886
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3887
    "Created: 10.6.1996 / 18:42:01 / cg"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  3888
    "Modified: 14.6.1996 / 15:17:28 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3889
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3890
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3891
asGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3892
    "get a gray image from the receiver"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3893
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3894
    ^ self asGrayImageDepth:depth dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3895
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3896
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3897
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3898
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3899
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3900
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3901
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3902
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3903
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3904
    "Created: 10.6.1996 / 19:07:08 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3905
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3906
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3907
asGrayImageDepth:depth dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3908
    "get a greyscale image, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3909
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3910
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3911
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3912
	^ self asThresholdGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3913
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3914
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3915
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3916
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3917
	^ self asOrderedDitheredGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3918
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3919
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3920
    ^ self asFloydSteinbergDitheredGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3921
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3922
    "Created: 10.6.1996 / 19:08:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3923
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3924
48194c26a46c Initial revision
claus
parents:
diff changeset
  3925
asMonochromeFormOn:aDevice
48194c26a46c Initial revision
claus
parents:
diff changeset
  3926
    "get a monochrome device form"
48194c26a46c Initial revision
claus
parents:
diff changeset
  3927
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3928
    |form|
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3929
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3930
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm].
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  3931
    depth == 1 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3932
	((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  3933
    ].
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3934
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3935
    form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3936
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3937
    (device isNil or:[aDevice == device]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3938
	"remember this form in the receiver ..."
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3939
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3940
	form notNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3941
	    monoDeviceForm := form.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3942
	    device isNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3943
		device := aDevice.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3944
		Lobby register:self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3945
	    ] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3946
		Lobby registerChange:self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3947
	    ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3948
	    "
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3949
	     can save space, by not keeping the images data-bits
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3950
	     twice (here and in the device form)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3951
	    "
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3952
	    form forgetBits
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3953
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3954
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  3955
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3956
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3957
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3958
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3959
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3960
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3961
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3962
     (i asMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3963
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3964
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  3965
    "Modified: 23.10.1997 / 00:44:59 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3966
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3967
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3968
asMonochromeFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3969
    "get a monochrome device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3970
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3971
    |monoBits|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3972
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3973
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3974
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3975
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3976
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3977
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3978
    aDitherAlgorithm == #burkes ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3979
	monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3980
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3981
	aDitherAlgorithm == #stevensonArce ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3982
	    monoBits := self stevensonArceDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3983
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3984
	    (aDitherAlgorithm == #pattern
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3985
	    or:[aDitherAlgorithm == #ordered]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3986
		^ self asOrderedDitheredGrayFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3987
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3988
		^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3989
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3990
	]
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3991
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3992
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3993
    "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3994
    "/ make its pixel interpretation correct for the device
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3995
    "/
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3996
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3997
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3998
    "Modified: 10.6.1996 / 20:18:05 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3999
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4000
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4001
asNearestPaintDepth8FormOn:aDevice colors:fixColors 
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4002
    "return a nearest paint pseudoForm from the palette picture. 
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4003
     Use the colors in the fixColors array. 
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4004
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4005
     also be used to dither an 8bit image into a smaller number of colors,
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4006
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4007
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4008
    |pseudoBits f deviceDepth map|
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4009
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4010
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4011
    deviceDepth == 8 ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4012
	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4013
	    ^ nil
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4014
	]
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4015
    ].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4016
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4017
    pseudoBits := self nearestPaintDepth8BitsColors:fixColors.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4018
    pseudoBits isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4019
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4020
    f := Form width:width height:height depth:deviceDepth on:aDevice.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4021
    f isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4022
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4023
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4024
    "/ have to create a funny colorMap, where
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4025
    "/ color at:index == color colorId:index
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4026
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4027
    map := Array new:256.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4028
    fixColors do:[:clr |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4029
	map at:clr colorId + 1 put:clr
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4030
    ].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4031
    f colorMap:map. 
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4032
    f initGC.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4033
    f bits:pseudoBits.
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  4034
    aDevice 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4035
	drawBits:pseudoBits 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4036
	bitsPerPixel:8 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4037
	depth:deviceDepth  
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4038
	padding:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4039
	width:width height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4040
	x:0 y:0
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4041
	into:(f id) x:0 y:0 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4042
	width:width height:height 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4043
	with:(f gcId).
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4044
    ^ f
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4045
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4046
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4047
     example: 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4048
	color reduction from Depth8 to Depth4 (dithering) can be done by:
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4049
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4050
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4051
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4052
     map := #( 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4053
		  (0     0   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4054
		  (0     0 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4055
		  (0    50   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4056
		  (0    50 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4057
		  (0   100   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4058
		  (0   100 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4059
		  (100   0   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4060
		  (100   0 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4061
		  (100  50   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4062
		  (100  50 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4063
		  (100 100   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4064
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4065
						      green:(rgb at:2)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4066
						       blue:(rgb at:3)) on:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4067
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4068
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4069
     form := img8 asNearestPaintDepth8FormOn:Display 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4070
		      colors:map 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4071
			nRed:2
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4072
		      nGreen:3
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4073
		       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4074
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4075
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4076
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4077
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4078
    "Modified: 17.6.1996 / 18:52:47 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4079
    "Created: 23.6.1997 / 15:26:09 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4080
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4081
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4082
asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4083
    "return a nearest paint pseudoForm from the palette picture. 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4084
     Use the colors in the fixColors array, which must be fixR x fixG x fixB
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4085
     colors assigned to aDevice, such as the preallocated colors of the
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4086
     Color class. 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4087
     By passing the ditherColors as extra array, this method can
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4088
     also be used to dither an 8bit image into a smaller number of colors,
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4089
     for example to create dithered Depth4Images from Depth8Images."
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4090
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4091
    |pseudoBits f deviceDepth map|
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4092
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4093
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4094
    deviceDepth == 8 ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4095
	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4096
	    ^ nil
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4097
	]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4098
    ].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4099
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4100
    pseudoBits := self nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4101
    pseudoBits isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4102
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4103
    f := Form width:width height:height depth:deviceDepth on:aDevice.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4104
    f isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4105
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4106
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4107
    "/ have to create a funny colorMap, where
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4108
    "/ color at:index == color colorId:index
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4109
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4110
    map := Array new:256.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4111
    fixColors do:[:clr |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4112
	map at:clr colorId + 1 put:clr
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4113
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4114
    f colorMap:map. 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4115
    f initGC.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4116
    f bits:pseudoBits.
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  4117
    aDevice 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4118
	drawBits:pseudoBits 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4119
	bitsPerPixel:8 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4120
	depth:deviceDepth  
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4121
	padding:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4122
	width:width height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4123
	x:0 y:0
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4124
	into:(f id) x:0 y:0 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4125
	width:width height:height 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4126
	with:(f gcId).
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4127
    ^ f
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4128
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4129
    "
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4130
     example: 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4131
	color reduction from Depth8 to Depth4 (dithering) can be done by:
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4132
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4133
     |img8 reducedImg8 img4 map form|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4134
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4135
     map := #( 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4136
		  (0     0   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4137
		  (0     0 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4138
		  (0    50   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4139
		  (0    50 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4140
		  (0   100   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4141
		  (0   100 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4142
		  (100   0   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4143
		  (100   0 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4144
		  (100  50   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4145
		  (100  50 100)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4146
		  (100 100   0)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4147
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4148
						      green:(rgb at:2)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4149
						       blue:(rgb at:3)) on:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4150
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4151
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4152
     form := img8 asNearestPaintDepth8FormOn:Display 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4153
		      colors:map 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4154
			nRed:2
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4155
		      nGreen:3
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4156
		       nBlue:2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4157
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4158
     img4 := Depth4Image fromImage:img8.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4159
    "
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4160
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4161
    "Created: 17.6.1996 / 18:47:46 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4162
    "Modified: 17.6.1996 / 18:52:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4163
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4164
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4165
asOrderedDitheredGrayFormOn:aDevice
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4166
    "return a dithered depth-x grey form from the receiver image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4167
     Uses an 8x8 dithermatrix."
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4168
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4169
    |depth bits|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4170
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4171
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4172
    (depth == 1 
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4173
    or:[aDevice hasGrayscales not]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4174
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4175
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4176
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4177
	^ self asOrderedDitheredMonochromeFormOn:aDevice
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4178
    ].
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4179
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4180
    bits := self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4181
		orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4182
		ditherWidth:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4183
		depth:depth.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4184
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4185
    ^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4186
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4187
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4188
     |i|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4189
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4190
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4191
     (i asOrderedDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4192
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4193
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4194
    "Modified: 24.6.1997 / 22:19:30 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4195
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4196
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4197
asOrderedDitheredGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4198
    "return a dithered depth-x grey image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4199
     Uses an 8x8 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4200
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4201
    |dither|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4202
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4203
    dither := self class orderedDitherMatrixOfSize:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4204
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4205
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4206
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4207
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4208
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4209
	^ Depth1Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4210
	    width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4211
	    height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4212
	    fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4213
		self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4214
		    orderedDitheredMonochromeBitsWithDitherMatrix:dither
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4215
		    ditherWidth:8)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4216
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4217
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4218
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4219
	width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4220
	height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4221
	fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4222
	    self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4223
		orderedDitheredGrayBitsWithDitherMatrix:dither
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4224
		ditherWidth:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4225
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4226
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4227
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4228
     |i i1 i2 i4 i8|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4229
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4230
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4231
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4232
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4233
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4234
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4235
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4236
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4237
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4238
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4239
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4240
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4241
     i8 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4242
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4243
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4244
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4245
     |i i1 i2 i4 i8|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4246
     i := Image fromFile:'goodies/bitmaps/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4247
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4248
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4249
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4250
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4251
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4252
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4253
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4254
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4255
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4256
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4257
     i8 inspect.
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4258
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4259
     i2 := i8 asOrderedDitheredGrayImageDepth:2.
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4260
     i2 inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4261
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4262
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4263
    "Created: 7.6.1996 / 18:03:54 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4264
    "Modified: 24.6.1997 / 22:19:36 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4265
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4266
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4267
asOrderedDitheredMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4268
    "return a dithered monochrome form from the grey image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4269
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4270
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4271
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4272
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4273
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4274
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4275
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4276
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4277
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4278
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4279
    ^ self 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4280
	asOrderedDitheredMonochromeFormOn:aDevice 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4281
	ditherMatrix:(self class orderedDitherMatrixOfSize:4)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4282
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4283
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4284
"/    ^ self 
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4285
"/        asOrderedDitheredMonochromeFormOn:aDevice 
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4286
"/        ditherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4287
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4288
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4289
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4290
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4291
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4292
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4293
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4294
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4295
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4296
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4297
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4298
     i := (Image fromFile:'goodies/bitmaps/winBitmaps/a11.ico') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4299
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4300
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4301
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4302
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4303
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4304
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4305
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4306
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4307
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4308
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4309
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4310
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4311
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4312
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4313
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4314
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4315
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4316
     i := (Image fromFile:'goodies/bitmaps/blue-ball.gif') magnifiedBy:1.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4317
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4318
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4319
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4320
    "Created: 7.6.1996 / 14:52:32 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4321
    "Modified: 17.4.1997 / 01:10:10 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4322
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4323
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4324
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4325
    "return a dithered monochrome form from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4326
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4327
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4328
    |monoBits|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4329
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4330
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4331
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4332
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4333
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4334
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4335
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4336
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4337
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4338
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4339
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4340
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4341
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4342
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4343
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4344
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4345
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4346
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4347
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4348
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4349
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4350
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4351
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4352
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4353
    "Created: 7.6.1996 / 14:51:42 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4354
    "Modified: 17.4.1997 / 01:08:24 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4355
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4356
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4357
asOrderedDitheredMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4358
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4359
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4360
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4361
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4362
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4363
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4364
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4365
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4366
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4367
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4368
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4369
    ^ self 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4370
	asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4371
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4372
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4373
"/    ^ self 
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4374
"/        asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4375
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4376
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4377
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4378
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4379
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4380
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4381
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4382
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4383
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4384
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4385
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4386
     i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4387
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4388
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4389
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4390
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4391
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4392
     i := Image fromFile:'goodies/bitmaps/garfield.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4393
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4394
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4395
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4396
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4397
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4398
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4399
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4400
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4401
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4402
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4403
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4404
     i := (Image fromFile:'goodies/bitmaps/blue-ball.gif') magnifiedBy:1.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4405
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4406
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4407
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4408
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4409
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4410
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4411
     i asOrderedDitheredMonochromeImage inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4412
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4413
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4414
    "Created: 7.6.1996 / 15:02:07 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4415
    "Modified: 10.6.1996 / 11:15:09 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4416
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4417
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4418
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4419
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4420
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4421
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4422
    |monoBits|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4423
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4424
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4425
    ^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4426
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4427
    "order-4 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4428
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4429
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4430
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4431
     i := Image fromFile:'garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4432
     i
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4433
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4434
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4435
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4436
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4437
    "order-6 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4438
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4439
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4440
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4441
     i := Image fromFile:'garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4442
     i
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4443
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4444
	ditherWidth:8
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4445
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4446
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4447
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4448
    "thresholding at:0.5 (all above 0.5 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4449
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4450
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4451
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4452
     i := Image fromFile:'garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4453
     i
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4454
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4455
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4456
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4457
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4458
    "thresholding at: 0.25 (all above 0.25 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4459
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4460
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4461
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4462
     i := Image fromFile:'garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4463
     i
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4464
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4465
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4466
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4467
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4468
    "thresholding at: 0.75 (all above 0.75 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4469
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4470
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4471
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4472
     i := Image fromFile:'garfield.gif'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4473
     i
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4474
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4475
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4476
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4477
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4478
    "Modified: 7.6.1996 / 17:23:47 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4479
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4480
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4481
asPseudoFormQuickOn:aDevice
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4482
    "return a pseudo-deviceForm from the image.
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  4483
     Fail if any color is not available (i.e. do not dither)."
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4484
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4485
    |f d 
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4486
     temp temp8 bits clr cMap idMap 
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4487
     w            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4488
     h            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4489
     dDev         "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4490
     nClr         "{ Class: SmallInteger }" 
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4491
     bytesPerLine "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4492
     usedColors pix fmt|
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4493
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4494
    d := self depth.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4495
    (d == 1
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4496
    or:[d == 2
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4497
    or:[d == 4
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4498
    or:[d == 8]]]) ifFalse:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4499
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4500
    w := width.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4501
    h := height.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4502
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4503
    "/ for now (since the code below does not care for padding;
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4504
    "/ if the padding is not supported: fail
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4505
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4506
    dDev := aDevice depth.
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4507
    (bytesPerLine := dDev) == 8 ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4508
	bytesPerLine := (w * dDev + 7) // 8.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4509
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4510
2532
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
  4511
    fmt := aDevice supportedImageFormatForDepth:dDev.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4512
    fmt isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4513
	"/ cannot draw directly
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4514
	^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4515
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4516
    (bytesPerLine * 8) \\ (fmt at:#padding) == 0 ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4517
	"/ mhmh - ought to repad here;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4518
	"/ however, the nonQuick converter does it.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4519
	^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4520
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4521
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4522
    "/ see if all of the images colors are representable
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4523
    "/ on the device
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4524
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4525
    bits := self bitsPerPixel.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4526
    nClr := (1 bitShift:bits).
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4527
    cMap := Array new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4528
    idMap := ByteArray new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4529
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4530
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4531
	nClr := nClr min:(colorMap size)
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4532
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4533
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  4534
    d == 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4535
	usedColors := bytes usedValues.    "gets us an array filled with used values"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4536
	1 to:nClr do:[:pixel |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4537
	    (usedColors includes:(pixel - 1)) ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4538
		clr := Color black
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4539
	    ] ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4540
		clr := self colorFromValue:pixel-1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4541
		clr := clr exactOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4542
		clr isNil ifTrue:[^ nil].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4543
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4544
	    (pix := clr colorId) isNil ifTrue:[^ nil].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4545
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4546
	    cMap at:(pixel) put:clr.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4547
	    idMap at:(pixel) put:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4548
	].
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  4549
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4550
	1 to:nClr do:[:pixel |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4551
	    clr := self colorFromValue:pixel-1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4552
	    clr := clr exactOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4553
	    clr isNil ifTrue:[^ nil].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4554
	    (pix := clr colorId) isNil ifTrue:[^ nil].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4555
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4556
	    cMap at:(pixel) put:clr.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4557
	    idMap at:(pixel) put:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4558
	].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4559
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4560
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4561
    "/ got all colors; good - simply change depth & translate pixels
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4562
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4563
    (d == 8 and:[dDev == 8]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4564
	"/ only translate
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4565
	temp := ByteArray uninitializedNew:(w * h).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4566
	bytes expandPixels:8         "xlate only"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4567
		    width:w 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4568
		   height:h
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4569
		     into:temp
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4570
		  mapping:idMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4571
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4572
	"/ stupid: expandPixels can only handle any-to-8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4573
	"/ compressPixels can only handle 8-to-any
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4574
	"/ However, those methods are faster
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4575
	"/ - even if we convert twice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4576
	"/ Therefore, convert first from myDepth to 8,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4577
	"/ then from 8 to the device depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4578
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4579
	d ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4580
	    temp8 := ByteArray uninitializedNew:(w * h).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4581
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4582
	    bytes expandPixels:d      
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4583
			 width:w 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4584
			height:h
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4585
			  into:temp8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4586
		       mapping:idMap.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4587
	    idMap := nil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4588
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4589
	    temp8 := bytes.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4590
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4591
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4592
	dDev ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4593
	    temp := ByteArray uninitializedNew:(bytesPerLine * h).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4594
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4595
	    temp8 compressPixels:dDev      
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4596
			 width:w 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4597
			height:h
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4598
			  into:temp
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4599
		       mapping:idMap.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4600
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4601
	    temp := temp8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4602
	].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4603
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4604
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4605
    f := Form width:w height:h depth:dDev on:aDevice.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4606
    f isNil ifTrue:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4607
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4608
    f colorMap:cMap. 
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4609
    f initGC.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4610
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4611
    aDevice 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4612
	drawBits:temp 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4613
	depth:dDev 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4614
	padding:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4615
	width:w 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4616
	height:h
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4617
	x:0 y:0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4618
	into:(f id) x:0 y:0 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4619
	width:w 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4620
	height:h 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4621
	with:(f gcId).
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4622
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4623
    ^ f
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4624
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4625
    "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4626
     (
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4627
	(((Depth4Image
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4628
	     width:4 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4629
	     height:4
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4630
	     fromArray:#[ 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4631
			    16r01 16r23
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4632
			    16r45 16r67
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4633
			    16r89 16rab
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4634
			    16rcd 16ref 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4635
			]))
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4636
	       magnifiedBy:30
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4637
	 )
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4638
	  asPseudoFormQuickOn:Display
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4639
      ) inspect
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4640
     "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4641
2113
c64f89f9ffba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2102
diff changeset
  4642
    "Modified: / 7.5.1998 / 19:40:47 / cg"
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4643
!
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4644
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4645
asStevensonArceDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4646
    "return a stevenson-arce dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4647
     Depending on the images contents, this may or may not look better than
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4648
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4649
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4650
     error diffusion is done and due to being specially tuned."
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4651
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4652
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4653
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4654
    monoBits := self stevensonArceDitheredMonochromeBits.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4655
    ^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4656
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4657
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4658
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4659
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4660
     i := Image fromFile:'garfield.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4661
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4662
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4663
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4664
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4665
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4666
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4667
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4668
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4669
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4670
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4671
     i := Image fromFile:'claus.gif'.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4672
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4673
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4674
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4675
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4676
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4677
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4678
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4679
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4680
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4681
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4682
     i := Depth4Image
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4683
	     width:4 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4684
	     height:4
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4685
	     fromArray:#[ 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4686
			    16r01 16r23
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4687
			    16r45 16r67
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4688
			    16r89 16rab
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4689
			    16rcd 16ref 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4690
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4691
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4692
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4693
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4694
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4695
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4696
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4697
    "Created: 10.6.1996 / 12:38:29 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4698
    "Modified: 12.6.1996 / 13:58:24 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4699
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4700
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4701
asThresholdGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4702
    "return a thresholded grey form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4703
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4704
    |depth|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4705
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4706
    (depth := aDevice depth) == 1 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4707
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4708
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4709
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4710
    ^ self 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4711
	makeDeviceGrayPixmapOn:aDevice 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4712
	depth:depth 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4713
	fromArray:(self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4714
			orderedDitheredGrayBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4715
			ditherWidth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4716
			depth:depth)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4717
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4718
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4719
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4720
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4721
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4722
     (i asThresholdGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4723
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4724
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4725
    "Created: 10.6.1996 / 18:38:31 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4726
    "Modified: 24.6.1997 / 22:19:46 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4727
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4728
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4729
asThresholdGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4730
    "return a thresholded depth-x grey image from the receiver image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4731
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4732
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4733
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4734
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4735
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4736
	^ Depth1Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4737
	    width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4738
	    height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4739
	    fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4740
		self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4741
		    orderedDitheredMonochromeBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4742
		    ditherWidth:4)
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4743
    ].
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4744
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4745
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4746
	width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4747
	height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4748
	fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4749
	    self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4750
		orderedDitheredGrayBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4751
		ditherWidth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4752
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4753
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4754
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4755
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4756
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4757
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4758
     (i asThresholdGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4759
     (i asThresholdGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4760
     (i asThresholdGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4761
     (i asThresholdGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4762
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4763
     (i asOrderedDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4764
     (i asOrderedDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4765
     (i asOrderedDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4766
     (i asOrderedDitheredGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4767
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4768
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4769
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4770
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4771
     (i asFloydSteinbergDitheredGrayImageDepth:8) inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4772
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4773
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4774
    "Created: 7.6.1996 / 18:13:33 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4775
    "Modified: 24.6.1997 / 22:19:52 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4776
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4777
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4778
asThresholdMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4779
    "return a threshold monochrome form from the image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4780
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4781
    ^ self 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4782
	asOrderedDitheredMonochromeFormOn:aDevice 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4783
	ditherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4784
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4785
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4786
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4787
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4788
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4789
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4790
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4791
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4792
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4793
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4794
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4795
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4796
     i := (Image fromFile:'goodies/bitmaps/a11.ico') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4797
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4798
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4799
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4800
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4801
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4802
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4803
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4804
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4805
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4806
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4807
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4808
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4809
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4810
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4811
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4812
     (i asThresholdMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4813
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4814
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4815
    "Created: 7.6.1996 / 16:15:17 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4816
    "Modified: 10.6.1996 / 17:44:29 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4817
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4818
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4819
asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4820
    "return a threshold monochrome image from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4821
     Threshold means: brightness < 0.5 -> black / otherwise white"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4822
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4823
    ^ self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4824
	asOrderedDitheredMonochromeImageWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4825
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4826
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4827
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4828
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4829
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4830
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4831
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4832
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4833
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4834
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4835
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4836
     i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4837
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4838
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4839
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4840
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4841
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4842
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4843
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4844
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4845
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4846
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4847
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4848
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4849
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4850
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4851
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4852
    "Created: 7.6.1996 / 16:15:17 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4853
    "Modified: 7.6.1996 / 17:16:10 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4854
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4855
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4856
asThresholdMonochromeImage:thresholdBrighness
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4857
    "return a threshold monochrome image from the image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4858
     The argument (0..1) gives the threshold value;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4859
     Threshold means: brightness < threshold -> black / otherwise white"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4860
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4861
    |value ditherMatrix|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4862
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4863
    value := thresholdBrighness * 255.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4864
    ditherMatrix := ByteArray new:256 withAll:(value truncated).
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4865
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4866
    ^ self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4867
	asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4868
	ditherWidth:16
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4869
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4870
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4871
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4872
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4873
     i := Image width:4 height:4 depth:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4874
		fromArray:#[ 16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4875
			     16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4876
			     16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4877
			     16rcd 16ref ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4878
     i := i magnifiedBy:30.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4879
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4880
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4881
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4882
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4883
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4884
     (i asThresholdMonochromeImage:1) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4885
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4886
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4887
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4888
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4889
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4890
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4891
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4892
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4893
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4894
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4895
     (i asThresholdMonochromeImage:0.625) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4896
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4897
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4898
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4899
    "Created: 7.6.1996 / 16:15:17 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4900
    "Modified: 8.6.1996 / 14:51:57 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4901
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4902
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4903
clearMaskedPixels
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4904
    "assuming that I already have a device representation
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4905
     in deviceForm, clear any masked pixels.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4906
     This will allow faster drawing in the future."
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4907
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4908
    maskedPixelsAre0 == true ifTrue:[^ self].   "/ already cleared
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4909
    mask isNil ifTrue:[^ self].         "/ no mask
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4910
    deviceForm isNil ifTrue:[^ self].   "/ no device rep.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4911
    mask depth ~~ 1 ifTrue:[^ self].    "/ not done with alpha masks
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4912
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4913
    deviceForm foreground:Color allColor background:Color noColor.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4914
    deviceForm function:#and.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4915
    deviceForm copyPlaneFrom:(mask asFormOn:device) x:0 y:0 toX:0 y:0 width:width height:height.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4916
    maskedPixelsAre0 := true.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4917
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4918
    "Created: 12.4.1997 / 12:18:05 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4919
    "Modified: 12.4.1997 / 12:20:19 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4920
!
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4921
3104
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  4922
exactOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  4923
    "for compatibility with color protocol - here, the same as #onDevice."
3104
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  4924
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  4925
    ^ self onDevice:aDevice
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  4926
!
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  4927
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  4928
exactOrNearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  4929
    "for compatibility with color protocol - here, the same as #onDevice."
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  4930
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  4931
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  4932
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  4933
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4934
fromForm:aForm
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4935
    "setup the receiver from a form"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4936
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4937
    |map c0 c1|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4938
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4939
    width := aForm width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4940
    height := aForm height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4941
    bitsPerSample := self bitsPerSample.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4942
    samplesPerPixel := self samplesPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4943
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4944
    aForm hasBits ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4945
	"/ must read the data from the device
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4946
	self from:aForm in:(0@0 extent:aForm extent).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4947
	^ self
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4948
    ].
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4949
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4950
    "/ the form has all data available
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4951
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4952
    bytes := aForm bits.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4953
    map := aForm colorMap.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4954
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4955
    aForm depth == 1 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4956
	map isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4957
	    photometric := #whiteIs0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4958
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4959
	    c0 := map at:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4960
	    c1 := map at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4961
	    ((c0 = Color white)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4962
	    and:[c1 = Color black]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4963
		photometric := #whiteIs0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4964
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4965
		((c0 = Color black)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4966
		and:[c1 = Color white]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4967
		    photometric := #blackIs0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4968
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4969
		    photometric := #palette.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4970
		    colorMap := Array with:c0 with:c1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4971
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4972
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4973
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4974
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4975
	map notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4976
	    photometric := #palette.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4977
	    colorMap := map copy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4978
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4979
	    "
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4980
	     photometric stays at default
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4981
	     (which is rgb for d24, greyscale for others)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4982
	    "
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4983
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4984
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  4985
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  4986
    "Modified: 5.7.1996 / 16:24:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4987
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  4988
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4989
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4990
    "setup the receiver from another image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4991
     Color precision may be lost, if conversion is from a higher depth
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4992
     image. 
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4993
     WARNING:
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  4994
     This implementation is a slow fallback (the loop over the
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4995
     source pixels is very slow). If this method is used heavily, you
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4996
     may want to redefine it in concrete subclasses for common source images."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4997
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  4998
    ^ self fromImage:anImage photometric:nil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  4999
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5000
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5001
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5002
    "setup the receiver from another image and optionally set the photometric.
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5003
     Color precision may be lost, if conversion is from a higher depth
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5004
     image. 
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5005
     WARNING:
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5006
     This implementation is a slow fallback (the loop over the
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5007
     source pixels is very slow). If this method is used heavily, you
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5008
     may want to redefine it in concrete subclasses for common source images."
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5009
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5010
    |map clr mappedRowPixels samePhotometric
1784
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5011
     h "{ Class: SmallInteger }"
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5012
     w "{ Class: SmallInteger }"|
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5013
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5014
    width := anImage width.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5015
    height := anImage height.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5016
    bitsPerSample := self bitsPerSample.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5017
    samplesPerPixel := self samplesPerPixel.
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5018
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5019
    self colormapFromImage:anImage photometric:photometricOrNil.
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5020
1374
ab515c0576c6 preserve mask when creating an image from another image.
Claus Gittinger <cg@exept.de>
parents: 1362
diff changeset
  5021
    self mask:anImage mask.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5022
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5023
    samePhotometric := (photometric == anImage photometric).
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5024
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5025
    ((self depth = anImage depth)
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5026
    and:[samePhotometric]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5027
	bytes := anImage bits copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5028
	^ self.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5029
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5030
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5031
    bytes := ByteArray uninitializedNew:(self bytesPerRow * height).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5032
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5033
    self depth >= anImage depth ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5034
	anImage depth <= 12 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5035
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5036
	    "/ if my depth is greater, all colors can be represented,
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5037
	    "/ and the loop can be done over pixel values ...
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5038
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5039
	    (colorMap isNil or:[samePhotometric not]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5040
		map := Array new:(1 bitShift:anImage depth).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5041
		1 to:map size do:[:i |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5042
		    clr := anImage colorFromValue:(i - 1).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5043
		    map at:i put:(self valueFromColor:clr).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5044
		].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5045
	    ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5046
	    mappedRowPixels := self pixelArraySpecies new:width.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5047
	    h := height-1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5048
	    w := width.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5049
	    0 to:h do:[:row |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5050
		anImage rowAt:row into:mappedRowPixels startingAt:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5051
		map notNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5052
		    1 to:w do:[:i |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5053
			mappedRowPixels at:i put:(map at:(mappedRowPixels at:i)+1)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5054
		    ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5055
		].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5056
		self rowAt:row putAll:mappedRowPixels
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5057
	    ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5058
	    ^ self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5059
	].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5060
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5061
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5062
    anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5063
	self colorAtX:x y:y put:clr
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5064
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5065
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5066
    "
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5067
     |i i2 i4 i8 i16 i24|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5068
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5069
     i := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5070
     i inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5071
     i2 := Depth2Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5072
     i2 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5073
     i4 := Depth4Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5074
     i4 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5075
     i8 := Depth8Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5076
     i8 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5077
     i24 := Depth24Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5078
     i24 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5079
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5080
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5081
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5082
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5083
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5084
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5085
     Transcript showCR:(
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5086
	Time millisecondsToRun:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5087
	    i24 := Depth24Image fromImage:i.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5088
	]
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5089
     ).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5090
     i24 inspect.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5091
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5092
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5093
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5094
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5095
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5096
     MessageTally spyOn:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5097
	i24 := Depth24Image fromImage:i.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5098
     ]
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5099
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5100
1784
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5101
    "Modified: 23.6.1997 / 19:38:59 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5102
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5103
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5104
fromSubImage:anImage in:aRectangle
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5105
    "setup the receiver from another image, extracting a rectangular
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5106
     area. Color precision may be lost, if conversion is from a higher depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5107
     image. For palette & rgb images, this may fail if a color cannot be
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5108
     represented.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5109
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5110
     WARNING:
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5111
       This implementation is a slow fallback (the loop over the
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5112
       source pixels is very slow). If this method is used heavily, you
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5113
       may want to redefine it in concrete subclasses for the common case of
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5114
       of creating a subImage with the same depth & palette."
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5115
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5116
    |xL yT xR yB maskClass|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5117
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5118
    width := aRectangle width.
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5119
    height := aRectangle height.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5120
    bytes := ByteArray uninitializedNew:(self bytesPerRow * height).
3458
b2e098e6288b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3457
diff changeset
  5121
    depth := self depth.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5122
    bitsPerSample := self bitsPerSample.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5123
    bitsPerPixel := self bitsPerPixel.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5124
    samplesPerPixel := self samplesPerPixel.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5125
    self colormapFromImage:anImage.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5126
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5127
    xL := aRectangle left.
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5128
    yT := aRectangle top.
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5129
    xR := xL + aRectangle width - 1.
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5130
    yB := yT + aRectangle height - 1.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5131
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5132
    ((photometric == anImage photometric)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5133
    and:[self bitsPerPixel = anImage bitsPerPixel
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5134
    and:[colorMap = anImage colorMap]]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5135
	"/ can do it by value
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5136
	anImage 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5137
	    valuesFromX:xL y:yT toX:xR y:yB
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5138
	    do:[:x :y :pixelValue |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5139
		    self pixelAtX:x-xL y:y-yT put:pixelValue.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5140
	       ]
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5141
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5142
	"/ must do it by colors
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5143
	anImage 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5144
	    colorsFromX:xL y:yT toX:xR y:yB
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5145
	    do:[:x :y :clr |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5146
		    self colorAtX:x-xL y:y-yT put:clr.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5147
	       ]
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5148
    ].
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5149
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5150
    anImage mask notNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5151
	anImage mask depth == 1 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5152
	    maskClass := ImageMask
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5153
	] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5154
	    maskClass := anImage mask class.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5155
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5156
	mask := maskClass new 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5157
		    fromSubImage:anImage mask in:aRectangle
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5158
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5159
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5160
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5161
     |i i2 i4 i8 i16 i24|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5162
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5163
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5164
     i inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5165
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5166
     i4 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5167
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5168
     i8 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5169
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5170
     i24 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5171
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5172
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5173
    "Created: / 20.9.1995 / 01:06:02 / claus"
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5174
    "Modified: / 20.9.1995 / 10:15:37 / claus"
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5175
    "Modified: / 18.5.1999 / 20:06:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5176
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5177
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5178
monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5179
    "return a monochrome device image of the receiver for aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5180
     (monochrome, even if device supports colors)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5181
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5182
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5183
    (device notNil and:[aDevice ~~ device]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5184
	"oops, I am already accociated to another device
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5185
	 - need a copy ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5186
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5187
	^ self copy monochromeOn:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5188
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5189
    monoDeviceForm := self asMonochromeFormOn:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5190
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5191
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5192
nearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5193
    "for compatibility with color protocol - here, the same as #onDevice."
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5194
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5195
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5196
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5197
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5198
on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5199
    "return an image with the same pixels as the receiver, but
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5200
     associated to aDevice. If the receiver is not yet bound to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5201
     a device, this will be the receiver. Otherwise, a new image
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5202
     is returned."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5203
3623
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5204
    "/ send out a warning: #on: is typically used to create views
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5205
    "/ operating on a model.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5206
    "/ Please use #onDevice: to avoid confusion.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5207
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5208
    <resource:#obsolete>
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5209
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5210
    self obsoleteMethodWarning:'use #onDevice:'.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5211
    ^ self onDevice:aDevice
1496
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5212
!
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5213
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5214
onDevice:aDevice
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5215
    "return an image with the same pixels as the receiver, but
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5216
     associated to aDevice. If the receiver is not yet bound to
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5217
     a device, this will be the receiver. Otherwise, a new image
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5218
     is returned."
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5219
2980
409e9547a45c ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  5220
    aDevice isNil ifTrue:[^ self].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5221
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5222
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5223
    (device notNil and:[aDevice ~~ device]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5224
	"oops, I am already accociated to another device
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5225
	 - need a copy ...
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5226
	"
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5227
	^ self copy onDevice:aDevice
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5228
    ].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5229
    deviceForm := self asFormOn:aDevice.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5230
    maskedPixelsAre0 := nil.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5231
    device := aDevice.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5232
    Lobby register:self
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5233
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5234
    "Modified: / 22.8.1998 / 13:34:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5235
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5236
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5237
!Image methodsFor:'converting greyscale images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5238
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5239
greyImageAsFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5240
    "return a grey-deviceForm from the grey image."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5241
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5242
    |pictureDepth nPlanes|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5243
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5244
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5245
    nPlanes := samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5246
    (nPlanes == 2) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5247
	'Image [info]: alpha plane ignored' infoPrintCR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5248
	nPlanes := 1
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5249
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5250
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5251
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5252
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5253
    "monochrome is very easy ..."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5254
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5255
    (pictureDepth == 1) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5256
	^ Form width:width height:height fromArray:bytes on:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5257
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5258
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5259
    (aDevice visualType == #TrueColor) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5260
	^ self greyImageAsTrueColorFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5261
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5262
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5263
    "/ PseudoColor conversion also works for StaticColor,
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5264
    "/ GrayScale and DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5265
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5266
    ^ self greyImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5267
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5268
    "Modified: 19.10.1997 / 05:17:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5269
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5270
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5271
greyImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5272
    "return an 8-bit pseudo Form from the grey image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5273
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5274
    |wideBits pictureDepth f map  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5275
     colorMap usedColors nUsed aColor 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5276
     nColors "{ Class: SmallInteger }"
1766
08b918d293a6 fixed conversion of greyScale images with colorCube
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
  5277
     range id
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5278
     cube nR nG nB grayColors
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5279
     fit|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5280
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5281
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5282
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5283
    (#(2 4 8) includes:pictureDepth) ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5284
	self error:'currently only depth-2, 4 or 8 supported'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5285
	^ nil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5286
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5287
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5288
    wideBits := ByteArray uninitializedNew:(width * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5289
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5290
    (pictureDepth == 8) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5291
	"for 8bits, we scan for used colors first;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5292
	 to avoid allocating too many colors"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5293
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5294
	(grayColors := aDevice fixGrayColors) notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5295
	    DitherAlgorithm == #floydSteinberg ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5296
		f := self
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5297
		       asFloydSteinbergDitheredDepth8FormOn:aDevice 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5298
		       colors:grayColors 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5299
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5300
	    f notNil ifTrue:[^ f].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5301
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5302
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5303
	(cube := aDevice fixColors) notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5304
	    nR := aDevice numFixRed.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5305
	    nG := aDevice numFixGreen.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5306
	    nB := aDevice numFixBlue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5307
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5308
	    DitherAlgorithm == #floydSteinberg ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5309
		f := self
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5310
		       asFloydSteinbergDitheredDepth8FormOn:aDevice 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5311
		       colors:cube 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5312
		       nRed:nR
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5313
		       nGreen:nG
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5314
		       nBlue:nB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5315
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5316
		f := self
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5317
		       asNearestPaintDepth8FormOn:aDevice 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5318
		       colors:cube 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5319
		       nRed:nR
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5320
		       nGreen:nG
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5321
		       nBlue:nB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5322
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5323
	    f notNil ifTrue:[^ f].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5324
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5325
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5326
	usedColors := bytes usedValues.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5327
	nUsed := usedColors max + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5328
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5329
	colorMap := Array new:nUsed.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5330
	range := 100 / 255.0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5331
	usedColors do:[:grey |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5332
	    colorMap at:(grey + 1) put:(Color gray:(range * grey))
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5333
	].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5334
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5335
	nColors := (1 bitShift:pictureDepth).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5336
	colorMap := Array new:nColors.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5337
	range := 100 / (nColors - 1) asFloat.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5338
	1 to:nColors do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5339
	    colorMap at:i put:(Color gray:(i - 1) * range).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5340
	].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5341
    ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5342
    photometric ~~ #blackIs0 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5343
	colorMap reverse
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5344
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5345
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5346
    "allocate those colors & setup the translation map"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5347
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5348
    fit := true.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5349
    map := ByteArray uninitializedNew:256.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5350
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5351
    1 to:nColors do:[:i |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5352
	aColor := colorMap at:i.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5353
	aColor notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5354
	    aColor := aColor onDevice:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5355
	    colorMap at:i put:aColor.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5356
	    id := aColor colorId.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5357
	    id isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5358
		id := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5359
		fit := false.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5360
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5361
	    map at:i put:id
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5362
	]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5363
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5364
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5365
    fit ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5366
	"/ here comes the hard part - some grey value
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5367
	"/ could not be allocated.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5368
	"/ Must dither.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5369
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5370
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5371
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5372
    "expand & translate"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5373
    bytes expandPixels:pictureDepth
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5374
		width:width 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5375
	       height:height
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5376
		 into:wideBits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5377
	      mapping:map.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5378
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5379
    f := Form width:width height:height depth:8 on:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5380
    f isNil ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5381
    f colorMap:colorMap. 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5382
    f initGC.
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5383
    aDevice 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5384
	drawBits:wideBits 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5385
	depth:8 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5386
	padding:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5387
	width:width height:height
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5388
	x:0 y:0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5389
	into:(f id) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5390
	x:0 y:0 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5391
	width:width height:height 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5392
	with:(f gcId).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5393
    ^ f
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  5394
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5395
    "Modified: 19.10.1997 / 05:19:44 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5396
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5397
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5398
greyImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5399
    "return a true-color device-form for the grey-image receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5400
     TODO: the pixel loops ought to be implemented as inline primitive code ..."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5401
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5402
    |depth  
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5403
     myDepth    "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5404
     nColors    "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5405
     colorValues
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5406
     scaleDown 
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5407
     scaleRed   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5408
     scaleGreen "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5409
     scaleBlue  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5410
     redShift   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5411
     blueShift  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5412
     greenShift "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5413
     form bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits 
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  5414
     greyValue  "{ Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5415
     h          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5416
     w          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5417
     pixelArray newPixelArray i|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5418
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5419
    "/ this is a slow fallback method; this ought to be
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5420
    "/ redefined in DepthxImage for more performance.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5421
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5422
    depth := aDevice depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5423
    myDepth := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5424
    myDepth > 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5425
	self error:'unsupported trueColor depth in greyImageAsTrueColorFormOn:'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5426
	^ nil
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5427
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  5428
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5429
    "/ compute scale to map from my pixels into devices range
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5430
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5431
    scaleDown := 1 bitShift:myDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5432
    scaleRed := (1 bitShift:aDevice bitsRed).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5433
    scaleGreen := (1 bitShift:aDevice bitsGreen).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5434
    scaleBlue := (1 bitShift:aDevice bitsBlue).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5435
    redShift := aDevice shiftRed.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5436
    greenShift := aDevice shiftGreen.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5437
    blueShift := aDevice shiftBlue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5438
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5439
    "/ prepare the map
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5440
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5441
    nColors := (1 bitShift:myDepth).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5442
    colorValues := Array new:nColors.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5443
    1 to:nColors do:[:i |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5444
	|v gv bv rv nv|
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5445
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5446
	"/ scale down to 0..1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5447
	v := (i-1) / scaleDown.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5448
	rv := (v * scaleRed) truncated.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5449
	gv := (v * scaleGreen) truncated.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5450
	bv := (v * scaleBlue) truncated.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5451
	nv := rv bitShift:redShift.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5452
	nv := nv bitOr:(gv bitShift:greenShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5453
	nv := nv bitOr:(bv bitShift:blueShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5454
	colorValues at:i put:nv
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5455
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5456
    photometric == #whiteIs0 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5457
	"/ reverse the order; 0 is brightest
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5458
	colorValues reverse
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5459
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5460
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5461
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5462
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5463
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5464
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5465
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5466
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5467
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  5468
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  5469
    i width:width height:height.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5470
    imageBits := ByteArray new:(i bytesPerRow * height).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5471
    i bits:imageBits.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5472
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5473
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5474
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5475
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5476
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5477
    w := width - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5478
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5479
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5480
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5481
    0 to:h do:[:y |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5482
	self rowAt:y into:pixelArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5483
	0 to:w do:[:x |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5484
	    greyValue := pixelArray at:(x+1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5485
	    newPixelArray at:(x+1) put:(colorValues at:greyValue + 1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5486
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5487
	i rowAt:y putAll:newPixelArray.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5488
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5489
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5490
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5491
    form isNil ifTrue:[^ nil].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5492
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5493
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5494
    form 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5495
	copyBitsFrom:imageBits 
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5496
	bitsPerPixel:usedDeviceBitsPerPixel 
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5497
	depth:usedDeviceDepth 
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5498
	padding:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5499
	width:width height:height 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5500
	x:0 y:0 
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5501
	toX:0 y:0. 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5502
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5503
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5504
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5505
    "Created: 20.10.1995 / 22:05:10 / cg"
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  5506
    "Modified: 24.4.1997 / 23:11:16 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5507
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  5508
48194c26a46c Initial revision
claus
parents:
diff changeset
  5509
!Image methodsFor:'converting palette images'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5510
48194c26a46c Initial revision
claus
parents:
diff changeset
  5511
paletteImageAsFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  5512
    "return a device-form for the palette-image receiver"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  5513
380
c5ffc6d48a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
  5514
    |type ddepth|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5515
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5516
    ddepth := aDevice depth.
379
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  5517
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5518
    aDevice hasGrayscales not ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5519
	^ self asMonochromeFormOn:aDevice
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5520
    ].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5521
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5522
    ((type := aDevice visualType) == #StaticGray) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5523
	ddepth == 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5524
	    ^ self paletteImageAsGray8FormOn:aDevice
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5525
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5526
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5527
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5528
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5529
    (type == #TrueColor) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5530
	DitherAlgorithm == #floydSteinberg ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5531
	    ddepth == 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5532
		self depth == 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5533
		    "/ use fixColor dither algorithm
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5534
		    ^ self asDitheredTrueColor8FormOn:aDevice
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5535
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5536
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5537
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5538
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5539
	^ self paletteImageAsTrueColorFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5540
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5541
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5542
    "/ the PseudoColor conversion also works for
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5543
    "/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5544
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5545
    ^ self paletteImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5546
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5547
    "Modified: 14.6.1996 / 19:31:01 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5548
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5549
48194c26a46c Initial revision
claus
parents:
diff changeset
  5550
paletteImageAsPseudoFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  5551
    "return a pseudo-deviceForm from the palette image."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5552
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5553
    |tempImage d temp8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5554
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5555
    d := self depth.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5556
    (#(1 2 4 8) includes:d) ifTrue:[ 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5557
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5558
	 fallback code for some depth's:
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5559
	 create a temporary Depth8Image and use its conversion method
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5560
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5561
	temp8 := ByteArray uninitializedNew:(width * height).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5562
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5563
	bytes expandPixels:d      
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5564
		     width:width 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5565
		   height:height
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5566
		     into:temp8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5567
		  mapping:nil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5568
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5569
	tempImage := Image width:width height:height depth:8 fromArray:temp8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5570
	tempImage colorMap:colorMap.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5571
	^ tempImage paletteImageAsPseudoFormOn:aDevice
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5572
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  5573
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5574
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5575
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5576
paletteImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5577
    "return a true-color device-form for the palette-image receiver."
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5578
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  5579
    |depth 
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  5580
     nColors "{ Class: SmallInteger }"
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  5581
     h       "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  5582
     pixel   "{ Class: SmallInteger }"
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  5583
     colorValues 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5584
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
194
Claus Gittinger <cg@exept.de>
parents: 193
diff changeset
  5585
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel 
1729
9cccc0fcea24 removed unused variables
Claus Gittinger <cg@exept.de>
parents: 1668
diff changeset
  5586
     i pixelArray newPixelArray|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5587
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5588
    "/ this is a slow fallback method; this ought to be
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5589
    "/ redefined in DepthxImage for more performance.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5590
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5591
    depth := aDevice depth.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5592
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5593
    "/ gather r/g/b values for all colors in the map ...
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5594
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5595
    nColors := colorMap size.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5596
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5597
    "/ precompute scales to map from 0..100 into devices range
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5598
    "/ (this may be different for the individual components)
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5599
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5600
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5601
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5602
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5603
    redShift := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5604
    greenShift := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5605
    blueShift := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5606
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5607
    colorValues := Array uninitializedNew:nColors.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5608
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5609
    1 to:nColors do:[:index |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5610
	|clr rv gv bv v "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5611
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5612
	clr := colorMap at:index.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5613
	clr notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5614
	    rv := (clr red * scaleRed) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5615
	    gv := (clr green * scaleGreen) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5616
	    bv := (clr blue * scaleBlue) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5617
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5618
	    v := rv bitShift:redShift.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5619
	    v := v bitOr:(gv bitShift:greenShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5620
	    v := v bitOr:(bv bitShift:blueShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5621
	    colorValues at:index put:v.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5622
"/ clr print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5623
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5624
"/ ' -> ' print. v printNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5625
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5626
	]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5627
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5628
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5629
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5630
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5631
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
2864
dd151bfdff9d care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents: 2832
diff changeset
  5632
    usedDeviceDepth == 1 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5633
	^ self asMonochromeFormOn:aDevice.
2864
dd151bfdff9d care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents: 2832
diff changeset
  5634
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5635
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5636
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5637
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5638
1665
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  5639
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  5640
    i width:width height:height.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5641
    imageBits := ByteArray new:(i bytesPerRow * height).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5642
    i bits:imageBits.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5643
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5644
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5645
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5646
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5647
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5648
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5649
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5650
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  5651
    0 to:h do:[:y |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5652
	self rowAt:y into:pixelArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5653
	1 to:width do:[:x |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5654
	    pixel := pixelArray at:x.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5655
	    newPixelArray at:x put:(colorValues at:pixel + 1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5656
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5657
	i rowAt:y putAll:newPixelArray.
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  5658
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5659
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5660
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5661
    form isNil ifTrue:[^ nil].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5662
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5663
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5664
    form 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5665
	copyBitsFrom:imageBits 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5666
	bitsPerPixel:usedDeviceBitsPerPixel 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5667
	depth:usedDeviceDepth 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5668
	padding:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5669
	width:width height:height 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5670
	x:0 y:0 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5671
	toX:0 y:0. 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5672
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5673
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5674
2185
756d58c52113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2182
diff changeset
  5675
    "Modified: / 24.7.1998 / 00:56:14 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5676
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  5677
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5678
!Image methodsFor:'converting rgb images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5679
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5680
asDitheredTrueColor8FormOn:aDevice
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5681
    "convert an rgb image to a dithered depth8-form on aDevice.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  5682
     Return the device-form. 
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  5683
     This method is only valid for trueColor displays."
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5684
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5685
    |fixColors pixel
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5686
     dstIdx     "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5687
     shiftRed   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5688
     shiftGreen "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5689
     shiftBlue  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5690
     nRed    "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5691
     nGreen  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5692
     nBlue   "{ Class: SmallInteger }"|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5693
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5694
    shiftRed := aDevice shiftRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5695
    shiftGreen := aDevice shiftGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5696
    shiftBlue := aDevice shiftBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5697
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5698
    nRed := (1 bitShift:aDevice bitsRed).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5699
    nGreen := (1 bitShift:aDevice bitsGreen).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5700
    nBlue := (1 bitShift:aDevice bitsBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5701
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5702
    fixColors := Array new:(nRed * nGreen * nBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5703
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5704
    dstIdx := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5705
    0 to:nRed - 1 do:[:sR |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5706
	0 to:nGreen - 1 do:[:sG |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5707
	    0 to:nBlue - 1 do:[:sB |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5708
		pixel := (sR bitShift:shiftRed)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5709
			 + (sG bitShift:shiftGreen)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5710
			 + (sB bitShift:shiftBlue).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5711
		fixColors at:dstIdx put:(Color colorId:(pixel)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5712
		dstIdx := dstIdx + 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5713
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5714
	]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5715
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5716
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5717
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5718
	asFloydSteinbergDitheredDepth8FormOn:aDevice 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5719
	colors:fixColors 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5720
	nRed:nRed nGreen:nGreen nBlue:nBlue
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  5721
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5722
    "Created: 14.6.1996 / 17:23:52 / cg"
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  5723
    "Modified: 23.6.1997 / 15:22:36 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5724
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5725
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5726
rgbImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5727
    "convert am rgb image to a device-form on aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5728
     Return the device-form."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5729
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5730
    |visual|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5731
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5732
    visual := aDevice visualType.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5733
    (visual == #StaticGray) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5734
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5735
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5736
    (visual == #TrueColor) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5737
	^ self rgbImageAsTrueColorFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5738
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5739
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5740
    "/ PseudoColor conversion also works for StaticColor, GrayScale
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5741
    "/ and DirectColor displays; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5742
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5743
    ^ self rgbImageAsPseudoFormOn:aDevice
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5744
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5745
    "Modified: 14.6.1996 / 19:30:06 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5746
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5747
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5748
rgbImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5749
    "return a pseudocolor form from the rgb-picture"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5750
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5751
    |n     "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5752
     depth "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5753
     palette f|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5754
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5755
    (depth := self depth) <= 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5756
	"/ simulate it via a temporary palette image
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5757
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5758
	palette := Array new:(1 bitShift:depth).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5759
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5760
	n := (1 bitShift:depth)-1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5761
	0 to:n do:[:pixelValue |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5762
	    palette at:(pixelValue+1) put:(self colorFromValue:pixelValue)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5763
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5764
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5765
	colorMap := palette.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5766
	photometric := #palette.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5767
	f := self paletteImageAsPseudoFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5768
	colorMap := nil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5769
	photometric := #rgb.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5770
	^ f
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5771
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5772
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5773
    ^ self subclassResponsibility
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5774
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5775
    "Modified: 8.6.1996 / 10:58:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5776
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5777
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5778
rgbImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5779
    "return a truecolor form from the rgb-picture."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5780
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5781
    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5782
     form|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5783
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5784
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5785
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5786
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5787
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5788
    "/ kludge for some 15bit XFree servers (should return 16 here - does not)
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  5789
    usedDeviceBitsPerPixel == 15 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5790
	usedDeviceBitsPerPixel := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  5791
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  5792
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5793
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5794
    "/ only the trivial case, where the depths match
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5795
    "/ is handled here; conversions are supposed to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5796
    "/ be done in concrete subclasses (see D24Image)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5797
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5798
    self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5799
	'Image [warning]: unimplemented trueColor depth in rgbImageAsTrueColorFormOn: ' errorPrint. self bitsPerPixel errorPrintCR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5800
	^ self asMonochromeFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5801
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5802
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5803
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5804
    form isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5805
	'Image [warning]: display bitmap creation failed' errorPrintCR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5806
	^ nil
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5807
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5808
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5809
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5810
    form 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5811
	copyBitsFrom:bytes 
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5812
	bitsPerPixel:usedDeviceBitsPerPixel 
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5813
	depth:usedDeviceDepth 
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5814
	padding:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5815
	width:width height:height 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5816
	x:0 y:0 
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5817
	toX:0 y:0. 
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5818
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5819
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5820
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  5821
    "Modified: 10.1.1997 / 17:53:23 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5822
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5823
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5824
!Image methodsFor:'copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5825
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5826
postCopy
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5827
    "redefined to also copy the pixels and the colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5828
     and clear out any device handles in the copy."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5829
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5830
    bytes := bytes copy.
916
ddc18f6280ed dont deepCopy the colorMap
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
  5831
    colorMap := colorMap copy.
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5832
    device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil.
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5833
    mask := mask copy.
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  5834
    maskedPixelsAre0 := false.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  5835
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  5836
    "Modified: / 22.8.1998 / 11:27:09 / cg"
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5837
!
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5838
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5839
skipInstvarIndexInDeepCopy:index
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5840
    "a helper for deepCopy; only indices for which this method returns
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5841
     false are copied in a deep copy."
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5842
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5843
    index == 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5844
	^ true "/ skip device
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5845
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5846
    index == 13 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5847
	^ true "/ skip deviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5848
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5849
    index == 14 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5850
	^ true "/ skip monoDeviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5851
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5852
    index == 15 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5853
	^ true "/ skip fullColorDeviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5854
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5855
    ^ false
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5856
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5857
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5858
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5859
!Image methodsFor:'displaying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5860
1737
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5861
asImage
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5862
    "ST-80 compatibility
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5863
    "
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5864
    ^ self
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5865
!
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5866
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5867
displayFilledOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  5868
    "display the receiver as an opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5869
     This allows Images to be wrapped by a FillingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5870
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5871
    aGC displayOpaqueForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5872
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5873
    "Created: 29.5.1996 / 10:34:18 / cg"
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  5874
    "Modified: 29.5.1996 / 10:52:36 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5875
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5876
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5877
displayOn:aGC at:aPoint
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5878
    "draw the receiver in the graphicsContext, aGC.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5879
     Smalltalk-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5880
672
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5881
    self displayOn:aGC x:aPoint x y:aPoint y.
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5882
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5883
    "Modified: 12.5.1996 / 20:16:38 / cg"
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5884
!
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5885
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5886
displayOn:aGC x:x y:y
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5887
    "draw the receiver in the graphicsContext, aGC.
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5888
     Smalltalk-80 compatibility"
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5889
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5890
    aGC displayForm:self x:x y:y.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5891
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5892
    "Modified: 23.4.1996 / 11:12:31 / cg"
672
01d7c8b9d2e7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  5893
    "Created: 12.5.1996 / 20:14:31 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5894
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5895
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5896
displayOn:aGC x:x y:y opaque:opaque
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5897
    "draw the receiver in the graphicsContext, aGC.
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5898
     Smalltalk-80 compatibility"
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5899
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5900
    opaque ifTrue:[
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5901
        self displayOpaqueOn:aGC x:x y:y .
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5902
    ] ifFalse:[
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5903
        self displayOn:aGC x:x y:y .
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5904
    ].
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5905
!
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  5906
3379
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  5907
displayOpaqueOn:aGC at:aPoint
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  5908
    "draw the receiver in the graphicsContext, aGC.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  5909
     Smalltalk-80 compatibility"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  5910
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  5911
    self displayOpaqueOn:aGC x:aPoint x y:aPoint y.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  5912
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  5913
    "Modified: 12.5.1996 / 20:16:38 / cg"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  5914
!
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  5915
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  5916
displayOpaqueOn:aGC x:x y:y
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  5917
    "draw the receiver in the graphicsContext, aGC.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  5918
     Smalltalk-80 compatibility"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  5919
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  5920
    aGC displayOpaqueForm:self x:x y:y.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  5921
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  5922
    "Modified: 23.4.1996 / 11:12:31 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  5923
    "Created: 22.10.1996 / 16:35:49 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  5924
!
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  5925
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5926
displayStrokedOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  5927
    "display the receiver as an non opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5928
     This allows Images to be wrapped by a StrokingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5929
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5930
    aGC displayForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  5931
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  5932
    "Created: 29.5.1996 / 10:34:18 / cg"
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  5933
    "Modified: 29.5.1996 / 10:52:30 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5934
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5935
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5936
!Image methodsFor:'dither helpers'!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5937
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5938
burkesDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5939
    "return the bitmap for a dithered monochrome bitmap from the image.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5940
     Works for any source depths / photometric"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5941
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5942
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5943
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5944
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5945
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5946
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5947
     errorArray1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5948
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5949
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5950
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5951
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5952
     byte            "{Class: SmallInteger }" 
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5953
     grey|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5954
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5955
    self depth > 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5956
	^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5957
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5958
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5959
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5960
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5961
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5962
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5963
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5964
    (monoBits isNil or:[bytes isNil]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5965
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5966
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5967
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5968
    errorArray := Array new:(w+4).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5969
    errorArray1 := Array new:(w+4) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5970
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5971
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5972
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5973
    "/ fetch scaled brightness values outside of loop into a table;
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5974
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5975
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5976
    greyValues := self greyMapForRange:(255*1024).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5977
    
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5978
    0 to:(h-1) do:[:y |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5979
	nextDst := dstIndex + bytesPerMonoRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5980
	byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5981
	bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5982
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5983
	t := errorArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5984
	errorArray := errorArray1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5985
	errorArray1 := t.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5986
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5987
	errorArray1 atAllPut:0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5988
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5989
	self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5990
	    |eP "{Class: SmallInteger }" 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5991
	     eD 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5992
	     eI "{Class: SmallInteger }" 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5993
	     xE "{Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5994
	     xN "{Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5995
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5996
	    "/ get the colors grey value [0 .. 1]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5997
	    grey := greyValues at:(pixel + 1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5998
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5999
	    "/ adjust error
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6000
	    xE := x + 2 + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6001
	    grey := (grey + (errorArray at:xE)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6002
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6003
	    byte := byte bitShift:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6004
	    grey > (127*1024) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6005
		byte := byte bitOr:1.      "/ white
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6006
		e := grey - (255*1024)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6007
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6008
		e := grey                  "/ black
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6009
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6010
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6011
	    e ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6012
		"/ distribute the error:
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6013
		"/                  XX  8  4
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6014
		"/             2  4  8  4  2
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6015
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6016
		eD := e.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6017
		eI := e // 32.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6018
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6019
		eP := eI * 8. eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6020
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6021
		xN := xE + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6022
		errorArray at:xN put:(errorArray at:xN) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6023
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6024
		eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6025
		errorArray1 at:xE put:(errorArray1 at:xE) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6026
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6027
		eP := eI * 4. eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6028
		xN := xE + 2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6029
		errorArray at:xN put:(errorArray at:xN) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6030
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6031
		eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6032
		xN := xE - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6033
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6034
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6035
		eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6036
		xN := xE + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6037
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6038
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6039
		eP := eI * 2. eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6040
		xN := xE - 2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6041
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6042
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6043
		eD := eD.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6044
		xN := xE + 2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6045
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6046
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6047
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6048
	    bitCnt := bitCnt - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6049
	    bitCnt == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6050
		monoBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6051
		dstIndex := dstIndex + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6052
		byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6053
		bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6054
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6055
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6056
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6057
	bitCnt ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6058
	    byte := byte bitShift:bitCnt.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6059
	    monoBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6060
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6061
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6062
	dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6063
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6064
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6065
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6066
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6067
    "Created: 10.6.1996 / 12:18:20 / cg"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6068
    "Modified: 10.6.1996 / 13:16:33 / cg"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6069
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6070
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6071
floydSteinbergDitheredDepth8BitsColors:colors
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6072
    "return a floyd-steinberg dithered bitmap from the receiver picture,
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6073
     which must be a depth-8 image. 
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6074
     This method expects an array of colors to be used for dithering
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6075
     (which need not be a colorCubes colors)."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6076
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6077
    ^ self floydSteinbergDitheredDepth8BitsColors:colors map:nil
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6078
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6079
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6080
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6081
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6082
    "return a floyd-steinberg dithered bitmap from the receiver picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6083
     which must be a depth-8 image. 
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6084
     This method expects an array of colors to be used for dithering
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6085
     (which need not be a colorCubes colors)."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6086
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6087
    |pseudoBits  
882
a3181765132b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 879
diff changeset
  6088
     rgbBytes 
a3181765132b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 879
diff changeset
  6089
     ditherRGBBytes ditherColors
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6090
     w       "{Class: SmallInteger }"
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6091
     h       "{Class: SmallInteger }"
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6092
     index   "{Class: SmallInteger }"
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6093
     fixR    "{Class: SmallInteger }"
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6094
     fixG    "{Class: SmallInteger }"
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6095
     fixB    "{Class: SmallInteger }"
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6096
     ditherIds failed map lastColor colorsByDistance qScramble
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6097
     clrLookup lookupPos
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6098
     error clr|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6099
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6100
    self depth ~~ 8 ifTrue:[^ nil].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6101
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6102
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6103
    "/ collect color components as integer values (for integer arithmetic)
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6104
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6105
    rgbBytes := ByteArray uninitializedNew:256 * 3.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6106
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6107
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6108
	lastColor := colorMap size - 1
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6109
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6110
	lastColor := 255.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6111
    ].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6112
    index := 1.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6113
    0 to:lastColor do:[:pix |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6114
	clr := self colorFromValue:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6115
	rgbBytes at:index put:(clr redByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6116
	rgbBytes at:index+1 put:(clr greenByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6117
	rgbBytes at:index+2 put:(clr blueByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6118
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6119
	index := index + 3.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6120
    ].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6121
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6122
    "/ collect valid ditherColors ...
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6123
    aMapOrNil isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6124
	ditherColors := colors select:[:clr | clr notNil].
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6125
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6126
	ditherColors := colors
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6127
    ].
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6128
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6129
    "/ ... and sort by manhatten distance from black
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6130
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6131
    qScramble := #(
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6132
		"/  2rX00X00X00X00
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6133
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6134
		    2r000000000000    "/ 0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6135
		    2r000000000100    "/ 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6136
		    2r000000100000    "/ 2
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6137
		    2r000000100100    "/ 3
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6138
		    2r000100000000    "/ 4
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6139
		    2r000100000100    "/ 5
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6140
		    2r000100100000    "/ 6
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6141
		    2r000100100100    "/ 7
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6142
		    2r100000000000    "/ 8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6143
		    2r100000000100    "/ 9
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6144
		    2r100000100000    "/ a
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6145
		    2r100000100100    "/ b
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6146
		    2r100100000000    "/ c
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6147
		    2r100100000100    "/ d
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6148
		    2r100100100000    "/ e
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6149
		    2r100100100100    "/ f
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6150
		  ).
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6151
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6152
    ditherColors := ditherColors sort:[:a :b |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6153
				|cr "{Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6154
				 cg "{Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6155
				 cb "{Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6156
				 i1 "{Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6157
				 i2 "{Class: SmallInteger }"|
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6158
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6159
				cr := a redByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6160
				cg := a greenByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6161
				cb := a blueByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6162
				i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6163
				i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6164
				i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6165
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6166
				cr := b redByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6167
				cg := b greenByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6168
				cb := b blueByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6169
				i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6170
				i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6171
				i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6172
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6173
				i1 < i2
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6174
		    ].
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6175
    aMapOrNil isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6176
	ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6177
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6178
	ditherIds := aMapOrNil asByteArray
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6179
    ].
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6180
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6181
    "/ build an index table, for fast lookup from manhatten-r-g-b distance
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6182
    "/ to the position in the colorList
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6183
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6184
    clrLookup := ByteArray new:(4096).
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6185
    index := 0.
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6186
    ditherColors keysAndValuesDo:[:clrPosition :clr |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6187
	|r g b i|
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6188
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6189
	r := clr redByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6190
	g := clr greenByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6191
	b := clr blueByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6192
	i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6193
	i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6194
	i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6195
	lookupPos := i.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6196
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6197
	[index < lookupPos] whileTrue:[        
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6198
	    clrLookup at:(index+1) put:(clrPosition-1-1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6199
	    index := index + 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6200
	]
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6201
    ].
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6202
    clrLookup from:index+1 to:4096 put:(ditherColors size - 1).
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6203
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6204
"/    [index <= (4095)] whileTrue:[
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6205
"/        clrLookup at:(index+1) put:(ditherColors size - 1).
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6206
"/        index := index + 1.
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6207
"/    ].
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6208
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6209
    "/ collect ditherColor components
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6210
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6211
    lastColor := ditherColors size.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6212
    ditherIds := ByteArray uninitializedNew:lastColor.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6213
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6214
    index := 1.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6215
    1 to:lastColor do:[:pix |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6216
	clr := ditherColors at:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6217
	ditherRGBBytes at:index put:(clr redByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6218
	ditherRGBBytes at:index+1 put:(clr greenByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6219
	ditherRGBBytes at:index+2 put:(clr blueByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6220
	aMapOrNil isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6221
	    ditherIds at:pix put:clr colorId.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6222
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6223
	    ditherIds at:pix put:(aMapOrNil at:pix).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6224
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6225
	index := index + 3.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6226
    ].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6227
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6228
    pseudoBits := ByteArray uninitializedNew:(width * height).
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6229
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6230
    w := width + 2.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6231
    error := ByteArray uninitializedNew:w*(3*2).
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6232
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6233
    w := width.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6234
    h := height.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6235
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6236
    failed := true.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6237
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6238
%{
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6239
    int __x, __y;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6240
    int __eR, __eG, __eB;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6241
    unsigned char *srcP, *dstP;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6242
    unsigned char *rgbP;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6243
    unsigned char *idP;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6244
    unsigned char *dp;
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6245
    unsigned char *__clrLookup;
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6246
    short *errP, *eP;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6247
    int __fR, __fG, __fB;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6248
    int iR, iG, iB;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6249
    int idx;
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6250
    int __w = __intVal(w);
882
a3181765132b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 879
diff changeset
  6251
    int __h = __intVal(h);
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6252
    int __nColors = __intVal(lastColor);
882
a3181765132b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 879
diff changeset
  6253
    int __wR = -1, __wG, __wB;
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6254
    static int __qScramble[16] = {
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6255
		    0x000 /* 2r000000000000    0 */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6256
		    0x004 /* 2r000000000100    1 */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6257
		    0x020 /* 2r000000100000    2 */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6258
		    0x024 /* 2r000000100100    3 */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6259
		    0x100 /* 2r000100000000    4 */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6260
		    0x104 /* 2r000100000100    5 */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6261
		    0x120 /* 2r000100100000    6 */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6262
		    0x124 /* 2r000100100100    7 */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6263
		    0x800 /* 2r100000000000    8 */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6264
		    0x804 /* 2r100000000100    9 */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6265
		    0x820 /* 2r100000100000    a */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6266
		    0x824 /* 2r100000100100    b */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6267
		    0x900 /* 2r100100000000    c */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6268
		    0x904 /* 2r100100000100    d */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6269
		    0x920 /* 2r100100100000    e */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6270
		    0x924 /* 2r100100100100    f */,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6271
		  };
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6272
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6273
    if (__isByteArray(__INST(bytes))
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6274
     && __isByteArray(pseudoBits)
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6275
     && __isByteArray(rgbBytes)
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6276
     && __isByteArray(ditherRGBBytes)
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6277
     && __isByteArray(ditherIds)
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6278
     && __isByteArray(clrLookup)
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6279
     && __isByteArray(error)) {
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6280
	failed = false;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6281
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6282
	srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6283
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6284
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6285
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6286
	__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6287
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6288
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6289
	/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6290
	 * clear error accumulator
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6291
	 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6292
	eP = errP;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6293
	bzero(eP, (__w+2) * 2 * 3);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6294
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6295
	for (__y=__h; __y>0; __y--) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6296
	    __eR = __eG = __eB = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6297
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6298
	    eP = &(errP[3]);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6299
	    __eR = eP[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6300
	    __eG = eP[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6301
	    __eB = eP[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6302
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6303
	    for (__x=__w; __x>0; __x--) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6304
		int __want;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6305
		int pix;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6306
		int __wantR, __wantG, __wantB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6307
		int idx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6308
		int tR, tG, tB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6309
		int nR, nG, nB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6310
		int dR, dG, dB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6311
		int minDelta, bestIdx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6312
		int cnt;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6313
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6314
		pix = *srcP++;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6315
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6316
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6317
		 * wR, wG and wB is the wanted r/g/b value;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6318
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6319
		idx = pix+pix+pix;  /* pix * 3 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6320
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6321
		__wantR = rgbP[idx] + __eR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6322
		__wantG = rgbP[idx+1] + __eG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6323
		__wantB = rgbP[idx+2] + __eB;
882
a3181765132b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 879
diff changeset
  6324
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6325
#define RED_SCALE 30
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6326
#define GREEN_SCALE 59
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6327
#define BLUE_SCALE 11
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6328
#define GOOD_DELTA 30
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6329
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6330
#define xRED_SCALE 1
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6331
#define xGREEN_SCALE 1
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6332
#define xBLUE_SCALE 1
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6333
#define xGOOD_DELTA 3
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6334
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6335
#define FAST_LOOKUP
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6336
/* #define ONE_SHOT */
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6337
#define NPROBE 8
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6338
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6339
#ifndef FAST_LOOKUP
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6340
		if ((__wantR == __wR)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6341
		 && (__wantG == __wG)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6342
		 && (__wantB == __wB)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6343
		    /*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6344
		     * same color again - reuse last bestMatch
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6345
		     */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6346
		} else 
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6347
#endif
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6348
		{
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6349
		    __wR = __wantR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6350
		    __wG = __wantG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6351
		    __wB = __wantB;
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6352
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6353
#ifdef FAST_LOOKUP
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6354
		    if(__wR > 255) __wR = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6355
		    else if (__wR < 0) __wR = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6356
		    if(__wG > 255) __wG = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6357
		    else if (__wG < 0) __wG = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6358
		    if(__wB > 255) __wB = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6359
		    else if (__wB < 0) __wB = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6360
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6361
		    {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6362
			int lookupIndex;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6363
			int idx, idx0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6364
			int d, delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6365
			unsigned char *dp0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6366
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6367
			dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6368
			lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6369
			lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6370
			lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6371
			idx = bestIdx =__clrLookup[lookupIndex];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6372
			dp += (idx+idx+idx);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6373
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6374
			/* try color at lookupIndex */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6375
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6376
			d = dp[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6377
			delta = (__wR - d) * RED_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6378
			if (delta < 0) delta = -delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6379
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6380
			d = dp[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6381
			if (__wG > d) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6382
			    delta += (__wG - d) * GREEN_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6383
			else 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6384
			    delta += (d - __wG) * GREEN_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6385
			d = dp[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6386
			if (__wB > d) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6387
			    delta += (__wB - d) * BLUE_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6388
			else 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6389
			    delta += (d - __wB) * BLUE_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6390
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6391
			if (delta <= GOOD_DELTA) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6392
			    goto foundBest;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6393
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6394
			minDelta = delta;
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6395
# ifndef ONE_SHOT
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6396
			idx0 = idx; dp0 = dp;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6397
			cnt = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6398
			while ((++cnt <= NPROBE) && (idx > 0)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6399
			    /* try previous color(s) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6400
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6401
			    idx--; dp -= 3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6402
			    d = dp[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6403
			    delta = (__wR - d) * RED_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6404
			    if (delta < 0) delta = -delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6405
			    d = dp[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6406
			    if (__wG > d) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6407
				delta += (__wG - d) * GREEN_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6408
			    else 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6409
				delta += (d - __wG) * GREEN_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6410
			    d = dp[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6411
			    if (__wB > d) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6412
				delta += (__wB - d) * BLUE_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6413
			    else 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6414
				delta += (d - __wB) * BLUE_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6415
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6416
			    if (delta < minDelta) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6417
				bestIdx = idx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6418
				if (delta <= GOOD_DELTA) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6419
				    goto foundBest;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6420
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6421
				minDelta = delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6422
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6423
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6424
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6425
			idx = idx0; dp = dp0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6426
			cnt = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6427
			while ((++cnt <= NPROBE) && (++idx < __nColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6428
			    /* try next color */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6429
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6430
			    dp += 3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6431
			    d = dp[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6432
			    delta = (__wR - d) * RED_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6433
			    if (delta < 0) delta = -delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6434
			    d = dp[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6435
			    if (__wG > d) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6436
				delta += (__wG - d) * GREEN_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6437
			    else 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6438
				delta += (d - __wG) * GREEN_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6439
			    d = dp[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6440
			    if (__wB > d) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6441
				delta += (__wB - d) * BLUE_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6442
			    else 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6443
				delta += (d - __wB) * BLUE_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6444
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6445
			    if (delta < minDelta) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6446
				bestIdx = idx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6447
				if (delta <= GOOD_DELTA) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6448
				    goto foundBest;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6449
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6450
				minDelta = delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6451
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6452
			}
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6453
# endif
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6454
		    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6455
	foundBest: ;
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6456
#else
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6457
/*
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6458
		    if(__wR > 255) __wR = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6459
		    else if (__wR < 0) __wR = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6460
		    if(__wG > 255) __wG = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6461
		    else if (__wG < 0) __wG = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6462
		    if(__wB > 255) __wB = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6463
		    else if (__wB < 0) __wB = 0;
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6464
*/
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6465
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6466
		    /* find the best matching color */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6467
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6468
		    minDelta = 99999;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6469
		    bestIdx = -1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6470
		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6471
		    for (idx = 0; idx<__nColors; idx++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6472
			int d, delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6473
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6474
			d = dp[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6475
			delta = (__wR - d) * RED_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6476
			if (delta < 0) delta = -delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6477
			if (delta < minDelta) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6478
			    d = dp[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6479
			    if (__wG > d) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6480
				delta += (__wG - d) * GREEN_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6481
			    else 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6482
				delta += (d - __wG) * GREEN_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6483
			    if (delta < minDelta) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6484
				d = dp[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6485
				if (__wB > d) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6486
				    delta += (__wB - d) * BLUE_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6487
				else 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6488
				    delta += (d - __wB) * BLUE_SCALE;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6489
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6490
				if (delta < minDelta) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6491
				    bestIdx = idx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6492
				    if (delta <= GOOD_DELTA) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6493
					break;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6494
				    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6495
				    minDelta = delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6496
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6497
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6498
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6499
			dp += 3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6500
		    }
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  6501
#endif
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6502
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6503
		dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6504
		dp += bestIdx * 3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6505
		dR = dp[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6506
		dG = dp[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6507
		dB = dp[2];
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6508
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6509
/*
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6510
printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6511
		__wantR, __wantG, __wantB,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6512
		__wR, __wG, __wB,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6513
		dR, dG, dB);
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6514
*/
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6515
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6516
		 * store the corresponding dither colors colorId
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6517
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6518
		*dstP++ = idP[bestIdx];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6519
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6520
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6521
		 * the new error & distribute the error
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6522
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6523
		__eR = __wantR - dR; 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6524
		if (__eR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6525
		    tR = __eR >> 4;  /* 16th of error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6526
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6527
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6528
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6529
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6530
		    __eR = nR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6531
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6532
		    __eR = eP[3];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6533
		    eP[0] = eP[-3] = eP[3] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6534
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6535
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6536
		__eG = __wantG - dG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6537
		if (__eG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6538
		    tG = __eG >> 4;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6539
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6540
		    eP[1] = tG*5;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6541
		    eP[-2] = tG*3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6542
		    eP[4] = __eG - (tG*15);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6543
		    __eG = nG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6544
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6545
		    __eG = eP[4];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6546
		    eP[1] = eP[-2] = eP[4] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6547
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6548
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6549
		__eB = __wantB - dB; 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6550
		if (__eB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6551
		    tB = __eB >> 4;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6552
		    nB = eP[5] + (tB * 7);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6553
		    eP[2] = tB*5;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6554
		    eP[-1] = tB*3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6555
		    eP[5] = __eB - (tB*15);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6556
		    __eB = nB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6557
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6558
		    __eB = eP[5];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6559
		    eP[2] = eP[-1] = eP[5] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6560
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6561
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6562
		eP += 3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6563
	    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6564
	}
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6565
    }
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6566
%}.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6567
    failed ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6568
	self primitiveFailed.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6569
	^ nil
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6570
    ].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6571
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6572
    ^ pseudoBits
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6573
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6574
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6575
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue 
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6576
    "return a floyd-steinberg dithered bitmap from the receiver picture,
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6577
     which must be a depth-8 image. 
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6578
     This is a special-cased dither method for 8-bit palette images being displayed on
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6579
     an 8-bit pseudoColor display, AND fixColor dithering is used.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6580
     Use the colors in the fixColors array, which must be fixR x fixG x fixB
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6581
     colors assigned to aDevice, such as the preallocated colors of the
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6582
     Color class. 
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6583
     By passing the ditherColors as extra array, this method can
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6584
     also be used to dither an 8bit image into a smaller number of colors,
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6585
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6586
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6587
    |pseudoBits  
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6588
     rgbBytes
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6589
     w       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6590
     h       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6591
     index   "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6592
     fixR    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6593
     fixG    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6594
     fixB    "{Class: SmallInteger }"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6595
     fixGfixB
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6596
     fixIds failed map lastColor 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6597
     rgbIDX  "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6598
     idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6599
     error clr|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6600
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6601
    self depth ~~ 8 ifTrue:[^ nil].
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6602
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6603
    fixR := nRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6604
    fixR == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6605
    fixG := nGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6606
    fixG == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6607
    fixB := nBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6608
    fixB == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6609
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6610
    "/ simple check
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6611
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6612
	self error:'invalid color array passed'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6613
	^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6614
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6615
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6616
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6617
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6618
    "/ collect color components as integer values (for integer arithmetic)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6619
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6620
    rgbBytes := ByteArray uninitializedNew:256 * 3.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6621
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6622
    index := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6623
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6624
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6625
	lastColor := colorMap size - 1
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6626
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6627
	lastColor := 255.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6628
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6629
    0 to:lastColor do:[:pix |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6630
	clr := self colorFromValue:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6631
	rgbBytes at:index put:(clr redByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6632
	rgbBytes at:index+1 put:(clr greenByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6633
	rgbBytes at:index+2 put:(clr blueByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6634
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6635
	index := index + 3.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6636
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6637
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6638
    pseudoBits := ByteArray uninitializedNew:(width * height).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6639
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6640
    w := width + 2.
1636
c30f6644666e dont use bcopy in #floydSteinbergDitheredDepth8BitsColors
Claus Gittinger <cg@exept.de>
parents: 1630
diff changeset
  6641
    error := ByteArray new:w*(3*2).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6642
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6643
    w := width.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6644
    h := height.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6645
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6646
    idxAndErrRBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6647
    idxAndErrGBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6648
    idxAndErrBBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6649
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6650
    fixGfixB := fixG * fixB.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6651
    index := 1.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6652
    0 to:255 do:[:i |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6653
	rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6654
	idxAndErrRBytes at:index put:(rgbIDX * fixGfixB).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6655
	idxAndErrRBytes at:index+1 put:i - (rgbIDX * 255 // (fixR-1)) + 128.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6656
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6657
	rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6658
	idxAndErrGBytes at:index put:(rgbIDX * fixB). 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6659
	idxAndErrGBytes at:index+1 put:i - (rgbIDX * 255 // (fixG-1)) + 128.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6660
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6661
	rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6662
	idxAndErrBBytes at:index put:(rgbIDX ).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6663
	idxAndErrBBytes at:index+1 put:i - (rgbIDX * 255 // (fixB-1)) + 128.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6664
	index := index + 2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6665
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6666
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6667
    failed := true.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6668
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6669
%{
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6670
    int __x, __y;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6671
    int __eR, __eG, __eB;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6672
    unsigned char *srcP, *dstP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6673
    unsigned char *rgbP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6674
    unsigned char *idP;
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6675
    unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes;
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6676
    short *errP, *eP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6677
    int idx;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6678
    int __w = __intVal(w);
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6679
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6680
    if (__isByteArray(__INST(bytes))
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6681
     && __isByteArray(pseudoBits)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6682
     && __isByteArray(rgbBytes)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6683
     && __isByteArray(fixIds)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6684
     && __isByteArray(error)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6685
     && __bothSmallInteger(fixR, fixG)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6686
     && __isSmallInteger(fixB)) {
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6687
	failed = false;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6688
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6689
	srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6690
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6691
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6692
	idP = __ByteArrayInstPtr(fixIds)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6693
	__idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6694
	__idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6695
	__idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6696
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6697
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6698
	eP = errP;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6699
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6700
	for (__y=__intVal(h); __y>0; __y--) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6701
	    __eR = __eG = __eB = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6702
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6703
	    eP = &(errP[3]);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6704
	    __eR = eP[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6705
	    __eG = eP[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6706
	    __eB = eP[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6707
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6708
	    for (__x=__w; __x>0; __x--) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6709
		int __want;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6710
		int pix;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6711
		int idx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6712
		int tR, tG, tB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6713
		int nR, nG, nB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6714
		int iRGB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6715
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6716
		pix = *srcP++;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6717
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6718
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6719
		 * wR, wG and wB is the wanted r/g/b value;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6720
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6721
		pix = pix+pix+pix;  /* pix * 3 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6722
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6723
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6724
		 * compute indexR/G/B and the new error:
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6725
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6726
		__want = rgbP[pix]   + __eR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6727
		if (__want > 255) __want = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6728
		else if (__want < 0) __want = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6729
		__want += __want;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6730
		idx = __idxAndErrRBytes[__want];   
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6731
		__eR = __idxAndErrRBytes[__want+1]; 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6732
		__eR -= 128;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6733
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6734
		__want = rgbP[pix+1] + __eG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6735
		if (__want > 255) __want = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6736
		else if (__want < 0) __want = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6737
		__want += __want;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6738
		idx += __idxAndErrGBytes[__want];   
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6739
		__eG = __idxAndErrGBytes[__want+1]; 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6740
		__eG -= 128;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6741
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6742
		__want = rgbP[pix+2] + __eB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6743
		if (__want > 255) __want = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6744
		else if (__want < 0) __want = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6745
		__want += __want;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6746
		idx += __idxAndErrBBytes[__want];   
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6747
		__eB = __idxAndErrBBytes[__want+1]; 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6748
		__eB -= 128;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6749
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6750
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6751
		 * store the corresponding dither colors colorId
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6752
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6753
		*dstP++ = idP[idx];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6754
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6755
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6756
		 * distribute the error
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6757
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6758
		if (__eR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6759
		    tR = __eR >> 4;  /* 16th of error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6760
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6761
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6762
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6763
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6764
		    __eR = nR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6765
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6766
		    __eR = eP[3];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6767
		    eP[0] = eP[-3] = eP[3] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6768
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6769
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6770
		if (__eG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6771
		    tG = __eG >> 4;  /* 16th of error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6772
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6773
		    eP[1] = tG*5;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6774
		    eP[-2] = tG*3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6775
		    eP[4] = __eG - (tG*15);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6776
		    __eG = nG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6777
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6778
		    __eG = eP[4];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6779
		    eP[1] = eP[-2] = eP[4] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6780
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6781
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6782
		if (__eB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6783
		    tB = __eB >> 4;  /* 16th of error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6784
		    nB = eP[5] + (tB * 7);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6785
		    eP[2] = tB*5;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6786
		    eP[-1] = tB*3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6787
		    eP[5] = __eB - (tB*15);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6788
		    __eB = nB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6789
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6790
		    __eB = eP[5];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6791
		    eP[2] = eP[-1] = eP[5] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6792
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6793
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6794
		eP += 3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6795
	    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6796
	}
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6797
    }
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6798
%}.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6799
    failed ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6800
	self primitiveFailed.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6801
	^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6802
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6803
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6804
    ^ pseudoBits
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6805
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6806
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6807
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6808
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6809
floydSteinbergDitheredGrayBitsDepth:depth
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6810
    "return the bits for dithering a gray image from the image.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6811
     Works for any source depths / photometric, 
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6812
     but possibly slow since each pixel is processed individually.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6813
     Redefined by some subclasses for more performance (D8Image/D24Image)"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6814
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6815
    |dstIndex        "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6816
     nextDst         "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6817
     bytesPerOutRow  "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6818
     outBits greyValues greyErrors greyPixels greyLevels
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6819
     errorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6820
     nextErrorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6821
     t
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6822
     w               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6823
     h               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6824
     bitCnt          "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6825
     byte            "{Class: SmallInteger }" 
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6826
     grey
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6827
     eR eRB eB eLB |
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6828
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6829
    depth > 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6830
	self error:'unimplemented conversion'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6831
	^ nil
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6832
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6833
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6834
    w := width.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6835
    h := height.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6836
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6837
    bytesPerOutRow := ((w * depth) + 7) // 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6838
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6839
    (outBits isNil or:[bytes isNil]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6840
	^ nil
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6841
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6842
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6843
    greyLevels := (1 bitShift:depth) - 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6844
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6845
    errorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6846
    nextErrorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6847
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6848
    nextErrorArray atAllPut:0.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6849
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6850
    dstIndex := 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6851
    bitCnt := 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6852
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6853
    self depth <= 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6854
	"/ fetch scaled brightness values outside of loop into a table;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6855
	"/ use table-value in loop
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6856
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6857
	greyValues := self greyMapForRange:(greyLevels).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6858
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6859
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6860
						   0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6861
					       ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6862
						   v truncated]].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6863
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6864
	greyPixels := ByteArray withAll:greyPixels.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6865
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6866
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6867
						   0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6868
					       ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6869
						   ((v - v truncated) * 1024) truncated
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6870
					       ]].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6871
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6872
	0 to:(h-1) do:[:y |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6873
	    nextDst := dstIndex + bytesPerOutRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6874
	    byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6875
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6876
	    t := errorArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6877
	    errorArray := nextErrorArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6878
	    nextErrorArray := t.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6879
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6880
	    nextErrorArray atAllPut:0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6881
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6882
	    self valuesAtY:y from:0 to:(w-1) do:[:x :value |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6883
		|e     "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6884
		 pixel "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6885
		 error "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6886
		 e16   "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6887
		 xE    "{ Class: SmallInteger }" 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6888
		 xN    "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6889
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6890
		pixel := greyPixels at:(value + 1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6891
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6892
		"/ adjust error
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6893
		xE := x + 2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6894
		error := (greyErrors at:(value + 1)) + (errorArray at:xE).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6895
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6896
		byte := byte bitShift:depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6897
		error > 512 "0.5" ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6898
		    pixel := pixel + 1.      
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6899
		    e := error - 1024 "1.0"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6900
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6901
		    e := error              
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6902
		].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6903
		byte := byte bitOr:pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6904
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6905
		e ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6906
		    e16 := e // 16.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6907
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6908
		    eR  := e16 * 7.              "/ 7/16 to right
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6909
		    eRB := e16 * 1.              "/ 1/16 to right below
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6910
		    eB  := e16 * 5.              "/ 5/16 to below
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6911
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6912
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6913
		    xN := xE + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6914
		    eR ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6915
			errorArray     at:xN put:(errorArray at:xN) + eR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6916
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6917
		    eRB ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6918
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6919
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6920
		    eB ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6921
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6922
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6923
		    eLB ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6924
			xN := xE - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6925
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6926
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6927
		].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6928
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6929
		bitCnt := bitCnt - depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6930
		bitCnt == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6931
		    outBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6932
		    dstIndex := dstIndex + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6933
		    byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6934
		    bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6935
		].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6936
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6937
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6938
	    bitCnt ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6939
		byte := byte bitShift:bitCnt.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6940
		outBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6941
		bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6942
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6943
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6944
	    dstIndex := nextDst.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6945
	].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6946
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6947
	0 to:(h-1) do:[:y |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6948
	    nextDst := dstIndex + bytesPerOutRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6949
	    byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6950
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6951
	    t := errorArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6952
	    errorArray := nextErrorArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6953
	    nextErrorArray := t.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6954
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6955
	    nextErrorArray atAllPut:0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6956
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6957
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6958
		|e     "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6959
		 pixel "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6960
		 error "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6961
		 e16   "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6962
		 xE    "{ Class: SmallInteger }" 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6963
		 xN    "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6964
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6965
		grey := (clr brightness * greyLevels).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6966
		pixel := grey truncated.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6967
		error := ((grey - pixel) * 1024) truncated.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6968
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6969
		"/ adjust error
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6970
		xE := x + 2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6971
		error := error + (errorArray at:xE).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6972
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6973
		byte := byte bitShift:depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6974
		error > 512 "0.5" ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6975
		    pixel := pixel + 1.      
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6976
		    e := error - 1024 "1.0"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6977
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6978
		    e := error              
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6979
		].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6980
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6981
		byte := byte bitOr:pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6982
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6983
		e ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6984
		    e16 := e // 16.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6985
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6986
		    eR  := e16 * 7.              "/ 7/16 to right
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6987
		    eRB := e16 * 1.              "/ 1/16 to right below
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6988
		    eB  := e16 * 5.              "/ 5/16 to below
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6989
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6990
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6991
		    xN := xE + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6992
		    eR ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6993
			errorArray     at:xN put:(errorArray at:xN) + eR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6994
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6995
		    eRB ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6996
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6997
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6998
		    eB ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6999
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7000
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7001
		    eLB ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7002
			xN := xE - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7003
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7004
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7005
		].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7006
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7007
		bitCnt := bitCnt - depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7008
		bitCnt == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7009
		    outBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7010
		    dstIndex := dstIndex + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7011
		    byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7012
		    bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7013
		].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7014
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7015
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7016
	    bitCnt ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7017
		byte := byte bitShift:bitCnt.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7018
		outBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7019
		bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7020
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7021
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7022
	    dstIndex := nextDst.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7023
	].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7024
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7025
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7026
    ^ outBits
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7027
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7028
    "Created: 10.6.1996 / 13:28:22 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7029
    "Modified: 11.6.1996 / 00:13:38 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7030
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7031
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7032
floydSteinbergDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7033
    "return the bitmap for a dithered monochrome bitmap from the image.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7034
     Works for any source depths / photometric, 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7035
     but very very slow since each pixel is processed individually.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7036
     Redefined by some subclasses for more performance (D8Image)"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7037
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7038
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7039
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7040
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7041
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7042
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7043
     nextErrorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7044
     e eD t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7045
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7046
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7047
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7048
     byte            "{Class: SmallInteger }" 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7049
     grey dT 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7050
     eR eRB eB eLB |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7051
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7052
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7053
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7054
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7055
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7056
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7057
    (monoBits isNil or:[bytes isNil]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7058
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7059
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7060
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7061
    errorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7062
    nextErrorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7063
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7064
    nextErrorArray atAllPut:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7065
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7066
    dstIndex := 1.
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7067
    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7068
    byte := 0.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7069
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7070
    self depth <= 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7071
	"/ fetch scaled brightness values outside of loop into a table;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7072
	"/ use table-value in loop
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7073
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7074
	greyValues := self greyMapForRange:(255 * 1024).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7075
	greyValues := greyValues collect:[:v | v rounded].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7076
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7077
	0 to:(h-1) do:[:y |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7078
	    nextDst := dstIndex + bytesPerMonoRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7079
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7080
	    t := errorArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7081
	    errorArray := nextErrorArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7082
	    nextErrorArray := t.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7083
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7084
	    nextErrorArray atAllPut:0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7085
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7086
	    self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7087
%{
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7088
		int __grey, __e;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7089
		int __byte = __intVal(byte);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7090
		OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7091
		OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7092
		int __x = __intVal(x);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7093
		int __eR, __eB, __eRB, __eLB, __eI;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7094
		int __bitCnt = __intVal(bitCnt);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7095
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7096
		__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7097
		__grey += __intVal(__errorArray[__x+1]);
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7098
                
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7099
		__byte <<= 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7100
		if (__grey > 127*1024) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7101
		    __e = __grey - (255*1024);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7102
		    __byte |= 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7103
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7104
		    __e = __grey;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7105
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7106
		if (__e) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7107
		    __eI = __e >> 4;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7108
		    __eR  = __eI * 7;            
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7109
		    __eRB = __eI * 1;            
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7110
		    __eB  = __eI * 5;            
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7111
		    __eLB = __e - __eR - __eRB - __eB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7112
		    __errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7113
		    __nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7114
		    __nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7115
		    __nextErrorArray[__x  ] = __MKSMALLINT(__intVal(__nextErrorArray[__x  ]) + __eLB);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7116
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7117
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7118
		__bitCnt--;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7119
		if (__bitCnt == 0) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7120
		    int __dstIndex = __intVal(dstIndex);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7121
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7122
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7123
		    dstIndex = __MKSMALLINT(__dstIndex + 1);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7124
		    __byte = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7125
		    __bitCnt = 8;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7126
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7127
		byte = __MKSMALLINT(__byte);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7128
		bitCnt = __MKSMALLINT(__bitCnt);
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7129
%}.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7130
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  7131
"/                |eI "{ Class: SmallInteger }" 
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  7132
"/                 xE "{ Class: SmallInteger }" 
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  7133
"/                 xN "{ Class: SmallInteger }" |
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  7134
"/
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7135
"/                "/ get the colors grey value [0 .. 1]
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7136
"/                grey := greyValues at:(pixel + 1).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7137
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7138
"/                "/ adjust error
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7139
"/                xE := x + 2.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7140
"/                grey := (grey + (errorArray at:xE)).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7141
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7142
"/                byte := byte bitShift:1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7143
"/                grey > (127*1024) ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7144
"/                    byte := byte bitOr:1.      "/ white
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7145
"/                    e := grey - (255*1024)
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7146
"/                ] ifFalse:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7147
"/                    e := grey                  "/ black
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7148
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7149
"/                e ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7150
"/                    eD := e.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7151
"/                    eI := e // 16.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7152
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7153
"/                    eR  := eI * 7.              "/ 7/16 to right
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7154
"/                    eRB := eI * 1.              "/ 1/16 to right below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7155
"/                    eB  := eI * 5.              "/ 5/16 to below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7156
"/                    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7157
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7158
"/                    xN := xE + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7159
"/                    eR ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7160
"/                        errorArray     at:xN put:(errorArray at:xN) + eR.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7161
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7162
"/                    eRB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7163
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7164
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7165
"/                    eB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7166
"/                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7167
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7168
"/                    eLB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7169
"/                        xN := xE - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7170
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7171
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7172
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7173
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7174
"/                bitCnt := bitCnt - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7175
"/                bitCnt == 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7176
"/                    monoBits at:dstIndex put:byte.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7177
"/                    dstIndex := dstIndex + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7178
"/                    byte := 0.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7179
"/                    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7180
"/                ].
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7181
		  0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7182
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7183
	    bitCnt ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7184
		byte := byte bitShift:bitCnt.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7185
		monoBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7186
		bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7187
		byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7188
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7189
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7190
	    dstIndex := nextDst.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7191
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7192
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7193
	'Image [info]: slow floydSteinberg dither ..' infoPrintCR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7194
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7195
	0 to:(h-1) do:[:y |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7196
	    nextDst := dstIndex + bytesPerMonoRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7197
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7198
	    t := errorArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7199
	    errorArray := nextErrorArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7200
	    nextErrorArray := t.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7201
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7202
	    nextErrorArray atAllPut:0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7203
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7204
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7205
		|eI "{ Class: SmallInteger }" 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7206
		 xE "{ Class: SmallInteger }" 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7207
		 xN "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7208
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7209
		"/ get the colors grey value [0 .. 1]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7210
		grey := (clr brightness * 255).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7211
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7212
		"/ adjust error
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7213
		xE := x + 2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7214
		grey := (grey + (errorArray at:xE)) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7215
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7216
		byte := byte bitShift:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7217
		grey > 127 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7218
		    byte := byte bitOr:1.      "/ white
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7219
		    e := grey - 255
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7220
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7221
		    e := grey                  "/ black
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7222
		].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7223
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7224
		e ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7225
		    eD := e.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7226
		    eI := e // 16.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7227
		    eR  := eI * 7.              "/ 7/16 to right
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7228
		    eRB := eI * 1.              "/ 1/16 to right below
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7229
		    eB  := eI * 5.              "/ 5/16 to below
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7230
		    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7231
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7232
		    xN := xE + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7233
		    eR ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7234
			errorArray     at:xN put:(errorArray at:xN) + eR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7235
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7236
		    eRB ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7237
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7238
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7239
		    eB ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7240
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7241
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7242
		    eLB ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7243
			xN := xE - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7244
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7245
		    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7246
		].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7247
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7248
		bitCnt := bitCnt - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7249
		bitCnt == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7250
		    monoBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7251
		    dstIndex := dstIndex + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7252
		    byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7253
		    bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7254
		].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7255
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7256
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7257
	    bitCnt ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7258
		byte := byte bitShift:bitCnt.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7259
		monoBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7260
		bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7261
		byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7262
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7263
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7264
	    dstIndex := nextDst.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7265
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7266
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7267
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7268
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7269
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7270
    "Created: 8.6.1996 / 16:39:46 / cg"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7271
    "Modified: 10.6.1996 / 15:12:11 / cg"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7272
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7273
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7274
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7275
    "return a nearest paint bitmap from the receiver picture,
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7276
     which must be a depth-8 image. 
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7277
     This is a special-cased dither method for 8-bit palette images being displayed on
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7278
     an 8-bit pseudoColor display, AND fixColor dithering is used.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7279
     Use the colors in the fixColors array, which must be fixR x fixG x fixB
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7280
     colors assigned to aDevice, such as the preallocated colors of the
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7281
     Color class."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7282
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7283
    |pseudoBits  
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7284
     fixR    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7285
     fixG    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7286
     fixB    "{Class: SmallInteger }"
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7287
     fixGfixB 
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7288
     r       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7289
     g       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7290
     b       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7291
     idx     "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7292
     idMap lastColor 
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7293
     clr|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7294
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7295
    self depth ~~ 8 ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7296
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7297
    fixR := nRed.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7298
    fixR == 0 ifTrue:[ ^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7299
    fixG := nGreen.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7300
    fixG == 0 ifTrue:[ ^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7301
    fixB := nBlue.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7302
    fixB == 0 ifTrue:[ ^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7303
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7304
    "/ simple check
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7305
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7306
	self error:'invalid color array passed'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7307
	^ nil
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7308
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7309
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7310
    "/
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7311
    "/ collect colorIds
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7312
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7313
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7314
	lastColor := colorMap size - 1
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7315
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7316
	lastColor := 255.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7317
    ].
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7318
    fixGfixB := fixG * fixB.
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7319
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7320
    idMap := ByteArray uninitializedNew:256.
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7321
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7322
    0 to:lastColor do:[:pix |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7323
	clr := self colorFromValue:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7324
	r := clr redByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7325
	g := clr greenByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7326
	b := clr blueByte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7327
	idx := ((r * (fixR-1) + 128) // 255) * fixGfixB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7328
	idx := idx + (((g * (fixG-1) + 128) // 255) * fixB).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7329
	idx := idx + ((b * (fixB-1) + 128) // 255).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7330
	idMap at:(pix+1) put:(fixColors at:(idx+1)) colorId.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7331
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7332
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7333
    pseudoBits := ByteArray uninitializedNew:(width * height).
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7334
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7335
    "/ translate
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7336
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7337
    bytes expandPixels:8         "xlate only"
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7338
		width:width 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7339
	       height:height
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7340
		 into:pseudoBits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7341
	      mapping:idMap.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7342
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7343
    ^ pseudoBits
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7344
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7345
    "Modified: 18.6.1996 / 09:18:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7346
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7347
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7348
nfloydSteinbergDitheredDepth8BitsColors:colors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7349
    "return a floyd-steinberg dithered bitmap from the receiver picture,
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7350
     which must be a depth-8 image. 
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7351
     This method expects an array of colors to be used for dithering
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7352
     (which need not be a colorCubes colors)."
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7353
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7354
    |pseudoBits  
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7355
     rgbBytes 
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7356
     ditherRGBBytes ditherColors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7357
     w       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7358
     h       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7359
     index   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7360
     numR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7361
     numG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7362
     numB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7363
     bitsR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7364
     bitsG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7365
     bitsB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7366
     maxBits  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7367
     maskR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7368
     maskG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7369
     maskB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7370
     shR      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7371
     shG      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7372
     shB      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7373
     ditherIds failed map lastColor colorsByDistance qScramble
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7374
     clrLookup lookupPos cube nCube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7375
     dR  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7376
     dG  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7377
     dB  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7378
     iR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7379
     iRG   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7380
     iRGB  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7381
     clr 
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7382
     rI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7383
     gI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7384
     bI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7385
     maxIDX  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7386
     subCubeColorCollection
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7387
     error 
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7388
     dl "{Class: SmallInteger }"|
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7389
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7390
    self depth ~~ 8 ifTrue:[^ nil].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7391
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7392
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7393
    "/ collect color components as integer values (for integer arithmetic)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7394
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7395
    rgbBytes := ByteArray uninitializedNew:256 * 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7396
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7397
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7398
	lastColor := colorMap size - 1
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7399
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7400
	lastColor := 255.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7401
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7402
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7403
    0 to:lastColor do:[:pix |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7404
	clr := self colorFromValue:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7405
	rgbBytes at:index put:(clr redByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7406
	rgbBytes at:index+1 put:(clr greenByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7407
	rgbBytes at:index+2 put:(clr blueByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7408
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7409
	index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7410
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7411
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7412
    "/ collect valid ditherColors ...
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7413
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7414
    ditherColors := colors select:[:clr | clr notNil].
1845
6860bd2c4684 care to not use invalid ditherColors in nfloyd*
Claus Gittinger <cg@exept.de>
parents: 1815
diff changeset
  7415
    ditherColors := ditherColors select:[:clr | clr colorId notNil].
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7416
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7417
    "/ collect ditherColor components
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7418
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7419
    lastColor := ditherColors size.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7420
    ditherIds := ByteArray uninitializedNew:lastColor.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7421
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7422
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7423
    1 to:lastColor do:[:pix |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7424
	clr := ditherColors at:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7425
	ditherRGBBytes at:index put:(clr redByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7426
	ditherRGBBytes at:index+1 put:(clr greenByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7427
	ditherRGBBytes at:index+2 put:(clr blueByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7428
	ditherIds at:pix put:clr colorId.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7429
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7430
	index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7431
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7432
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7433
    "/ place the ditherColor positions into a color cube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7434
    bitsR := 5.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7435
    bitsG := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7436
    bitsB := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7437
    maxBits := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7438
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7439
"/    bitsR := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7440
"/    bitsG := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7441
"/    bitsB := 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7442
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7443
    numR := 1 bitShift:bitsR.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7444
    numG := 1 bitShift:bitsG.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7445
    numB := 1 bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7446
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7447
    maskR := (numR-1) bitShift:(bitsG + bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7448
    maskG := (numG-1) bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7449
    maskB := numB-1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7450
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7451
    shR := -16+bitsR+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7452
    shG := -16+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7453
    shB := -16+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7454
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7455
    maxIDX := numR*numG*numB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7456
    cube := Array new:maxIDX.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7457
    1 to:lastColor do:[:clrIdx |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7458
	clr := ditherColors at:clrIdx.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7459
	rI := clr scaledRed. rI := (rI bitShift:shR) bitAnd:maskR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7460
	gI := clr scaledGreen. gI := (gI bitShift:shG) bitAnd:maskG.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7461
	bI := clr scaledBlue. bI := (bI bitShift:shB) bitAnd:maskB.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7462
	index := rI + gI + bI + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7463
	subCubeColorCollection := cube at:index.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7464
	subCubeColorCollection isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7465
	    subCubeColorCollection := OrderedCollection new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7466
	    cube at:index put:subCubeColorCollection.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7467
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7468
	subCubeColorCollection add:(clrIdx - 1).
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7469
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7470
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7471
    shR := 1 bitShift:(bitsG+bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7472
    shG := 1 bitShift:(bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7473
    shB := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7474
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7475
    1 to:maxIDX do:[:i |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7476
	subCubeColorCollection := cube at:i.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7477
	subCubeColorCollection notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7478
	    cube at:i put:(subCubeColorCollection asByteArray)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7479
	]
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7480
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7481
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7482
"/    nCube := cube copy.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7483
"/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7484
"/    cube keysAndValuesDo:[:i :indices |
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7485
"/        indices notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7486
"/            nCube at:i put:(indices asByteArray)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7487
"/        ] ifFalse:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7488
"/            "/ find nearest color
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7489
"/        
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7490
"/            dl := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7491
"/            [dl < maxBits] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7492
"/                dR := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7493
"/                [dR <= dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7494
"/                    iR := i + (dR * shR).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7495
"/                    (iR > 0 and:[iR < maxIDX]) ifTrue:[    
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7496
"/                        dG := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7497
"/                        [dG < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7498
"/                            iRG := iR + (dG * shG).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7499
"/                            (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7500
"/                                dB := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7501
"/                                [dB < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7502
"/                                    iRGB := iRG + dB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7503
"/                                    (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7504
"/                                        (cube at:iRGB) notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7505
"/                                            nCube at:i put:(cube at:iRGB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7506
"/                                            dB := dG := dR := dl := 999.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7507
"/                                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7508
"/                                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7509
"/                                    dB := dB + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7510
"/                                ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7511
"/                            ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7512
"/                            dG := dG + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7513
"/                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7514
"/                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7515
"/                    dR := dR + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7516
"/                ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7517
"/                dl := dl + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7518
"/            ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7519
"/        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7520
"/    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7521
"/self halt.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7522
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7523
    "/ now, cube contains collections of colors which are
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7524
    "/ positioned in a subCube; quickly accessed by a lookup 
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7525
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7526
    pseudoBits := ByteArray uninitializedNew:(width * height).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7527
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7528
    w := width.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7529
    h := height.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7530
    error := ByteArray new:(w+2)*3*2.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7531
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7532
%{
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7533
#define BITSR   5
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7534
#define BITSG   6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7535
#define BITSB   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7536
#define MAXBITS 6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7537
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7538
#define xBITSR   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7539
#define xBITSG   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7540
#define xBITSB   3
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7541
#define xMAXBITS 4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7542
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7543
#define NR      32 /* (1<<BITSR) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7544
#define NG      64 /* (1<<BITSG) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7545
#define NB      16 /* (1<<BITSB) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7546
#define MAXRGB  64 /* (1<<MAXBITS) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7547
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7548
#define SHR     (BITSG+BITSB)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7549
#define SHG     BITSB
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7550
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7551
#define REMEMBER_SEARCH
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7552
#define xNO_FLOYD_STEINBERG
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7553
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7554
    int __x, __y;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7555
    int __eR, __eG, __eB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7556
    unsigned char *srcP, *dstP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7557
    unsigned char *rgbP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7558
    unsigned char *idP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7559
    short *errP, *eP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7560
    int __fR, __fG, __fB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7561
    int idx;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7562
    int __w = __intVal(w);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7563
    int __h = __intVal(h);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7564
    int __nColors = __intVal(lastColor);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7565
    int __wR = -1, __wG, __wB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7566
    OBJ *__cube;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7567
    int cubeIndex, cubeIndex2;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7568
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7569
    if (__isByteArray(__INST(bytes))
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7570
     && __isByteArray(pseudoBits)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7571
     && __isByteArray(rgbBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7572
     && __isByteArray(ditherRGBBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7573
     && __isByteArray(ditherIds)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7574
     && __isByteArray(error)) {
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7575
	failed = false;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7576
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7577
	srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7578
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7579
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7580
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7581
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7582
	__cube = __ArrayInstPtr(cube)->a_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7583
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7584
	eP = errP;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7585
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7586
	for (__y=__h; __y>0; __y--) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7587
	    eP = &(errP[3]);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7588
	    __eR = eP[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7589
	    __eG = eP[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7590
	    __eB = eP[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7591
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7592
	    for (__x=__w; __x>0; __x--) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7593
		int __want;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7594
		int pix;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7595
		int __wantR, __wantG, __wantB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7596
		int idx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7597
		int tR, tG, tB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7598
		int nR, nG, nB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7599
		int __dR, __dG, __dB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7600
		int minDelta, bestIdx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7601
		int __iR, __iG, __iB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7602
		int cR, cG, cB;   
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7603
		int delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7604
		OBJ subCubeColors;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7605
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7606
		pix = *srcP++;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7607
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7608
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7609
		 * wR, wG and wB is the wanted r/g/b value;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7610
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7611
		idx = pix+pix+pix;  /* pix * 3 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7612
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7613
		__wR = __wantR = rgbP[idx] + __eR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7614
		__wG = __wantG = rgbP[idx+1] + __eG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7615
		__wB = __wantB = rgbP[idx+2] + __eB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7616
		if(__wR > 255) __wR = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7617
		else if (__wR < 0) __wR = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7618
		if(__wG > 255) __wG = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7619
		else if (__wG < 0) __wG = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7620
		if(__wB > 255) __wB = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7621
		else if (__wB < 0) __wB = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7622
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7623
		__iR = __wR >> (8-BITSR);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7624
		__iG = __wG >> (8-BITSG);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7625
		__iB = __wB >> (8-BITSB);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7626
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7627
		cubeIndex = (__iR<<SHR) + (__iG<<SHG) + __iB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7628
		subCubeColors = __cube[cubeIndex];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7629
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7630
		if (subCubeColors == nil) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7631
		    /* search around in spirals, for the first match */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7632
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7633
		    delta = 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7634
		    while (delta < MAXRGB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7635
			/* check plane above */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7636
			cR = __iR + delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7637
			if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7638
			    for (cG=__iG-delta; cG<=__iG+delta; cG++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7639
				if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7640
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7641
					if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7642
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7643
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7644
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7645
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7646
					    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7647
					}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7648
				    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7649
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7650
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7651
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7652
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7653
			/* check plane below */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7654
			cR = __iR - delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7655
			if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7656
			    for (cG=__iG-delta; cG<=__iG+delta; cG++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7657
				if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7658
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7659
					if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7660
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7661
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7662
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7663
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7664
					    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7665
					}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7666
				    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7667
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7668
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7669
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7670
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7671
			/* check plane to the right */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7672
			cG = __iG + delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7673
			if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7674
			    for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7675
				if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7676
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7677
					if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7678
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7679
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7680
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7681
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7682
					    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7683
					}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7684
				    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7685
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7686
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7687
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7688
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7689
			/* check plane to the left */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7690
			cG = __iG - delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7691
			if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7692
			    for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7693
				if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7694
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7695
					if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7696
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7697
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7698
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7699
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7700
					    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7701
					}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7702
				    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7703
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7704
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7705
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7706
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7707
			/* check plane at back */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7708
			cB = __iB + delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7709
			if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7710
			    for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7711
				if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7712
				    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7713
					if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7714
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7715
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7716
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7717
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7718
					    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7719
					}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7720
				    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7721
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7722
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7723
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7724
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7725
			/* check plane at front */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7726
			cB = __iB - delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7727
			if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7728
			    for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7729
				if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7730
				    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7731
					if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7732
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7733
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7734
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7735
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7736
					    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7737
					}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7738
				    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7739
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7740
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7741
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7742
			delta = delta + 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7743
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7744
		    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7745
		    /* cannot happen - will lead to a segmentation violation ... */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7746
		    subCubeColors = nil;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7747
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7748
    found:
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7749
		    __iR = cR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7750
		    __iG = cG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7751
		    __iB = cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7752
		    bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7753
#ifdef REMEMBER_SEARCH
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7754
		    __cube[cubeIndex] = __MKSMALLINT(bestIdx);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7755
#endif
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7756
		} else {
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7757
#ifdef REMEMBER_SEARCH
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7758
		    if (__isSmallInteger(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7759
			bestIdx = __intVal(subCubeColors);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7760
		    } else 
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7761
#endif
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7762
		    {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7763
			bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7764
		    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7765
		}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7766
                
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7767
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7768
		 * ok, now, we have found a collection of nearby
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7769
		 * colors in subCubeColors.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7770
		 *
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7771
		 * since the error is at most 1/16 (i.e. roughly 6%),
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7772
		 * dont care for searching the best - simply take the
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7773
		 * first color found there.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7774
		 * (statistic reduces the error to even a smaller value).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7775
		 * There is no real problem due to that error, since
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7776
		 * it will be diffused anyway ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7777
		 */
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7778
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7779
#ifndef NO_FLOYD_STEINBERG
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7780
		{
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7781
		    unsigned char *dp;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7782
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7783
		    /*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7784
		     * fetch that colors r/g/b components
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7785
		     */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7786
		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7787
		    dp += bestIdx * 3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7788
		    __dR = dp[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7789
		    __dG = dp[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7790
		    __dB = dp[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7791
		}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7792
#endif
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7793
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7794
/*
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7795
printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7796
		__wantR, __wantG, __wantB,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7797
		__wR, __wG, __wB,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7798
		__dR, __dG, __dB);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7799
*/
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7800
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7801
		 * store the corresponding dither colors colorId
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7802
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7803
		*dstP++ = idP[bestIdx];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7804
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7805
#ifndef NO_FLOYD_STEINBERG
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7806
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7807
		 * the new error & distribute the error
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7808
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7809
		__eR = __wantR - __dR; 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7810
		if (__eR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7811
		    tR = __eR >> 4;  /* 16th of error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7812
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7813
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7814
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7815
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7816
		    __eR = nR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7817
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7818
		    __eR = eP[3];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7819
		    eP[0] = eP[-3] = eP[3] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7820
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7821
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7822
		__eG = __wantG - __dG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7823
		if (__eG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7824
		    tG = __eG >> 4;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7825
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7826
		    eP[1] = tG*5;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7827
		    eP[-2] = tG*3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7828
		    eP[4] = __eG - (tG*15);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7829
		    __eG = nG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7830
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7831
		    __eG = eP[4];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7832
		    eP[1] = eP[-2] = eP[4] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7833
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7834
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7835
		__eB = __wantB - __dB; 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7836
		if (__eB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7837
		    tB = __eB >> 4;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7838
		    nB = eP[5] + (tB * 7);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7839
		    eP[2] = tB*5;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7840
		    eP[-1] = tB*3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7841
		    eP[5] = __eB - (tB*15);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7842
		    __eB = nB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7843
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7844
		    __eB = eP[5];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7845
		    eP[2] = eP[-1] = eP[5] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7846
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7847
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7848
		eP += 3;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7849
#endif
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7850
	    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7851
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7852
	    /*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7853
	     * allow for an interrupt after every row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7854
	     * but care to refetch C variables
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7855
	     */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7856
	    if (InterruptPending) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7857
		int d_srcP = srcP - __ByteArrayInstPtr(_INST(bytes))->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7858
		int d_dstP = dstP - __ByteArrayInstPtr(pseudoBits)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7859
		int d_errP = errP - (short *) __ByteArrayInstPtr(error)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7860
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7861
		__interrupt__();
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7862
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7863
		srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element + d_srcP;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7864
		dstP = __ByteArrayInstPtr(pseudoBits)->ba_element + d_dstP;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7865
		rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7866
		idP = __ByteArrayInstPtr(ditherIds)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7867
		errP = (short *) __ByteArrayInstPtr(error)->ba_element + d_errP;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7868
		__cube = __ArrayInstPtr(cube)->a_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7869
	    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7870
	}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7871
    }
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7872
%}.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7873
    failed ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7874
	self primitiveFailed.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7875
	^ nil
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7876
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7877
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7878
    ^ pseudoBits
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7879
!
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7880
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7881
orderedDitheredGrayBitsDepth:depth
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7882
    "return the bitmap for a dithered depth-bitmap from the image"
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7883
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7884
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7885
	orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7886
	ditherWidth:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7887
	depth:depth.
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7888
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7889
    "Created: 24.6.1997 / 22:20:12 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7890
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7891
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7892
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7893
    "return the bitmap for a dithered depth-bitmap from the image;
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7894
     with a constant ditherMatrix, this can be used for thresholding.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7895
     Works for any source depths / photometric, 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7896
     but very very slow since each pixel is processed individually.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7897
     Redefined by some subclasses for more performance (D8Image)"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7898
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7899
    |f last dH nDither   
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7900
     greyLevels greyValues greyPixels greyErrors
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7901
     dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7902
     nextDst         
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7903
     bytesPerOutRow  "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7904
     pixelsPerByte   "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7905
     outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7906
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7907
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7908
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7909
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7910
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7911
    depth > 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7912
	'IMAGE: unimplemented orderedDither conversion' errorPrintCR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7913
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7914
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7915
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7916
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7917
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7918
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7919
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7920
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7921
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7922
    greyLevels := 1 bitShift:depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7923
    pixelsPerByte := 8 / depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7924
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7925
    bytesPerOutRow := (w * depth + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7926
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7927
    (outBits isNil or:[bytes isNil]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7928
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7929
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7930
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7931
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7932
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7933
    self bitsPerPixel <= 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7934
	"/ fetch scaled brightness values outside of loop into a table;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7935
	"/ use table-value in loop
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7936
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7937
	greyValues := self greyMapForRange:(greyLevels-1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7938
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7939
						   0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7940
					       ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7941
						   v truncated]].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7942
	greyPixels := ByteArray withAll:greyPixels.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7943
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7944
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7945
						   0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7946
					       ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7947
						   ((v - v truncated) * nDither) rounded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7948
					       ]].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7949
	greyErrors := ByteArray withAll:greyErrors.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7950
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7951
	0 to:(h-1) do:[:y |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7952
	    nextDst := dstIndex + bytesPerOutRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7953
	    byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7954
	    bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7955
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7956
	    self valuesAtY:y from:0 to:(w-1) do:[:x :value |
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7957
%{
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7958
		int __dW = __intVal(dW);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7959
		int __byte = __intVal(byte);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7960
		int __value = __intVal(value);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7961
		int __dT;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7962
		int __dstIdx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7963
		int __pixel, __grey;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7964
		int __bitCnt = __intVal(bitCnt);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7965
		unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7966
		unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7967
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7968
		__pixel = __greyPixels[__value];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7969
		__grey = __greyErrors[__value];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7970
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7971
		__dT = __ByteArrayInstPtr(ditherMatrix)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7972
			    ->ba_element[__intVal(x) % __dW 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7973
					 + (__intVal(y) % __intVal(dH)) * __dW];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7974
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7975
		if (__grey > __dT) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7976
		    __pixel++;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7977
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7978
		__byte = (__byte << __intVal(depth)) | __pixel;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7979
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7980
		__bitCnt = __bitCnt - __intVal(depth);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7981
		if (__bitCnt == 0) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7982
		    __dstIdx = __intVal(dstIndex);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7983
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7984
		    __dstIdx = __dstIdx + 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7985
		    dstIndex = __MKSMALLINT(__dstIdx);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7986
		    __byte = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7987
		    __bitCnt = 8;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7988
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7989
		byte = __MKSMALLINT(__byte);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7990
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7991
%}.
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7992
		0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7993
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7994
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7995
	    bitCnt ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7996
		byte := byte bitShift:bitCnt.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7997
		outBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7998
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7999
	    dstIndex := nextDst.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8000
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8001
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8002
	'Image [info]: slow ordered dither ..' infoPrintCR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8003
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8004
	0 to:(h-1) do:[:y |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8005
	    nextDst := dstIndex + bytesPerOutRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8006
	    byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8007
	    bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8008
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8009
	    "/ this is the representaion independent (but slow)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8010
	    "/ inner loop - it extracts colors from the receiver
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8011
            
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8012
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8013
		|dstClr grey dT pixel|
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8014
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8015
		"/ get the colors grey value [0 .. 1]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8016
		grey := clr brightness.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8017
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8018
		"/ remap into [0 .. greyLevels-1]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8019
		grey := grey * (greyLevels-1).
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8020
            
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8021
		"/ get threshold pixel [0 .. greyLevels-1]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8022
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8023
		pixel := grey truncated.  
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8024
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8025
		"/ compute the error [0..1]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8026
		grey := grey - pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8027
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8028
		"/ map into dither space [0 .. nDither]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8029
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8030
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8031
%{
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8032
		int __dW = __intVal(dW);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8033
		int __byte = __intVal(byte);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8034
		int __dT;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8035
		int __dstIdx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8036
		int __pixel;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8037
		int __bitCnt = __intVal(bitCnt);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8038
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8039
		__dT = __ByteArrayInstPtr(ditherMatrix)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8040
			    ->ba_element[__intVal(x) % __dW 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8041
					 + (__intVal(y) % __intVal(dH)) * __dW];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8042
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8043
		__pixel = __intVal(pixel);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8044
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8045
		if (__intVal(grey) > __dT) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8046
		    __pixel++;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8047
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8048
		__byte = (__byte << __intVal(depth)) | __pixel;
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8049
            
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8050
		__bitCnt = __bitCnt - __intVal(depth);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8051
		if (__bitCnt == 0) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8052
		    __dstIdx = __intVal(dstIndex);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8053
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8054
		    __dstIdx = __dstIdx + 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8055
		    dstIndex = __MKSMALLINT(__dstIdx);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8056
		    __byte = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8057
		    __bitCnt = 8;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8058
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8059
		byte = __MKSMALLINT(__byte);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8060
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8061
%}.
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8062
		0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8063
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8064
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8065
	    bitCnt ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8066
		byte := byte bitShift:bitCnt.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8067
		outBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8068
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8069
	    dstIndex := nextDst.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8070
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8071
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8072
    ^ outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8073
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8074
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8075
orderedDitheredMonochromeBits
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8076
    "return the bitmap for a dithered monochrome bitmap from the image;
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8077
     using a default ditherMatrix."
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8078
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8079
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8080
	orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8081
	ditherWidth:8
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8082
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8083
    "Created: 11.6.1996 / 16:48:57 / cg"
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8084
!
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8085
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8086
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8087
    "return the bitmap for a dithered monochrome bitmap from the image;
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8088
     with a constant ditherMatrix, this can be used for thresholding.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8089
     Works for any source depths / photometric, 
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8090
     but very very slow since each pixel is processed individually.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8091
     Redefined by some subclasses for more performance (D8Image)"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8092
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8093
    |f last dH nDither   
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8094
     greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8095
     dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8096
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8097
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8098
     monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8099
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8100
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8101
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8102
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8103
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8104
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8105
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8106
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8107
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8108
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8109
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8110
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8111
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8112
    (monoBits isNil or:[bytes isNil]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8113
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8114
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8115
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8116
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8117
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8118
    self bitsPerPixel <= 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8119
	"/ fetch scaled brightness values outside of loop into a table;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8120
	"/ use table-value in loop
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8121
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8122
	greyValues := self greyByteMapForRange:nDither.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8123
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8124
	0 to:(h-1) do:[:y |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8125
	    nextDst := dstIndex + bytesPerMonoRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8126
	    byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8127
	    bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8128
	    self valuesAtY:y from:0 to:(w-1) do:[:x :value |
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8129
%{
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8130
		int __dW = __intVal(dW);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8131
		int __byte = __intVal(byte);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8132
		int __dT;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8133
		int __dstIdx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8134
		int __bitCnt = __intVal(bitCnt);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8135
		int __grey;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8136
		unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8137
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8138
		__grey = __greyValues[__intVal(value)];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8139
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8140
		__dT = __ByteArrayInstPtr(ditherMatrix)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8141
			    ->ba_element[__intVal(x) % __dW 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8142
					 + (__intVal(y) % __intVal(dH)) * __dW];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8143
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8144
		__byte = __byte << 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8145
		if (__grey > __dT) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8146
		    __byte = __byte | 1;            /* white */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8147
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8148
		__bitCnt = __bitCnt - 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8149
		if (__bitCnt == 0) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8150
		    __dstIdx = __intVal(dstIndex);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8151
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8152
		    __dstIdx = __dstIdx + 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8153
		    dstIndex = __MKSMALLINT(__dstIdx);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8154
		    __byte = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8155
		    __bitCnt = 8;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8156
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8157
		byte = __MKSMALLINT(__byte);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8158
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8159
%}.
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8160
		0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8161
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8162
	    bitCnt ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8163
		byte := byte bitShift:bitCnt.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8164
		monoBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8165
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8166
	    dstIndex := nextDst.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8167
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8168
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8169
	'Image [info]: slow ordered dither ..' infoPrintCR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8170
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8171
	0 to:(h-1) do:[:y |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8172
	    nextDst := dstIndex + bytesPerMonoRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8173
	    byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8174
	    bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8175
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8176
		|dstClr grey dT|
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8177
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8178
		"/ get the colors grey value [0 .. 1]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8179
		grey := clr brightness.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8180
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8181
		"/ map into dither space [0 .. nDither]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8182
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8183
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8184
%{
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8185
		int __dW = __intVal(dW);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8186
		int __byte = __intVal(byte);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8187
		int __dT;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8188
		int __dstIdx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8189
		int __bitCnt = __intVal(bitCnt);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8190
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8191
		__dT = __ByteArrayInstPtr(ditherMatrix)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8192
			    ->ba_element[__intVal(x) % __dW 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8193
					 + (__intVal(y) % __intVal(dH)) * __dW];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8194
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8195
		__byte = __byte << 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8196
		if (__intVal(grey) > __dT) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8197
		    __byte = __byte | 1;            /* white */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8198
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8199
		__bitCnt = __bitCnt - 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8200
		if (__bitCnt == 0) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8201
		    __dstIdx = __intVal(dstIndex);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8202
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8203
		    __dstIdx = __dstIdx + 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8204
		    dstIndex = __MKSMALLINT(__dstIdx);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8205
		    __byte = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8206
		    __bitCnt = 8;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8207
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8208
		byte = __MKSMALLINT(__byte);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8209
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8210
%}.
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8211
		0
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8212
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8213
"/                dT := ditherMatrix at:(x \\ dW) + (y \\ dH * dW) + 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8214
"/     
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8215
"/                byte := byte bitShift:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8216
"/                grey < dT ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8217
"/                    byte := byte bitOr:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8218
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8219
"/                bitCnt := bitCnt - 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8220
"/                bitCnt == 0 ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8221
"/                    monoBits at:dstIndex put:byte.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8222
"/                    dstIndex := dstIndex + 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8223
"/                    byte := 0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8224
"/                    bitCnt := 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8225
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8226
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8227
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8228
	    bitCnt ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8229
		byte := byte bitShift:bitCnt.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8230
		monoBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8231
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8232
	    dstIndex := nextDst.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8233
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8234
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8235
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8236
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8237
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8238
stevensonArceDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8239
    "return the bitmap for a dithered monochrome bitmap from the image.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8240
     Works for any source depths / photometric"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8241
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  8242
    |dstIndex        "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8243
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8244
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8245
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8246
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8247
     errorArray1 errorArray2 errorArray3
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8248
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8249
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8250
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8251
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8252
     byte            "{Class: SmallInteger }" 
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  8253
     grey
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  8254
     xE              "{Class: SmallInteger }" |
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8255
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8256
    self depth > 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8257
	^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8258
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8259
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8260
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8261
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8262
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8263
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8264
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8265
    (monoBits isNil or:[bytes isNil]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8266
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8267
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8268
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8269
    errorArray := Array new:(w+6).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8270
    errorArray1 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8271
    errorArray2 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8272
    errorArray3 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8273
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8274
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8275
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8276
    "/ fetch scaled brightness values outside of loop into a table;
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8277
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8278
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8279
    greyValues := self greyMapForRange:(255 * 1024).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8280
    
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8281
    0 to:(h-1) do:[:y |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8282
	nextDst := dstIndex + bytesPerMonoRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8283
	byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8284
	bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8285
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8286
	t := errorArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8287
	errorArray := errorArray1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8288
	errorArray1 := errorArray2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8289
	errorArray2 := errorArray3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8290
	errorArray3 := t.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8291
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8292
	errorArray3 atAllPut:0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8293
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8294
	self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8295
	    |eP eD|
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8296
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8297
	    "/ get the colors grey value [0 .. 1]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8298
	    grey := greyValues at:(pixel + 1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8299
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8300
	    "/ adjust error
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8301
	    xE := x + 3 + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8302
	    grey := (grey + (errorArray at:xE)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8303
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8304
	    byte := byte bitShift:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8305
	    grey > (127 * 1024) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8306
		byte := byte bitOr:1.      "/ white
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8307
		e := grey - (255 * 1024)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8308
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8309
		e := grey                  "/ black
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8310
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8311
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8312
	    e ~= 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8313
		"/ distribute the error:
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8314
		"/                  XX    32
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8315
		"/         12    26    30    16
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8316
		"/            12    26    12
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8317
		"/          5    12    12     5
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8318
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8319
		eD := e.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8320
		e := e // 200.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8321
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8322
		eP := e * 32. eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8323
		errorArray at:xE+2 put:(errorArray at:xE+2) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8324
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8325
		eP := e * 30. eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8326
		errorArray1 at:xE+1 put:(errorArray1 at:xE+1) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8327
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8328
		eP := e * 16. eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8329
		errorArray1 at:xE+3 put:(errorArray1 at:xE+3) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8330
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8331
		eP := e * 26. eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8332
		errorArray1 at:xE-1 put:(errorArray1 at:xE-1) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8333
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8334
		eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8335
		errorArray2 at:xE put:(errorArray2 at:xE) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8336
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8337
		eP := e * 12. eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8338
		errorArray1 at:xE-3 put:(errorArray1 at:xE-3) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8339
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8340
		eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8341
		errorArray2 at:xE-2 put:(errorArray2 at:xE-2) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8342
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8343
		eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8344
		errorArray2 at:xE+2 put:(errorArray2 at:xE+2) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8345
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8346
		eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8347
		errorArray3 at:xE-1 put:(errorArray3 at:xE-1) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8348
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8349
		eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8350
		errorArray3 at:xE+1 put:(errorArray3 at:xE+1) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8351
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8352
		eP := e * 5. eD := eD - eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8353
		errorArray3 at:xE-3 put:(errorArray3 at:xE-3) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8354
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8355
		eP := eD.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8356
		errorArray3 at:xE+3 put:(errorArray3 at:xE+3) + eP.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8357
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8358
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8359
	    bitCnt := bitCnt - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8360
	    bitCnt == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8361
		monoBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8362
		dstIndex := dstIndex + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8363
		byte := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8364
		bitCnt := 8.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8365
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8366
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8367
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8368
	bitCnt ~~ 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8369
	    byte := byte bitShift:bitCnt.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8370
	    monoBits at:dstIndex put:byte.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8371
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8372
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8373
	dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8374
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8375
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8376
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8377
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8378
    "Created: 10.6.1996 / 12:38:35 / cg"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8379
    "Modified: 10.6.1996 / 12:52:20 / cg"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8380
! !
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8381
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8382
!Image methodsFor:'drawing'!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8383
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8384
drawRectangle: aRectangle withColor:aColor
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8385
    "draw a rectangle with some pixel value.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8386
     By using #atImageAndMask:put: it also works on images with mono masks."
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8387
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8388
    |xI "{ Class: SmallInteger }"
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8389
     yI "{ Class: SmallInteger }"
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8390
     wI "{ Class: SmallInteger }" 
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8391
     hI "{ Class: SmallInteger }"|
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8392
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8393
    xI := aRectangle left.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8394
    yI := aRectangle top.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8395
    wI := aRectangle width.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8396
    hI := aRectangle height.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8397
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8398
    xI to:xI+wI-1 do:[:xRun|
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8399
	self atImageAndMask: xRun@yI put:aColor.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8400
	self atImageAndMask: xRun@(yI+hI-1) put:aColor
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8401
    ].
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8402
    yI+1 to:yI+hI-2 do:[:yRun|
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8403
	self atImageAndMask: xI@yRun put:aColor.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8404
	self atImageAndMask: xI+wI-1@yRun put:aColor
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8405
    ].
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8406
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8407
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8408
!
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8409
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8410
fillRectangle: aRectangle withColor:aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8411
    "draw a rectangle with some pixel value.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8412
    By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8413
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8414
    |xI "{ Class: SmallInteger }"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8415
     yI "{ Class: SmallInteger }"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8416
     wI "{ Class: SmallInteger }" 
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8417
     hI "{ Class: SmallInteger }"|
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8418
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8419
    xI := aRectangle left.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8420
    yI := aRectangle top.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8421
    wI := aRectangle width.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8422
    hI := aRectangle height.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8423
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8424
    yI to:yI+hI-1 do:[:yRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8425
	xI to:xI+wI-1 do:[:xRun |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8426
	    self atImageAndMask:xRun@yRun put:aColor
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8427
	]
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8428
    ]
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8429
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8430
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8431
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8432
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8433
fillRectangleX:x y:y width:w height:h with:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8434
    "fill a rectangular area with a aColor"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8435
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8436
    self fillRectangleX:x y:y width:w height:h withValue:(self valueFromColor:aColor)
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8437
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8438
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8439
fillRectangleX:x y:y width:w height:h withValue:aPixelValue
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8440
    "fill a rectangular area with some pixel value.
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8441
     May be redefined in concrete subclasses for more performance, if req'd."
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8442
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8443
    |xI "{ Class: SmallInteger }"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8444
     yI "{ Class: SmallInteger }"
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8445
     wI "{ Class: SmallInteger }" 
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8446
     hI "{ Class: SmallInteger }"|
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8447
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8448
    xI := x.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8449
    yI := y.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8450
    wI := w.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8451
    hI := h.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8452
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8453
    yI to:yI+hI-1 do:[:yRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8454
	xI to:xI+wI-1 do:[:xRun |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8455
	    self pixelAtX:xRun y:yRun put:aPixelValue
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8456
	]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8457
    ]
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8458
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8459
    "Created: 22.4.1997 / 14:02:14 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8460
    "Modified: 24.4.1997 / 17:24:58 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8461
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8462
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8463
floodFillAt: aPoint withColor: aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8464
    "fill a area with aColor like a flood up to surrounded pixels having different colors.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8465
     By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8466
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8467
    |surroundingPixelsOfDo detectedPixel detectedPixelCoordinates 
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8468
     allDetectedPixelCoordinates morePixels seemsToBeAll
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8469
     sizeBefore toDo idx pixel
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8470
     w h|
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8471
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8472
    w := self width.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8473
    h := self height.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8474
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8475
    surroundingPixelsOfDo := 
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8476
        [:pX :pY :fn|
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8477
            |nX nY|
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8478
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8479
            nX := pX + 1.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8480
            nY := pY + 1.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8481
            (nY < h) ifTrue: [fn value:pX value:nY].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8482
            (pY > 0) ifTrue: [fn value:pX value:(pY - 1)].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8483
            (nX < w) ifTrue: [fn value:nX value:pY].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8484
            (pX > 0) ifTrue: [fn value:(pX - 1) value:pY].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8485
        ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8486
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8487
    (mask notNil and: [(mask pixelAt:aPoint) == 0]) ifTrue:[
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8488
        ^ (mask floodFillAt: aPoint withColor: Color white) do: [:p | self atImageAndMask: p put: aColor].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8489
    ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8490
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8491
    detectedPixel := self pixelAt: aPoint.
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8492
    allDetectedPixelCoordinates := BooleanArray new:(w * h). "/ Set new.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8493
    toDo := OrderedCollection new:1000.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8494
    allDetectedPixelCoordinates at:(1 + aPoint x + (aPoint y * w)) put:true. "/ allDetectedPixelCoordinatesadd:aPoint.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8495
    toDo add:aPoint.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8496
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8497
    [toDo notEmpty] whileTrue:[
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8498
        |p|
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8499
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8500
        p := toDo removeFirst.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8501
        surroundingPixelsOfDo value:p x value:p y  value:[:spX :spY |
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8502
            |sp|
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8503
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8504
            ((self pixelAtX:spX y:spY) == detectedPixel and: [mask isNil or:[(mask pixelAtX:spX y:spY) == 1]])
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8505
            ifTrue: [
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8506
                (allDetectedPixelCoordinates at:(1 + spX + (spY * w)))
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8507
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8508
                "/ sp := spX @ spY.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8509
                "/ (allDetectedPixelCoordinates includes:sp) 
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8510
                ifFalse:[
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8511
                    allDetectedPixelCoordinates at:(1 + spX + (spY * w)) put:true.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8512
                    toDo add:spX @ spY.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8513
                    "/ allDetectedPixelCoordinates add:sp.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8514
                    "/ toDo add:sp.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8515
                ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8516
            ]
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8517
        ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8518
    ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8519
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8520
"/    seemsToBeAll := false.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8521
"/    [seemsToBeAll] whileFalse:[
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8522
"/
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8523
"/        sizeBefore := allDetectedPixelCoordinates size.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8524
"/        morePixels := OrderedCollection new.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8525
"/        detectedPixelCoordinates do:[:p|
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8526
"/            surroundingPixelsOfDo value:p value:[:sp| 
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8527
"/                (detectedPixel == (self pixelAt: sp) and: [mask isNil or: [(mask colorAt: sp) = Color white]])
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8528
"/                ifTrue: [morePixels add: sp]
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8529
"/            ]
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8530
"/        ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8531
"/        detectedPixelCoordinates := (morePixels asSet reject: [:p| allDetectedPixelCoordinates includes: p]).
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8532
"/        allDetectedPixelCoordinates addAll: detectedPixelCoordinates.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8533
"/        seemsToBeAll := sizeBefore = allDetectedPixelCoordinates size.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8534
"/    ]. 
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8535
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8536
    idx := 1.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8537
    pixel := self valueFromColor:aColor.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8538
    0 to:h-1 do:[:y |
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8539
        0 to:w-1 do:[:x |
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8540
            (allDetectedPixelCoordinates at:idx) ifTrue:[ 
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8541
                self pixelAtX:x y:y put:pixel.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8542
            ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8543
            idx := idx + 1.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8544
        ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8545
    ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8546
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8547
    "/ allDetectedPixelCoordinates do: [:p| self atImageAndMask: p put: aColor].
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8548
    ^allDetectedPixelCoordinates
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8549
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8550
    "Modified: / 29.7.1998 / 03:09:16 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8551
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8552
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8553
rectangle: aRectangle withColor:aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8554
    "draw a rectangle with some pixel value.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8555
    By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8556
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8557
    self obsoleteMethodWarning.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8558
    self drawRectangle: aRectangle withColor:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8559
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8560
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8561
! !
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8562
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8563
!Image methodsFor:'enumerating'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8564
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8565
atY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8566
    "perform aBlock for each pixel from x1 to x2 in row y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8567
     The block is passed the color at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8568
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8569
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8570
     when going from pixel to pixel (i.e. the byte-index and mask computations
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8571
     and also the color allocation)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8572
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  8573
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  8574
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8575
    self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8576
    self colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8577
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8578
    "Modified: 7.6.1996 / 19:13:30 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8579
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8580
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8581
colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8582
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8583
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8584
     The code here provides a generic and slow implementation, and
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8585
     should be redefined in concrete subclasses, to avoid some processing
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8586
     when going from pixel to pixel (i.e. the byte-index and mask computations
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8587
     and also the color allocation)."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8588
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8589
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8590
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8591
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8592
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8593
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8594
    xStart to:xEnd do:[:xRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8595
	aBlock value:xRun value:(self colorAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8596
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8597
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  8598
    "Created: / 7.6.1996 / 19:12:51 / cg"
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  8599
    "Modified: / 30.9.1998 / 22:14:16 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8600
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8601
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8602
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8603
    "perform aBlock for each color in a rectangular area of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8604
     Notice, that x and y coordinates start at 0@0 for the upper left corner.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8605
     The block is passed the x and y coordinates and pixelValue at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8606
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8607
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8608
     when going from pixel to pixel (i.e. the byte-index and mask computations,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8609
     and especially, the color allocations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8610
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  8611
    |yS "{Class: SmallInteger }"
942
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  8612
     yE "{Class: SmallInteger }"
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  8613
     yR|
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  8614
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  8615
    yS := yStart.
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  8616
    yE := yEnd.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  8617
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  8618
    yS to:yE do:[:yRun |    
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8619
	yR := yRun.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8620
	self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8621
	    aBlock value:xRun value:yR value:color 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8622
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8623
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8624
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  8625
    "Modified: 11.7.1996 / 19:50:47 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8626
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8627
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8628
valueAtY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8629
    "perform aBlock for each pixelValue from x1 to x2 in row y.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8630
     Obsolete - remains for backward compatibility."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8631
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  8632
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  8633
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8634
    self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8635
    self valuesAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8636
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8637
    "Modified: 7.6.1996 / 19:11:06 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8638
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8639
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8640
valuesAtY:y from:x1 to:x2 do:aBlock
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8641
    "WARNING: for now, this enumerates pixel values 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8642
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8643
     In the future, this will enumerate colors 
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8644
     Use #pixelAtT:from:to:do: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8645
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8646
     perform aBlock for each pixelValue from x1 to x2 in row y.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8647
     Notice, that x and y coordinates start at 0@0 for the upper left corner.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8648
     The block is passed the x coordinate and the pixelValue at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8649
     (see also Image>>atY:from:to:do:).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8650
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8651
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8652
     when going from pixel to pixel (i.e. the byte-index and mask computations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8653
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8654
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8655
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8656
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8657
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8658
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8659
    xStart to:xEnd do:[:xRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8660
	aBlock value:xRun value:(self pixelAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8661
    ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8662
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8663
    "Created: 7.6.1996 / 19:09:51 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8664
    "Modified: 24.4.1997 / 16:55:38 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8665
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8666
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8667
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8668
    "perform aBlock for each pixelValue in a rectangular area of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8669
     Notice, that x and y coordinates start at 0@0 for the upper left corner.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8670
     The block is passed the x and y coordinates and pixelValue at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8671
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8672
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8673
     when going from pixel to pixel (i.e. the byte-index and mask computations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8674
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8675
    |xS "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8676
     xE "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8677
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8678
    xS := xStart.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8679
    xE := xEnd.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8680
    yStart to:yEnd do:[:yRun |    
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8681
	self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8682
	    aBlock value:xRun value:yRun value:pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8683
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8684
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8685
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8686
    "Modified: 7.6.1996 / 19:09:29 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8687
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  8688
3613
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8689
!Image methodsFor:'finalization'!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8690
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8691
finalizationLobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8692
    "answer the registry used for finalization.
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8693
     Images have their own Registry"
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8694
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8695
    ^ Lobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8696
!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8697
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8698
finalize
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8699
    "some Image has been collected - nothing to do"
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8700
! !
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8701
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8702
!Image methodsFor:'image manipulations'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  8703
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8704
applyPixelValuesTo:pixelFunctionBlock into:newImage
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8705
    "helper for withPixelFunctionAppliedToValues:
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8706
     enumerate pixelValues and evaluate the block for each.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8707
     To be redefined by subclasses for better performance."
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8708
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8709
    |w  "{Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8710
     h  "{Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8711
     newPixel newPixelRow pixelRow|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8712
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8713
    w := width.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8714
    h := height - 1.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8715
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8716
    newPixelRow := Array new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8717
    pixelRow := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8718
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8719
    0 to:h do:[:y |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8720
	self rowAt:y into:pixelRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8721
	1 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8722
	    newPixel := pixelFunctionBlock
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8723
			    value:self
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8724
			    value:(pixelRow at:col)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8725
			    value:(col-1)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8726
			    value:y.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8727
	    newPixelRow at:col put:newPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8728
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8729
	newImage rowAt:y putAll:newPixelRow
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8730
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8731
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8732
    "Modified: 24.4.1997 / 16:18:31 / cg"
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8733
!
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8734
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8735
applyPixelValuesTo:pixelFunctionBlock into:newImage in:aRectangle
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8736
    "helper for withPixelFunctionAppliedToValues:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8737
     enumerate pixelValues and evaluate the block for each.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8738
     To be redefined by subclasses for better performance."
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8739
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8740
    |w  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8741
     h  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8742
     x0  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8743
     y0  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8744
     y  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8745
     newPixel newPixelRow pixelRow|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8746
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8747
    x0 := aRectangle left.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8748
    y0 := aRectangle top.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8749
    w := aRectangle width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8750
    h := aRectangle height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8751
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8752
    newPixelRow := Array new:w.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8753
    pixelRow := self pixelArraySpecies new:width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8754
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8755
    y := y0.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8756
    h timesRepeat:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8757
	self rowAt:y into:pixelRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8758
	1 to:w do:[:runCol |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8759
	    newPixel := pixelFunctionBlock
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8760
			    value:self
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8761
			    value:(pixelRow at:runCol+x0)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8762
			    value:(runCol+x0-1)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8763
			    value:y.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8764
	    newPixelRow at:runCol put:newPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8765
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8766
	pixelRow replaceFrom:x0+1 to:x0+1+w-1 with:newPixelRow startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8767
	newImage rowAt:y putAll:newPixelRow.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8768
	y := y + 1.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8769
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8770
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8771
    "Modified: 24.4.1997 / 16:18:31 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8772
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8773
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8774
blendWith:aColor
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8775
    "return a new image which is blended with some color.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8776
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8777
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8778
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8779
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8780
     ^ self 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8781
	copyWithColorMapProcessing:[:clr | clr blendWith:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8782
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8783
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8784
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8785
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') blendWith:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8786
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') blendWith:Color white) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8787
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') blendWith:Color black) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8788
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8789
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8790
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8791
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8792
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8793
colorMapProcessing:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8794
    "a helper for all kinds of colormap manipulations.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8795
     The argument, aBlock is called for every colormap entry, 
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8796
     and the returned value will replace the original entry in the map.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8797
     This will fail for non-palette images.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8798
     See examples in Image>>copyWithColorMapProcessing:"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8799
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8800
    |nColors "{ Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8801
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8802
    colorMap isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8803
	^ self error:'image has no colormap'
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8804
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8805
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8806
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8807
    1 to:nColors do:[:index |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8808
	|clr|
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8809
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8810
	clr := colorMap at:index.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8811
	clr notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8812
	    colorMap at:index put:(aBlock value:clr)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8813
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8814
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8815
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8816
    "Modified: 23.4.1996 / 11:13:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8817
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8818
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8819
copyWithColorMapProcessing:aBlock
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8820
    "a helper to create & return new images based on the receiver with
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8821
     some colorMap processing. The receiver is copied, and the copied images
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8822
     colormap is modified by replacing entries with the result of the processing block,
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8823
     which is called with the original color values. The block is supposed to return
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8824
     a color.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8825
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale)"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8826
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8827
    |newImage|
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8828
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8829
    newImage := self copy.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8830
    newImage colorMap isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8831
	self error:'no colormap in image'.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8832
	^ nil
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8833
    ].
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8834
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8835
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8836
     the code below manipulates the colormap.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8837
     For non-palette images, special code is required
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8838
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8839
    newImage colorMapProcessing:aBlock.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8840
    ^ newImage
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8841
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8842
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8843
     leave red component only:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8844
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  8845
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8846
	copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0] 
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8847
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8848
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8849
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8850
     make it reddish:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8851
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8852
     (Image fromFile:'bitmaps/gifImages/claus.gif') 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8853
	copyWithColorMapProcessing:[:clr | Color red:((clr red * 2) min:100) green:clr green blue:clr blue] 
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8854
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8855
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8856
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8857
     invert:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8858
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8859
     (Image fromFile:'bitmaps/gifImages/claus.gif') 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8860
	copyWithColorMapProcessing:[:clr | Color red:(100 - clr red) green:(100 - clr green) blue:(100 - clr green)] 
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8861
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8862
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8863
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8864
     lighter:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8865
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8866
     (Image fromFile:'bitmaps/gifImages/claus.gif') 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8867
	copyWithColorMapProcessing:[:clr | |r g b|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8868
						r := clr red.  g := clr green.  b := clr blue.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8869
						Color red:(r + (100-r//2)) 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8870
						      green:(g + (100-g//2)) 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8871
						      blue:(b + (100-b//2))]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8872
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8873
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8874
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8875
     darker:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8876
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8877
     (Image fromFile:'bitmaps/gifImages/claus.gif') 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8878
	copyWithColorMapProcessing:[:clr | Color red:(clr red//2) green:(clr green // 2) blue:(clr blue // 2)] 
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8879
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8880
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8881
    "Modified: 24.4.1997 / 18:28:05 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8882
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8883
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8884
createMask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8885
    |maskArray bytesPerMaskRow|
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8886
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8887
    bytesPerMaskRow := (width+7) // 8.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8888
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8889
    maskArray := ByteArray new:(bytesPerMaskRow * height) withAll:2r11111111.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8890
    mask := ImageMask width:width height:height fromArray:maskArray.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8891
    ^ mask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8892
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8893
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8894
darkened
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8895
    "return a new image which is slightly darker than the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8896
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8897
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale).
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8898
     CAVEAT: Need an argument, which specifies by how much it should be darker."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8899
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8900
     ^ self 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8901
	copyWithColorMapProcessing:[:clr | clr darkened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8902
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8903
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8904
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8905
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8906
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8907
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8908
    "Modified: 24.4.1997 / 18:28:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8909
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8910
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8911
easyRotateBitsInto:destinationImage angle:degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8912
    "helper for rotation - does the actual pixel shuffling.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8913
     by degrees clockwise. Here, only 90, 180 and 270 degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8914
     are implemented. Hard angles are done in #hardRotate:.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8915
     The code here is depth-independent (but not too fast);
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8916
     can be redefined in subclasses for more performance"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8917
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8918
    |w  "{Class: SmallInteger }"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8919
     h  "{Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8920
     c2 r2 pixelArray|
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8921
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8922
    w := width - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8923
    h := height - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8924
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8925
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8926
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8927
    degrees = 90 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8928
	0 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8929
	    self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8930
	    c2 := h-row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8931
	    0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8932
		destinationImage pixelAtX:c2 y:col put:(pixelArray at:(col+1)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8933
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8934
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8935
	^ self.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8936
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8937
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8938
    degrees = 180 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8939
	0 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8940
	    self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8941
	    r2 := h - row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8942
	    0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8943
		destinationImage pixelAtX:(w-col) y:r2 put:(pixelArray at:(col+1)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8944
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8945
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8946
	^ self
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8947
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8948
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8949
    "/ degrees = 270
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8950
    0 to:h do:[:row |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8951
	self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8952
	0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8953
	    destinationImage pixelAtX:row y:(w-col) put:(pixelArray at:(col+1)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8954
	]
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8955
    ]
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8956
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8957
    "Created: 23.4.1997 / 14:36:45 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8958
    "Modified: 24.4.1997 / 17:26:26 / cg"
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  8959
!
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  8960
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8961
flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8962
    "destructively inplace horizontal flip"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8963
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8964
    |h  "{Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8965
     pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8966
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8967
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8968
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8969
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8970
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8971
    0 to:h do:[:row |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8972
	self rowAt:row into:pixelArray.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8973
	pixelArray reverse.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8974
	self rowAt:row putAll:pixelArray.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8975
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8976
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  8977
    mask notNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  8978
	mask flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8979
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8980
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8981
    "/ flush device info
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8982
    self restored
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  8983
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8984
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  8985
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipHorizontal inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8986
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8987
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8988
    "Modified: 24.4.1997 / 18:29:13 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8989
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8990
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8991
flipVertical
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8992
    "inplace vertical flip"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8993
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8994
    |h           "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8995
     bytesPerRow "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8996
     buffer 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8997
     indexLow    "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8998
     indexHi     "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8999
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9000
    bytesPerRow := self bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9001
    buffer := ByteArray new:bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9002
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9003
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9004
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9005
    indexLow := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9006
    indexHi := bytesPerRow * h + 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9007
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9008
    0 to:(h // 2) do:[:row |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9009
	buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9010
	bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9011
	bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9012
	indexLow := indexLow + bytesPerRow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9013
	indexHi := indexHi - bytesPerRow.
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9014
    ].
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9015
    mask notNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9016
	mask flipVertical
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9017
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9018
    "flush device info"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9019
    self restored
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9020
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9021
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9022
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipVertical inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9023
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9024
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9025
    "Modified: 24.4.1997 / 18:29:36 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9026
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9027
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9028
hardAntiAliasedMagnifiedBy:scalePoint
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9029
    "return a new image magnified and antiAliased by scalePoint, aPoint.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9030
     This converts into a depth24Image before doing the antiAlias-magnify.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9031
     It is definitely slower than the non antiAliasing/integral magnification methods."
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9032
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9033
    ^ (Depth24Image fromImage:self)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9034
	hardAntiAliasedMagnifiedBy:scalePoint
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9035
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9036
    "Modified: 2.6.1997 / 13:19:57 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9037
    "Created: 2.6.1997 / 15:53:34 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9038
!
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9039
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9040
hardMagnifiedBy:scalePoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9041
    "return a new image magnified by scalePoint, aPoint.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9042
     This is the general magnification method, handling non-integral values.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9043
     It is slower than the integral magnification method."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9044
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9045
    |mX        
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9046
     mY        
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9047
     newWidth  "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9048
     newHeight "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9049
     w         "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9050
     h         "{ Class: SmallInteger }"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9051
     newImage newBits bitsPerPixel newBytesPerRow newMask
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  9052
     value 
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9053
     srcRow pixelArray|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9054
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9055
    mX := scalePoint x.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9056
    mY := scalePoint y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9057
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9058
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9059
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9060
    newWidth := (width * mX) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9061
    newHeight := (height * mY) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9062
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9063
    bitsPerPixel := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9064
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9065
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9066
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9067
    mask notNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9068
	newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9069
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9070
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9071
    newImage := self species new.
888
69447418e2b1 better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
  9072
    newImage 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9073
	width:newWidth 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9074
	height:newHeight 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9075
	photometric:photometric 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9076
	samplesPerPixel:samplesPerPixel 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9077
	bitsPerSample:bitsPerSample 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9078
	colorMap:colorMap copy
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9079
	bits:newBits
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9080
	mask:newMask.
905
228d503775d9 everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  9081
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9082
    "walk over destination image fetching pixels from source image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9083
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9084
    w := newWidth - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9085
    h := newHeight - 1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9086
    pixelArray := newImage pixelArraySpecies new:newWidth.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9087
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9088
    0 to:h do:[:row |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9089
	srcRow := (row // mY).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9090
	0 to:w do:[:col |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9091
	    value := self pixelAtX:(col // mX) y:srcRow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9092
	    pixelArray at:(col+1) put:value.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9093
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9094
	newImage rowAt:row putAll:pixelArray.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9095
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9096
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9097
    ^ newImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9098
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9099
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9100
     |i|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9101
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9102
     Time millisecondsToRun:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9103
	 i := i hardMagnifiedBy:0.5@0.5
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9104
     ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9105
     i
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9106
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9107
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9108
    "Modified: 24.4.1997 / 18:30:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9109
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9110
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9111
hardRotated:degrees
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9112
    "return a new image from the old one, by rotating the image
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9113
     degrees clockwise. 
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9114
     Warning: the returned image will be larger than the original image."
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9115
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9116
    |p r a aN p1 p2 p3 p4 maxX minX maxY minY
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9117
     newImage 
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9118
     newWidth  "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9119
     newHeight "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9120
     newBytesPerRow newBits
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9121
     blackPixel halfW halfH radians m t bad
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9122
     bytesPerRow myDepth maskBits
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9123
     pX pY srcX srcY pix nX nY 
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9124
     sinRot cosRot sinPY cosPY|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9125
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9126
    "/ placing the image at the origin,
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9127
    "/ compute the diagonal and angle.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9128
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9129
    p := (width - 1 / 2) @ (height - 1 / 2).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9130
    r := p r.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9131
    a := p angle.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9132
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9133
    "/ add the rotation 
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9134
    "/ (sight - subtract, we defined things clockwise ... 
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9135
    "/  ... in contrast to point which thinks counter-clockwise)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9136
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9137
    aN := a - degrees.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9138
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9139
    "/ compute new corner points
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9140
    p1 := Point r:r angle:aN.         "/ rotated topRight
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9141
    p2 := Point r:r angle:aN-a-a.     "/ rotated bottomRight
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9142
    p3 := p1 * -1.                    "/ rotated bottomLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9143
    p4 := p2 * -1.                    "/ rotated topLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9144
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9145
    "/ compute the boundary of the new image
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9146
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9147
    maxX := minX := p1 x.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9148
    (t := p2 x) > maxX ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9149
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9150
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9151
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9152
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9153
    (t := p3 x) > maxX ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9154
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9155
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9156
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9157
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9158
    (t := p4 x) > maxX ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9159
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9160
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9161
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9162
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9163
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9164
    maxY := minY := p1 y.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9165
    (t := p2 y) > maxY ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9166
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9167
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9168
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9169
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9170
    (t := p3 y) > maxY ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9171
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9172
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9173
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9174
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9175
    (t := p4 y) > maxY ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9176
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9177
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9178
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9179
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9180
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9181
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9182
    newWidth := (maxX - minX) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9183
    newHeight := (maxY - minY) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9184
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9185
    newImage := self species new.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9186
    newImage width:newWidth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9187
    newImage height:newHeight.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9188
    newBytesPerRow := newImage bytesPerRow.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9189
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9190
    newImage bits:newBits.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9191
    newImage photometric:photometric.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9192
    newImage samplesPerPixel:samplesPerPixel.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9193
    newImage bitsPerSample:bitsPerSample.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9194
    newImage colorMap:colorMap copy.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9195
    newImage maskedPixelsAre0:maskedPixelsAre0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9196
    mask notNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9197
	newImage mask:(mask rotated:degrees)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9198
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9199
	self isMask ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9200
	    self depth ~~ 1 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9201
		m := ImageMask width:width height:height.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9202
		m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9203
		maskBits atAllPut:16rFF.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9204
		newImage mask:(m rotated:degrees)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9205
	    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9206
	]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9207
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9208
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9209
    maskedPixelsAre0 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9210
	blackPixel := 0.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9211
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9212
	blackPixel := self valueFromColor:Color black.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9213
	blackPixel isNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9214
	    blackPixel := self valueFromColor:Color white.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9215
	    blackPixel isNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9216
		blackPixel := 0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9217
	    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9218
	]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9219
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9220
    self isMask ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9221
	blackPixel := 0.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9222
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9223
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9224
    myDepth := self depth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9225
    newBits atAllPut:0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9226
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9227
    "/ now, walk over destination pixels,
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9228
    "/ fetching from source. 
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9229
    "/ (if we walked over the source, we could get holes
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9230
    "/  in the destination image ...)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9231
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9232
    halfW := (width - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9233
    halfH := (height - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9234
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9235
    radians := degrees degreesToRadians.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9236
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9237
    bytesPerRow := self bytesPerRow.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9238
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9239
%{
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9240
    int __newHeight = __intVal(newHeight);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9241
    int __newWidth = __intVal(newWidth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9242
    int __height = __intVal(__INST(height));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9243
    int __width = __intVal(__INST(width));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9244
    double __minX, __minY, __radians;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9245
    double __halfW, __halfH;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9246
    int __dstX, __dstY;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9247
    int __depth = __intVal(myDepth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9248
    unsigned char *__srcBytes, *__dstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9249
    unsigned char *__dstPtr, *__dstRowPtr, *__dstEndPtr;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9250
    int __nSrcBytes, __nDstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9251
    int __srcBytesPerRow = __intVal(bytesPerRow);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9252
    int __dstBytesPerRow = __intVal(newBytesPerRow);
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9253
    int __dstMask, __blackPixel;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9254
    double __sin, __cos;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9255
    double sin(), cos();
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9256
#   define Float_PI 3.14159
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9257
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9258
    bad = true;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9259
    if (1
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9260
     && __isFloat(minX) 
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9261
     && __isFloat(minY)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9262
     && __isFloat(radians)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9263
     && __isFloat(halfW)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9264
     && __isFloat(halfH)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9265
     && __isByteArray(newBits)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9266
     && __isByteArray(__INST(bytes))) {
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9267
	__srcBytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9268
	__dstBytes = __ByteArrayInstPtr(newBits)->ba_element;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9269
	__nSrcBytes = __byteArraySize(__INST(bytes));
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9270
	__nDstBytes = __byteArraySize(newBits);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9271
	__blackPixel = __intVal(blackPixel);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9272
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9273
	__radians = __floatVal(radians);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9274
	__radians = -__radians; /* sigh: clock-wise */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9275
	__sin = sin(__radians);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9276
	__cos = cos(__radians);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9277
	__minX = __floatVal(minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9278
	__minY = __floatVal(minY);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9279
	__halfW = __floatVal(halfW);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9280
	__halfH = __floatVal(halfH);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9281
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9282
	__dstRowPtr = __dstBytes;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9283
	__dstEndPtr = __dstBytes + __nDstBytes;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9284
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9285
#       define EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9286
#       define FAST_ADVANCE 5
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9287
#       define FAST_ADVANCE2
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9288
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9289
	switch (__depth) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9290
	    case 8:
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9291
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9292
		    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9293
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9294
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9295
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9296
		    __pY = (double)(__dstY + __minY);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9297
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9298
		    __sinPY = __sin * __pY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9299
		    __cosPY = __cos * __pY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9300
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9301
		    __dstPtr = __dstRowPtr;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9302
		    __dstRowPtr += __dstBytesPerRow;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9303
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9304
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9305
			double __pX, __nX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9306
			unsigned __pix;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9307
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9308
			/* translate X in destination (center to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9309
			__pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9310
			/* rotate X */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9311
			__nX = (__cos * __pX) - __sinPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9312
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9313
			/* translate X in source (origin to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9314
			__nX = __nX + __halfW + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9315
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9316
			/* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9317
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9318
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9319
			    if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9320
				break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9321
			    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9322
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9323
#ifdef FAST_ADVANCE
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9324
			    if (__blackPixel == 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9325
				do {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9326
				    /* try advance by FAST_ADVANCE pixels ... */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9327
				    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9328
				    if (__dstX >= __newWidth) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9329
					break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9330
				    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9331
				    __pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9332
				    __nX = (__cos * __pX) - __sinPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9333
				    __nX = __nX + __halfW + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9334
				} while (__nX < 0);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9335
				__dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9336
			    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9337
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9338
			    __pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9339
			} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9340
			    int __srcX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9341
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9342
			    __srcX = (int)__nX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9343
			    /* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9344
			    if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9345
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9346
				if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9347
				    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9348
				}
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9349
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9350
#ifdef FAST_ADVANCE2
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9351
				if (__blackPixel == 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9352
				    do {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9353
					/* try advance by FAST_ADVANCE pixels ... */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9354
					__dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9355
					if (__dstX >= __newWidth) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9356
					    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9357
					}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9358
					__pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9359
					__nX = (__cos * __pX) - __sinPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9360
					__nX = __nX + __halfW + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9361
					__srcX = (int)__nX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9362
				    } while (__srcX >= __width);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9363
				    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9364
				}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9365
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9366
				__pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9367
			    } else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9368
				double __nY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9369
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9370
				/* rotate Y */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9371
				__nY = (__sin * __pX) + __cosPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9372
				/* translate Y in source (origin to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9373
				__nY = __nY + __halfH + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9374
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9375
				/* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9376
				if (__nY < 0) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9377
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9378
				    if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9379
					break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9380
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9381
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9382
#ifdef FAST_ADVANCE2
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9383
				    if (__blackPixel == 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9384
					do {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9385
					    /* try advance by FAST_ADVANCE pixels ... */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9386
					    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9387
					    if (__dstX >= __newWidth) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9388
						break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9389
					    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9390
					    __pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9391
					    __nY = (__sin * __pX) + __cosPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9392
					    __nY = __nY + __halfH + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9393
					} while (__nY < 0);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9394
					__dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9395
				    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9396
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9397
				    __pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9398
				} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9399
				    int __srcY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9400
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9401
				    __srcY = (int)__nY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9402
				    /* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9403
				    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9404
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9405
					if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9406
					    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9407
					}
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9408
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9409
#ifdef FAST_ADVANCE
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9410
					if (__blackPixel == 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9411
					    do {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9412
						/* try advance by FAST_ADVANCE pixels ... */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9413
						__dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9414
						if (__dstX >= __newWidth) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9415
						    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9416
						}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9417
						__pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9418
						__nY = (__sin * __pX) + __cosPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9419
						__nY = __nY + __halfH + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9420
						__srcY = (int)__nY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9421
					    } while (__srcY >= __height);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9422
					    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9423
					}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9424
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9425
					__pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9426
				    } else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9427
					/* fetch source pixel */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9428
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9429
					int idx;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9430
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9431
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9432
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9433
					idx = __srcY * __srcBytesPerRow + __srcX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9434
					if ((unsigned)idx < __nSrcBytes) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9435
					    __pix = __srcBytes[idx];
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9436
					} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9437
					    __pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9438
					}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9439
				    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9440
				}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9441
			    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9442
			}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9443
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9444
			if (__pix != 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9445
			    *__dstPtr = __pix;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9446
			}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9447
			__dstPtr++;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9448
		    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9449
		}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9450
		break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9451
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9452
	    case 1:
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9453
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9454
		    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9455
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9456
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9457
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9458
		    __pY = (double)(__dstY + __minY);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9459
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9460
		    __sinPY = __sin * __pY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9461
		    __cosPY = __cos * __pY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9462
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9463
		    __dstPtr = __dstRowPtr;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9464
		    __dstMask = 0x80;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9465
		    __dstRowPtr += __dstBytesPerRow;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9466
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9467
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9468
			double __pX, __nX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9469
			int __pix;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9470
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9471
			/* translate X in destination (center to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9472
			__pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9473
			/* rotate X */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9474
			__nX = (__cos * __pX) - __sinPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9475
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9476
			/* translate X in source (origin to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9477
			__nX = __nX + __halfW + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9478
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9479
			/* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9480
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9481
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9482
			    if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9483
				break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9484
			    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9485
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9486
#ifdef FAST_ADVANCE
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9487
			    if (__blackPixel == 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9488
				do {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9489
				    /* try advance by 8 pixels ... */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9490
				    __dstX += 8; __dstPtr ++;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9491
				    if (__dstX >= __newWidth) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9492
					break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9493
				    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9494
				    __pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9495
				    __nX = (__cos * __pX) - __sinPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9496
				    __nX = __nX + __halfW + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9497
				} while (__nX < 0);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9498
				__dstX -= 8; __dstPtr--;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9499
			    }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9500
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9501
			    __pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9502
			} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9503
			    int __srcX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9504
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9505
			    __srcX = (int)__nX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9506
			    /* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9507
			    if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9508
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9509
				if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9510
				    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9511
				}
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9512
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9513
#ifdef FAST_ADVANCE2
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9514
				if (__blackPixel == 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9515
				    do {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9516
					/* try advance by 8 pixels ... */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9517
					__dstX += 8; __dstPtr++;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9518
					if (__dstX >= __newWidth) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9519
					    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9520
					}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9521
					__pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9522
					__nX = (__cos * __pX) - __sinPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9523
					__nX = __nX + __halfW + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9524
					__srcX = (int)__nX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9525
				    } while (__srcX >= __width);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9526
				    __dstX -= 8; __dstPtr--;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9527
				}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9528
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9529
				__pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9530
			    } else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9531
				double __nY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9532
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9533
				/* rotate Y */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9534
				__nY = (__sin * __pX) + __cosPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9535
				/* translate Y in source (origin to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9536
				__nY = __nY + __halfH + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9537
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9538
				/* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9539
				if (__nY < 0) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9540
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9541
				    if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9542
					break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9543
				    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9544
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9545
#ifdef FAST_ADVANCE2
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9546
				    if (__blackPixel == 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9547
					do {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9548
					    /* try advance by 8 pixels ... */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9549
					    __dstX += 8; __dstPtr++;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9550
					    if (__dstX >= __newWidth) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9551
						break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9552
					    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9553
					    __pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9554
					    __nY = (__sin * __pX) + __cosPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9555
					    __nY = __nY + __halfH + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9556
					} while (__nY < 0);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9557
					__dstX -= 8; __dstPtr--;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9558
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9559
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9560
				    __pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9561
				} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9562
				    int __srcY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9564
				    __srcY = (int)__nY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9565
				    /* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9566
				    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9567
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9568
					if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9569
					    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9570
					}
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9571
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9572
#ifdef FAST_ADVANCE
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9573
					if (__blackPixel == 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9574
					    do {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9575
						/* try advance by 8 pixels ... */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9576
						__dstX += 8; __dstPtr++;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9577
						if (__dstX >= __newWidth) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9578
						    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9579
						}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9580
						__pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9581
						__nY = (__sin * __pX) + __cosPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9582
						__nY = __nY + __halfH + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9583
						__srcY = (int)__nY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9584
					    } while (__srcY >= __height);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9585
					    __dstX -= 8; __dstPtr--;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9586
					}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9587
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9588
					__pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9589
				    } else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9590
					/* fetch source pixel */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9591
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9592
					int idx, pV;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9593
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9594
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9595
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9596
					idx = __srcY * __srcBytesPerRow + (__srcX >> 3);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9597
					if ((unsigned)idx < __nSrcBytes) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9598
					    pV = __srcBytes[idx];
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9599
					    __pix = (pV & (0x80 >> (__srcX & 7))) ? 1 : 0;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9600
					} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9601
					    __pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9602
					}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9603
				    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9604
				}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9605
			    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9606
			}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9607
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9608
			/* store pixel */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9609
			if (__pix != 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9610
			    *__dstPtr |= __dstMask;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9611
			}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9612
			__dstMask >>= 1;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9613
			if (__dstMask == 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9614
			    __dstMask = 0x80;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9615
			    __dstPtr++;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9616
			}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9617
		    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9618
		}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9619
		break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9620
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9621
	    case 24:
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9622
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9623
		    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9624
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9625
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9626
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9627
		    __pY = (double)(__dstY + __minY);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9628
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9629
		    __sinPY = __sin * __pY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9630
		    __cosPY = __cos * __pY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9631
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9632
		    __dstPtr = __dstRowPtr;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9633
		    __dstRowPtr += __dstBytesPerRow;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9634
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9635
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9636
			double __pX, __nX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9637
			unsigned __pix;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9638
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9639
			/* translate X in destination (center to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9640
			__pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9641
			/* rotate X */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9642
			__nX = (__cos * __pX) - __sinPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9643
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9644
			/* translate X in source (origin to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9645
			__nX = __nX + __halfW + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9646
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9647
			/* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9648
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9649
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9650
			    if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9651
				break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9652
			    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9653
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9654
			    __pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9655
			} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9656
			    int __srcX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9657
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9658
			    __srcX = (int)__nX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9659
			    /* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9660
			    if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9661
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9662
				if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9663
				    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9664
				}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9665
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9666
				__pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9667
			    } else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9668
				double __nY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9669
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9670
				/* rotate Y */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9671
				__nY = (__sin * __pX) + __cosPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9672
				/* translate Y in source (origin to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9673
				__nY = __nY + __halfH + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9674
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9675
				/* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9676
				if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9677
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9678
				    if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9679
					break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9680
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9681
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9682
				    __pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9683
				} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9684
				    int __srcY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9685
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9686
				    __srcY = (int)__nY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9687
				    /* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9688
				    if (__srcY >= __height) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9689
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9690
					if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9691
					    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9692
					}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9693
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9694
					__pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9695
				    } else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9696
					/* fetch source pixel */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9697
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9698
					int idx;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9699
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9700
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9701
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9702
					idx = __srcY * __srcBytesPerRow + __srcX + __srcX + __srcX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9703
					if ((unsigned)idx < __nSrcBytes) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9704
					    __pix = __srcBytes[idx];
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9705
					    __pix = (__pix<<8) | __srcBytes[idx+1];
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9706
					    __pix = (__pix<<8) | __srcBytes[idx+2];
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9707
					} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9708
					    __pix = __blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9709
					}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9710
				    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9711
				}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9712
			    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9713
			}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9714
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9715
			/* store pixel */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9716
			if (__pix != 0) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9717
			    __dstPtr[0] = (__pix >> 16 & 0xFF);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9718
			    __dstPtr[1] = (__pix >> 8) & 0xFF;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9719
			    __dstPtr[2] = __pix & 0xFF;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9720
			}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9721
			__dstPtr += 3;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9722
		    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9723
		}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9724
		break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9725
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9726
	    default:
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9727
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9728
		    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9729
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9730
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9731
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9732
		    __pY = (double)(__dstY + __minY);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9733
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9734
		    __sinPY = __sin * __pY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9735
		    __cosPY = __cos * __pY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9736
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9737
		    __dstPtr = __dstRowPtr;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9738
		    __dstMask = 0x80;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9739
		    __dstRowPtr += __dstBytesPerRow;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9740
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9741
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9742
			double __pX, __nX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9743
			OBJ __pix;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9744
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9745
			/* translate X in destination (center to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9746
			__pX = (double)(__dstX + __minX);
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9747
			/* rotate X */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9748
			__nX = (__cos * __pX) - __sinPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9749
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9750
			/* translate X in source (origin to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9751
			__nX = __nX + __halfW + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9752
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9753
			/* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9754
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9755
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9756
			    if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9757
				break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9758
			    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9759
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9760
			    __pix = blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9761
			} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9762
			    int __srcX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9763
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9764
			    __srcX = (int)__nX;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9765
			    /* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9766
			    if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9767
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9768
				if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9769
				    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9770
				}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9771
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9772
				__pix = blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9773
			    } else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9774
				double __nY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9775
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9776
				/* rotate Y */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9777
				__nY = (__sin * __pX) + __cosPY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9778
				/* translate Y in source (origin to 0/0) */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9779
				__nY = __nY + __halfH + 0.5;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9780
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9781
				/* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9782
				if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9783
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9784
				    if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9785
					break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9786
				    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9787
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9788
				    __pix = blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9789
				} else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9790
				    int __srcY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9791
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9792
				    __srcY = (int)__nY;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9793
				    /* inside ? */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9794
				    if (__srcY >= __height) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9795
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9796
					if (didFetchInRow) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9797
					    break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9798
					}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9799
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9800
					__pix = blackPixel;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9801
				    } else {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9802
					/* fetch source pixel */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9803
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9804
					static struct inlineCache valAt = _ILC2;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9805
#ifdef EARLY_OUT
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9806
					didFetchInRow = 1;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9807
#endif
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9808
					__pix = (*valAt.ilc_func)(self,
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9809
							      @symbol(pixelAtX:y:),
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9810
							      nil, &valAt,
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9811
							      __MKSMALLINT(__srcX),
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9812
							      __MKSMALLINT(__srcY));
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9813
				    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9814
				}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9815
			    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9816
			}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9817
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9818
			/* store pixel */
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9819
			{
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9820
			    static struct inlineCache atPutVal = _ILC3;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9821
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9822
			    if (__pix != __MKSMALLINT(0)) {
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9823
				(*atPutVal.ilc_func)(newImage,
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9824
						      @symbol(pixelAtX:y:put:),
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9825
						      nil, &atPutVal,
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9826
						      __MKSMALLINT(__dstX),
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9827
						      __MKSMALLINT(__dstY),
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9828
						      __pix
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9829
						     );
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9830
			    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9831
			}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9832
		    }
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9833
		}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9834
		break;
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9835
	}
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9836
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9837
	bad = false;
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9838
    }
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9839
%}.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9840
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9841
    bad ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9842
	"/ should not happen
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9843
	self primitiveFailed
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9844
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9845
"/        sinRot := radians negated sin.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9846
"/        cosRot := radians negated cos.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9847
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9848
"/        0 to:newHeight-1 do:[:dstY |
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9849
"/            pY := (dstY + minY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9850
"/            sinPY := (sinRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9851
"/            cosPY := (cosRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9852
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9853
"/            0 to:newWidth-1 do:[:dstX |
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9854
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9855
"/                "/ translate center to origin
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9856
"/                pX := (dstX + minX).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9857
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9858
"/                nX := (cosRot * pX) - sinPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9859
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9860
"/                "/ translate in source
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9861
"/                srcX := nX + halfW.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9862
"/                srcX := srcX rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9863
"/                "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9864
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9865
"/                (srcX >= 0 and:[srcX < width]) ifTrue:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9866
"/                    nY := (sinRot * pX) + cosPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9867
"/                    srcY := nY + halfH.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9868
"/                    srcY := srcY rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9869
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9870
"/                    "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9871
"/                    (srcY >= 0 and:[srcY < height]) ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9872
"/                        pix := self pixelAtX:srcX y:srcY
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9873
"/                    ] ifFalse:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9874
"/                        pix := blackPixel.        
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9875
"/                    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9876
"/                ] ifFalse:[
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9877
"/                    pix := blackPixel.        
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9878
"/                ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9879
"/                pix ~~ blackPixel ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9880
"/                    newImage pixelAtX:dstX y:dstY put:pix.        
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9881
"/                ]
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9882
"/            ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9883
"/        ].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9884
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9885
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9886
    ^ newImage
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9887
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9888
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9889
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9890
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9891
     i := Image fromFile:'goodies/bitmaps/xpmBitmaps/BOOK.xpm'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9892
     i inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9893
     (i rotated:45) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9894
     (i rotated:90) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9895
     (i rotated:91) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9896
     (i rotated:95) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9897
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9898
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9899
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9900
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9901
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9902
     i := Depth24Image fromImage:i.
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9903
     (i rotated:200) inspect
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9904
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9905
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9906
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9907
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9908
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9909
     Transcript showCR:(
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9910
	Time millisecondsToRun:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9911
	   i rotated:45.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9912
	]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9913
     ).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9914
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9915
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9916
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9917
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9918
     i := Image fromFile:'goodies/bitmaps/xpmBitmaps/BOOK.xpm'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9919
     v := View new extent:(i width max:100)@(i height max:100).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9920
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9921
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9922
     [true] whileTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9923
	rI := i rotated:rot.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9924
	rI := rI on:v device.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9925
	v clear.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9926
	v displayForm:rI x:v width//2-(rI width//2) y:v height//2-(rI height // 2).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9927
	rot := rot + 5.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9928
	rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9929
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9930
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9931
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9932
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9933
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9934
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9935
     v := View new extent:400@400.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9936
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9937
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9938
     [true] whileTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9939
	rI := i rotated:rot.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9940
	rI := rI on:v device.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9941
	v clear.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9942
	v displayForm:rI x:v width//2-(rI width//2) y:v height//2-(rI height // 2).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9943
	rot := rot + 5.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9944
	rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9945
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9946
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9947
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9948
    "Modified: 22.4.1997 / 17:36:37 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9949
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9950
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  9951
lightened
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9952
    "return a new image which is slightly brighter than the receiver.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9953
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9954
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale).
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9955
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  9956
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9957
     ^ self 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9958
	copyWithColorMapProcessing:[:clr | clr lightened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9959
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9960
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9961
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9962
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9963
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9964
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9965
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9966
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9967
    "Modified: 24.4.1997 / 18:31:23 / cg"
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  9968
!
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
  9969
134
claus
parents: 132
diff changeset
  9970
magnifiedBy:scale
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9971
    "return a new image magnified by scalePoint, aPoint.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  9972
     If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:'
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  9973
     while simple (integral) magnifications are handled here."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  9974
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9975
    |scalePoint mX mY
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9976
     magX      "{ Class: SmallInteger }"   "new version of stc can find this out itself..."
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9977
     magY      "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9978
     srcOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9979
     dstOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9980
     w         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9981
     h         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9982
     first
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9983
     newWidth newHeight newImage newBits newMask
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9984
     bitsPerPixel newBytesPerRow oldBytesPerRow|
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  9985
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9986
    scalePoint := scale asPoint.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  9987
    mX := scalePoint x.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  9988
    mY := scalePoint y.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9989
    ((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  9990
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
48194c26a46c Initial revision
claus
parents:
diff changeset
  9991
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
  9992
    ((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  9993
	^ self hardMagnifiedBy:scalePoint
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  9994
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  9995
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  9996
    bitsPerPixel := self depth.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  9997
    oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
  9998
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
  9999
    w := width.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10000
    h := height.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10001
    magX := mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10002
    magY := mY.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10003
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 10004
    newWidth := w * magX.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 10005
    newHeight := h * magY.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10006
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 10007
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
48194c26a46c Initial revision
claus
parents:
diff changeset
 10008
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10009
    mask notNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10010
	newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10011
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10012
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10013
    newImage := self species new.
905
228d503775d9 everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
 10014
    newImage 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10015
	width:newWidth 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10016
	height:newHeight 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10017
	photometric:photometric 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10018
	samplesPerPixel:samplesPerPixel 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10019
	bitsPerSample:bitsPerSample 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10020
	colorMap:colorMap copy
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10021
	bits:newBits
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10022
	mask:newMask.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10023
48194c26a46c Initial revision
claus
parents:
diff changeset
 10024
    mX = 1 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10025
	"expand rows only"
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10026
	srcOffset := 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10027
	dstOffset := 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10028
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10029
	1 to:h do:[:row |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10030
	    1 to:magY do:[:i |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10031
		newBits replaceFrom:dstOffset 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10032
			to:(dstOffset + oldBytesPerRow - 1)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10033
			with:bytes 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10034
			startingAt:srcOffset.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10035
		dstOffset := dstOffset + newBytesPerRow
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10036
	    ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10037
	    srcOffset := srcOffset + oldBytesPerRow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10038
	].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10039
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10040
	"expand cols"
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10041
	(mX > 1) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10042
	    dstOffset := 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10043
	    srcOffset := 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10044
	    1 to:h do:[:row |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10045
		self magnifyRowFrom:bytes 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10046
		     offset:srcOffset  
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10047
		     into:newBits 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10048
		     offset:dstOffset 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10049
		     factor:mX.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10050
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10051
		first := dstOffset.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10052
		dstOffset := dstOffset + newBytesPerRow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10053
		" and copy for row expansion "
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10054
		2 to:magY do:[:i |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10055
		    newBits replaceFrom:dstOffset 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10056
			    to:(dstOffset + newBytesPerRow - 1)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10057
			    with:newBits 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10058
			    startingAt:first.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10059
		    dstOffset := dstOffset + newBytesPerRow
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10060
		].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10061
		srcOffset := srcOffset + oldBytesPerRow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10062
	    ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10063
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10064
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
 10065
    ^ newImage
48194c26a46c Initial revision
claus
parents:
diff changeset
 10066
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10067
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10068
     ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') magnifiedBy:1@2)
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10069
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10070
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10071
    "Modified: 24.4.1997 / 18:32:04 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 10072
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 10073
154
claus
parents: 153
diff changeset
 10074
magnifiedPreservingRatioTo:anExtent 
claus
parents: 153
diff changeset
 10075
    "return a new image magnified to fit into anExtent,
claus
parents: 153
diff changeset
 10076
     preserving the receivers width/height ratio.
claus
parents: 153
diff changeset
 10077
     (i.e. not distorting the image).
claus
parents: 153
diff changeset
 10078
     See also #magnifiedTo: and #magnifiedBy:"
claus
parents: 153
diff changeset
 10079
claus
parents: 153
diff changeset
 10080
    |rX rY|
claus
parents: 153
diff changeset
 10081
claus
parents: 153
diff changeset
 10082
    rX := anExtent x / self width.
claus
parents: 153
diff changeset
 10083
    rY := anExtent y / self height.
claus
parents: 153
diff changeset
 10084
    ^ self magnifiedBy:(rX min:rY)
claus
parents: 153
diff changeset
 10085
claus
parents: 153
diff changeset
 10086
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10087
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
154
claus
parents: 153
diff changeset
 10088
claus
parents: 153
diff changeset
 10089
    in contrast to:
claus
parents: 153
diff changeset
 10090
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10091
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 10092
    "
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 10093
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 10094
    "Modified: 22.4.1997 / 12:33:46 / cg"
154
claus
parents: 153
diff changeset
 10095
!
claus
parents: 153
diff changeset
 10096
134
claus
parents: 132
diff changeset
 10097
magnifiedTo:anExtent 
154
claus
parents: 153
diff changeset
 10098
    "return a new image magnified to have the size specified by extent.
claus
parents: 153
diff changeset
 10099
     This may distort the image if the arguments ratio is not the images ratio.
claus
parents: 153
diff changeset
 10100
     See also #magnifiedPreservingRatioTo: and #magnifiedBy:"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10101
134
claus
parents: 132
diff changeset
 10102
    ^ self magnifiedBy:(anExtent / self extent)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10103
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10104
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10105
     ((Image fromFile:'goodies/bitmaps/garfield.gif') magnifiedTo:100@100)
154
claus
parents: 153
diff changeset
 10106
claus
parents: 153
diff changeset
 10107
    in contrast to:
claus
parents: 153
diff changeset
 10108
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10109
     ((Image fromFile:'goodies/bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10110
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10111
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10112
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10113
mixed:amount with:aColor
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10114
    "return a new image which is blended with some color; 
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10115
     amount determines how much of the blending color is applied (0..)
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10116
     where 0 means: blending color pure.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10117
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10118
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10119
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10120
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10121
     ^ self 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10122
	copyWithColorMapProcessing:[:clr | clr mixed:amount with:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10123
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10124
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10125
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10126
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:0.0 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10127
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:0.1 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10128
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:0.25 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10129
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:0.5 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10130
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:1 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10131
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:2 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10132
     ((Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') mixed:10 with:Color red) inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10133
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10134
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10135
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10136
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10137
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10138
negative
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10139
    "return a new image which is a negative of the receiver.
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10140
     The receiver must be a palette image (currently)."
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10141
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10142
    |newImage|
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10143
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10144
    colorMap isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10145
	photometric == #blackIs0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10146
	    newImage := self copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10147
	    newImage photometric:#whiteIs0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10148
	    ^ newImage
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10149
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10150
	photometric == #whiteIs0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10151
	    newImage := self copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10152
	    newImage photometric:#blackIs0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10153
	    ^ newImage
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10154
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10155
	^ nil
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10156
    ].
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10157
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10158
     ^ self 
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10159
	copyWithColorMapProcessing:[:clr | 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10160
		|newColor|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10161
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10162
		newColor := Color
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10163
				redByte:(255 - clr redByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10164
				greenByte:(255 - clr greenByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10165
				blueByte:(255 - clr blueByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10166
	]
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10167
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10168
    "
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10169
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10170
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') negative inspect
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10171
    "
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10172
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10173
    "Created: 20.6.1997 / 13:13:41 / cg"
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10174
    "Modified: 20.6.1997 / 13:17:50 / cg"
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10175
!
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10176
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10177
rotated:degrees
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10178
    "return a new image from the old one, by rotating the image
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10179
     degrees clockwise.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10180
     Notice, that the resulting image has a different extent.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10181
     If rotation is heavily used, the workHorse methods
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10182
     (#easyRotateBitsInto:angle: and #hardRotateBitsInto:angle) may
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10183
     be redefined in concrete image subclasses."
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10184
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10185
    |nW nH newImage newBits newBytesPerRow d|
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10186
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10187
    d := degrees.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10188
    [d < 0] whileTrue:[d := d + 360].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10189
    d >= 360 ifTrue:[d := d \\ 360].
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10190
    d := d truncated.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10191
    d = 0 ifTrue:[^ self].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10192
    ((d ~= 90) and:[(d ~= 270) and:[d ~= 180]]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10193
	^ self hardRotated:d
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10194
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10195
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10196
    d = 180 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10197
	nW := width.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10198
	nH := height.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10199
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10200
	nW := height.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10201
	nH := width.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10202
    ].
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10203
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10204
    newImage := self species new.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10205
    newImage width:nW.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10206
    newImage height:nH.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10207
    newBytesPerRow := newImage bytesPerRow.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10208
    newBits := ByteArray uninitializedNew:(newBytesPerRow * nH).
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10209
    newImage bits:newBits.
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10210
    newImage photometric:photometric.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10211
    newImage samplesPerPixel:samplesPerPixel.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10212
    newImage bitsPerSample:bitsPerSample.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10213
    newImage colorMap:colorMap copy.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10214
    mask notNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10215
	newImage mask:(mask rotated:degrees)
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10216
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10217
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10218
    self easyRotateBitsInto:newImage angle:d.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10219
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10220
    ^ newImage
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10221
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10222
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10223
     |i|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10224
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10225
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10226
     i inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10227
     (i rotated:45) inspect.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10228
     (i rotated:90) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10229
     (i rotated:180) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10230
     (i rotated:270) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10231
    "
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10232
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10233
     |i|
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10234
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10235
     i := Image fromFile:'goodies/bitmaps/xpmBitmaps/BOOK.xpm'.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10236
     i inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10237
     (i rotated:90) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10238
     (i rotated:180) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10239
     (i rotated:270) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10240
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10241
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10242
    "Modified: 24.4.1997 / 18:33:42 / cg"
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10243
!
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10244
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10245
withPixelFunctionApplied:pixelFunctionBlock
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10246
    "return a new image from the old one, by applying a pixel processor
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10247
     on the pixel colors.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10248
     Notice: this method is very slow - either apply pixel values
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10249
     (#withPixelFunctionAppliedToPixels:) or redefine this method in
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10250
     a concrete subclass.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10251
     (read `Behond photography, by Gerard J. Holzmann;
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10252
	   ISBM 0-13-074410-7)
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10253
     See blurred / oilPointed as examples ...)"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10254
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10255
    |w  "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10256
     h  "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
 10257
     newImage newBits newBytesPerRow|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10258
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10259
    newBytesPerRow := ((width * self depth) + 7) // 8.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10260
    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10261
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10262
    newImage := self species new.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10263
    newImage bits:newBits.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10264
    newImage width:width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10265
    newImage height:height.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10266
    newImage photometric:photometric.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10267
    newImage samplesPerPixel:samplesPerPixel.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10268
    newImage bitsPerSample:bitsPerSample.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10269
    newImage colorMap:colorMap copy.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10270
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10271
    w := width - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10272
    h := height - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10273
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10274
    0 to:h do:[:y |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10275
	0 to:w do:[:x |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10276
	    newImage colorAtX:x y:y put:(pixelFunctionBlock
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10277
						value:self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10278
						value:(self colorAtX:x y:y)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10279
						value:x
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10280
						value:y)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10281
	]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10282
    ].
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10283
    ^ newImage
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10284
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10285
    "black out everything except for some rectangle:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10286
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10287
     |i black|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10288
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10289
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10290
     i inspect.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10291
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10292
     black := Color black.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10293
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10294
			((x between:100 and:200) 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10295
			and:[y between:100 and:200]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10296
			    oldColor
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10297
			] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10298
			    black.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10299
			]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10300
		     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10301
    "
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10302
    "brighten a frame:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10303
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10304
     |i black w h|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10305
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10306
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10307
     i inspect.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10308
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10309
     w := i width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10310
     h := i height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10311
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10312
			((x between:0 and:10) 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10313
			or:[(y between:0 and:10)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10314
			or:[(x between:w-10 and:w)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10315
			or:[y between:h-10 and:h]]]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10316
			    oldColor lightened nearestIn:i colorMap
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10317
			] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10318
			    oldColor.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10319
			]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10320
		     ]) inspect.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10321
    "
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10322
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10323
    "Modified: 24.4.1997 / 18:36:59 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10324
!
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10325
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10326
withPixelFunctionAppliedToPixels:pixelFunctionBlock
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10327
    "return a new image from the old one, by applying a pixel processor
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10328
     on the pixel values.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10329
     (read `Behond photography, by Gerard J. Holzmann;
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10330
	   ISBM 0-13-074410-7)
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10331
     See blurred / oilPointed as examples ...)"
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10332
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10333
    |newImage newBits newBytesPerRow|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10334
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10335
    newBytesPerRow := ((width * self depth) + 7) // 8.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10336
    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10337
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10338
    newImage := self species new.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10339
    newImage bits:newBits.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10340
    newImage width:width.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10341
    newImage height:height.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10342
    newImage photometric:photometric.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10343
    newImage samplesPerPixel:samplesPerPixel.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10344
    newImage bitsPerSample:bitsPerSample.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10345
    newImage colorMap:colorMap copy.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10346
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10347
    self applyPixelValuesTo:pixelFunctionBlock into:newImage.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10348
    ^ newImage
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10349
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10350
    "oil painting effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10351
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10352
     |i w h|
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10353
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10354
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10355
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10356
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10357
     h := i height - 1.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10358
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10359
			|b p max xMin xMax yMin yMax|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10360
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10361
			b := Bag identityNew:10.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10362
			xMin := x-3 max:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10363
			xMax := x+3 min:w.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10364
			yMin := y-3 max:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10365
			yMax := y+3 min:h.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10366
			xMin to:xMax do:[:tx|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10367
			  yMin to:yMax do:[:ty|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10368
			    b add:(oldImage pixelAtX:tx y:ty)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10369
			  ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10370
			].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10371
			max := 0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10372
			b contents keysAndValuesDo:[:pixel :n |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10373
			    n > max ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10374
				p := pixel.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10375
				max := n
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10376
			    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10377
			].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10378
			p
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10379
		     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10380
    "
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10381
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10382
    "fisheye effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10383
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10384
     |i w h w2 h2 R white|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10385
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10386
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10387
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10388
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10389
     h := i height - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10390
     w2 := w // 2.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10391
     h2 := h // 2.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10392
     R := w2.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10393
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10394
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10395
			|p r a nR nP nX nY|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10396
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10397
			p := (x-w2)@(y-h2).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10398
			r := p r.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10399
			a := p theta.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10400
			nR := r * r / R.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10401
			nP := Point r:nR theta:a.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10402
			nX := ((nP x+w2) rounded max:0) min:w.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10403
			nY := ((nP y+h2) rounded max:0) min:h.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10404
			(nX > w or:[nX < 0]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10405
			    white
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10406
			] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10407
			    (nY > h or:[nY < 0]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10408
				white
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10409
			    ] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10410
				oldImage pixelAtX:nX y:nY
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10411
			    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10412
			]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10413
		     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10414
    "
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10415
    "fisheye effect:
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10416
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10417
     |i w h w2 h2 R white|
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10418
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10419
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10420
     i inspect.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10421
     w := i width - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10422
     h := i height - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10423
     w2 := w // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10424
     h2 := h // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10425
     R := w2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10426
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10427
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10428
			|p r a nR nP nX nY|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10429
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10430
			p := (x-w2)@(y-h2).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10431
			r := p r.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10432
			a := p theta.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10433
			nR := r * r / R.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10434
			nP := Point r:nR theta:a.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10435
			nX := (nP x+w2) rounded.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10436
			nY := (nP y+h2) rounded.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10437
			(nX > w or:[nX < 0]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10438
			    white
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10439
			] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10440
			    (nY > h or:[nY < 0]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10441
				white
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10442
			    ] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10443
				oldImage pixelAtX:nX y:nY
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10444
			    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10445
			]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10446
		     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10447
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10448
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10449
    "Created: 24.4.1997 / 18:37:17 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10450
    "Modified: 24.4.1997 / 18:40:02 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10451
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10452
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10453
!Image methodsFor:'inspecting'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10454
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10455
inspectorClass
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10456
    "redefined to launch an ImageInspector
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10457
     (instead of the default InspectorView)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10458
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10459
    (width notNil and:[height notNil]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10460
	^ ImageInspectorView
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10461
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10462
    ^ super inspectorClass
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10463
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10464
    "Modified: 10.6.1996 / 18:23:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10465
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10466
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10467
!Image methodsFor:'instance release'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10468
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10469
close
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10470
    "release device resources; destroy any device-resources"
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10471
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10472
    deviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10473
	deviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10474
	deviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10475
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10476
    monoDeviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10477
	monoDeviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10478
	monoDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10479
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10480
    fullColorDeviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10481
	fullColorDeviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10482
	fullColorDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10483
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10484
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10485
    device := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10486
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10487
	mask close.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10488
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10489
    Lobby unregister:self.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10490
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10491
    "Modified: 21.6.1996 / 19:08:19 / cg"
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10492
    "Created: 24.4.1997 / 11:55:20 / cg"
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10493
!
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10494
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10495
quickRelease
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10496
    "release device resources"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10497
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10498
    device := nil.
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10499
    deviceForm := nil.
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10500
    monoDeviceForm := nil.
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10501
    fullColorDeviceForm := nil.
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10502
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10503
    "Modified: 16.1.1997 / 19:33:01 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10504
!
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
 10505
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10506
release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10507
    "release device resources"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10508
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10509
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10510
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10511
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10512
    fullColorDeviceForm := nil.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 10513
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10514
	mask release.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 10515
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 10516
    Lobby unregister:self.
1746
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 10517
    super release.
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 10518
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 10519
    "Modified: 11.6.1997 / 13:20:04 / cg"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10520
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10521
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10522
restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10523
    "flush device specifics after a snapin or binary restore"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10524
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10525
    self release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10526
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10527
2227
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10528
!Image methodsFor:'misc'!
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10529
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10530
edit
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10531
    "open an image editor on the receiver"
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10532
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10533
    ImageEditor openOnImage:self.
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10534
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10535
    "Created: / 8.8.1998 / 01:25:15 / cg"
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10536
! !
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10537
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10538
!Image methodsFor:'obsolete'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10539
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10540
magnifyBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10541
    "obsolete: has been renamed to magnifiedBy: for ST-80 compatibility
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10542
     and name consistency ..."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10543
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10544
    self obsoleteMethodWarning.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10545
    ^ self magnifiedBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10546
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10547
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10548
!Image methodsFor:'pixel copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10549
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10550
copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h
1248
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
 10551
    "replace a rectangular area by pixels from another image.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10552
     The sources colors must be present in the destinations
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10553
     colorMap - otherwise, an error will be reported.
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10554
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10555
     WARNING:
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10556
       This implementation is a very slow fallback general algorithm
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10557
       (the loop over the source pixels is very slow).
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10558
       If this method is used heavily, you may want to redefine it in 
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10559
       concrete subclasses for the common case of of copying from an Image 
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10560
       with the same depth & palette.
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10561
       If you do heavy image processing, specialized versions are even req'd 
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10562
       for other cases, rewriting the inner loops as inline C-code."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10563
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10564
    |dX dY|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10565
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10566
    dX := srcX-dstX.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10567
    dY := srcY-dstY.
1248
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
 10568
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10569
    ((photometric == anImage photometric)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10570
     and:[self bitsPerPixel == anImage bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10571
     and:[colorMap = anImage colorMap]]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10572
	"/ can loop over values
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10573
	anImage valuesFromX:srcX  y:srcY 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10574
			toX:srcX+w-1 y:srcY+h-1  
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10575
			 do:[:x :y :pixelValue |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10576
	    self pixelAtX:x-dX y:y-dY put:pixelValue.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10577
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10578
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10579
	"/ must loop over colors - horribly slow
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10580
	anImage colorsFromX:srcX  y:srcY 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10581
			toX:srcX+w-1 y:srcY+h-1  
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10582
			 do:[:x :y :clr |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10583
	    self colorAtX:x-dX y:y-dY put:clr.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10584
	]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10585
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10586
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10587
    (mask isNil and:[anImage mask notNil]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10588
	"/ I have no mask; copied image has
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10589
	self createMask.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10590
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10591
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10592
    mask notNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10593
	anImage mask notNil ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10594
	    "/ both have a mask
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10595
	    mask copyFrom:anImage mask x:srcX y:srcY toX:dstX y:dstY width:w height:h
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10596
	] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10597
	    "/ I have a mask - copied image has not
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10598
	    mask fillRectangleX:dstX y:dstY width:w height:h withValue:1
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10599
	]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10600
"/    ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10601
"/        anImage mask notNil ifTrue:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10602
"/            "/ I have no mask; copied image has (already handled)
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10603
"/        ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10604
"/            "/ none has a mask - nothing to do.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10605
"/        ]
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10606
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10607
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10608
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10609
     |i1 i8 i4|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10610
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10611
     i8 := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10612
     i8 inspect.
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10613
     i1 := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10614
     i1 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10615
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10616
     i4 := Depth4Image fromImage:i8.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10617
     i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:20 height:20.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10618
     i4 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10619
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10620
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10621
    "Created: 20.9.1995 / 10:14:01 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10622
    "Modified: 20.9.1995 / 10:25:31 / claus"
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10623
    "Modified: 21.6.1997 / 13:15:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10624
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10625
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10626
subImageIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10627
    "create and return a new image consisting of a subArea of myself"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10628
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10629
    ^ self class fromSubImage:self in:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10630
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10631
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10632
     |i|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10633
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10634
     i := Image fromFile:'goodies/bitmaps/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10635
     i inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10636
     (i subImageIn:(300@160 corner:340@200)) inspect
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10637
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10638
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10639
    "Created: 20.9.1995 / 01:24:20 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10640
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10641
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10642
!Image methodsFor:'printing & storing'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10643
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10644
storeOn:aStream
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10645
    "append a printed representation of the receiver to aStream,
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10646
     from which a copy of it can be reconstructed."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10647
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10648
    aStream nextPutAll:'(' , self class name , ' new)'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10649
    aStream nextPutAll:' width: '. width storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10650
    aStream nextPutAll:'; height: '. height storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10651
    aStream nextPutAll:'; photometric:('. photometric storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10652
    aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10653
    aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream. 
2059
d0027278830c more compressive #storeOn:
tz
parents: 2054
diff changeset
 10654
    aStream nextPutAll:'); bits:(ByteArray fromPackedString:'. bytes asPackedString storeOn:aStream. aStream nextPutAll:') '.
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 10655
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 10656
    colorMap notNil 
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 10657
    ifTrue:
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 10658
    [
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10659
	|colorMapArray colors usedValues|
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10660
	colorMapArray := OrderedCollection new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10661
	colors := colorMap.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10662
	"/ cut off unused colors ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10663
	self depth <= 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10664
	    usedValues := self usedValues.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10665
	    colors := colors copyFrom:1 to:((usedValues max+1) min:colors size)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10666
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10667
	colors do: [:clr| colorMapArray add: clr redByte; add: clr greenByte; add: clr blueByte].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10668
	aStream nextPutAll:'; colorMapFromArray:'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10669
	colorMapArray asByteArray storeOn:aStream.
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 10670
    ].  
1962
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
 10671
    mask notNil
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
 10672
    ifTrue:
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
 10673
    [
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10674
	aStream nextPutAll:'; mask:('.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10675
	mask storeOn:aStream.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10676
	aStream nextPutAll:')'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10677
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10678
    aStream nextPutAll:'; yourself'
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
 10679
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
 10680
    "Modified: / 22.8.1998 / 12:55:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10681
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 10682
48194c26a46c Initial revision
claus
parents:
diff changeset
 10683
!Image methodsFor:'private'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 10684
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10685
bestSupportedImageFormatFor:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10686
    "scan through the image formats as supported by aDevice,
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10687
     and return the best to use when the receiver is to be represented
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10688
     on it. The best format is the one with the same number or more bits per
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 10689
     pixel. Here, the smallest format found which can represent enough pixels is taken."
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 10690
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 10691
    |bestDeviceDepth
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 10692
     bestDeviceBitsPerPixel "{ Class: SmallInteger }"
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 10693
     "maxDepth" 
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 10694
     bestInfo maxInfo 
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 10695
     myDepth                "{ Class: SmallInteger }"
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 10696
     maxBitsPerPixel        "{ Class: SmallInteger }"|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10697
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10698
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10699
    maxBitsPerPixel := 0.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10700
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10701
    aDevice supportedImageFormats do:[:entry |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10702
	|deviceImageDepth        "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10703
	 deviceImageBitsPerPixel "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10704
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10705
	deviceImageDepth := entry at:#depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10706
	deviceImageBitsPerPixel := entry at:#bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10707
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10708
	"/ for now, ignore all depth's which are neither 1 nor the
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10709
	"/ devices depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10710
	"/ (actually, many devices can handle other pixMap formats,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10711
	"/ but I dont know (yet) how to pass the correct color info
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 10712
        
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10713
	((deviceImageDepth == 1) or:[deviceImageDepth == aDevice depth]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10714
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10715
	    deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10716
		maxInfo := entry.
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 10717
    "/            maxBitsPerPixel := deviceImageBitsPerPixel.
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 10718
    "/            maxDepth := deviceImageDepth.
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10719
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10720
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10721
	    deviceImageDepth >= myDepth ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10722
		deviceImageDepth == myDepth ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10723
		    "/ take the better one ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10724
		    (bestDeviceDepth isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10725
		     or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10726
			and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10727
			bestInfo := entry.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10728
			bestDeviceDepth := deviceImageDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10729
			bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10730
		    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10731
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10732
		    "/ take the next-larger depth
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10733
		    (bestDeviceDepth isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10734
		     or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10735
			bestInfo := entry.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10736
			bestDeviceDepth := deviceImageDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10737
			bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10738
		    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10739
		]    
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10740
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10741
	].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10742
    ].
851
c9511f8945ce fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents: 841
diff changeset
 10743
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10744
    bestDeviceDepth isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10745
	maxBitsPerPixel == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10746
	    "/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10747
	    "/ oops - nothing appropriate
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10748
	    "/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10749
	    maxInfo notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10750
		^ maxInfo
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10751
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10752
	    bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10753
	    bestInfo := IdentityDictionary new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10754
	    bestInfo at:#depth put:bestDeviceDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10755
	    bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10756
	    bestInfo at:#padding put:32.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10757
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10758
	    bestInfo := maxInfo.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10759
	]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 10760
    ].
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 10761
    ^ bestInfo
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 10762
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 10763
    "Modified: / 7.2.1998 / 11:23:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10764
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10765
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10766
colormapFromImage:anImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10767
    "setup the receivers colormap from another image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10768
     Color precision may be lost, if conversion is from a higher depth
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10769
     image. This does not convert any pixel values; it is  non-public helper
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10770
     for fromImage:/fromSubImake:"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10771
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 10772
    self colormapFromImage:anImage photometric:nil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 10773
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 10774
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 10775
colormapFromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 10776
    "setup the receivers colormap from another image.
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 10777
     Color precision may be lost, if conversion is from a higher depth
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 10778
     image. This does not convert any pixel values; it is  non-public helper
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 10779
     for fromImage:/fromSubImake:"
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 10780
2447
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 10781
    |usedColors|
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 10782
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10783
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10784
	photometric := #rgb
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10785
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10786
	photometricOrNil isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10787
	    photometric := anImage photometric.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10788
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10789
	    photometric := photometricOrNil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10790
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10791
	photometric == #palette ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10792
	    colorMap := anImage colorMap copy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10793
	    "
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10794
	     must generate/compress the colormap, if source image has higher depth
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10795
	     than myself. 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10796
	    "
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10797
	    (colorMap isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10798
	    or:[anImage bitsPerPixel > self bitsPerPixel]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10799
		"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10800
		 get used colors are extracted into our colorMap
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10801
		 (the at-put below will set the pixelValue according the
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10802
		 new colorIndex
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10803
		"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10804
		colorMap := anImage usedColors asArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10805
		colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10806
		    'Image [warning]: possibly too many colors in image' errorPrintCR
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10807
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10808
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10809
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10810
	    usedColors := anImage usedColors asArray.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10811
	    usedColors size > (1 bitShift:self bitsPerPixel) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10812
		'Image [warning]: possibly too many colors in image' errorPrintCR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10813
		usedColors := usedColors copyTo:(1 bitShift:self bitsPerPixel).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10814
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10815
	    colorMap := usedColors.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10816
	    photometric := #palette
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10817
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10818
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10819
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10820
    "Created: 20.9.1995 / 00:58:42 / claus"
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 10821
    "Modified: 10.1.1997 / 17:52:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10822
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10823
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10824
greyByteMapForRange:range
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10825
    "return a collection to map from pixelValues to greyLevels
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10826
     in the range 0..range. 
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10827
     Range must be < 256 (for elements to fit into a ByteArray).
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10828
     The values are rounded towards the nearest pixel."
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10829
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 10830
    |d clr val greyMap r
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 10831
     n "{ Class: SmallInteger }"|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 10832
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 10833
    r := range.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 10834
    r == 256 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10835
	r := 255
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10836
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10837
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10838
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10839
	n := colorMap size.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10840
	greyMap := ByteArray new:n.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10841
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10842
	1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10843
	    (clr := colorMap at:i) isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10844
		"/ an unused color
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10845
		val := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10846
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10847
		val := (r * clr brightness) rounded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10848
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10849
	    greyMap at:i put:val
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10850
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10851
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10852
	d := self bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10853
	n := 1 bitShift:d.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10854
	n >= 4096 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10855
	    self error:'size not supported - too large'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10856
	    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10857
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10858
	greyMap := ByteArray new:n.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10859
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10860
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10861
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10862
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10863
		greyMap at:i put:(r * (self colorFromValue:i-1) brightness) rounded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10864
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10865
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10866
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10867
		greyMap at:i put:(r / (n-1) * (i-1)) rounded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10868
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10869
	    photometric == #blackIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10870
		"/ we are done
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10871
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10872
		photometric == #whiteIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10873
		    greyMap reverse
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10874
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10875
		    self error:'invalid format'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10876
		    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10877
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10878
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10879
	].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10880
    ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 10881
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10882
    ^ greyMap
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10883
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10884
    "
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 10885
     Depth8Image new greyByteMapForRange:256
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 10886
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 10887
     Depth8Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 10888
     Depth4Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 10889
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 10890
     Depth4Image new greyByteMapForRange:1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10891
    "
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10892
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10893
    "Created: 8.6.1996 / 08:34:14 / cg"
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 10894
    "Modified: 1.3.1997 / 17:24:45 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10895
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10896
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10897
greyMapForRange:range
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10898
    "return a collection to map from pixelValues to greyLevels
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10899
     in the range 0..range. The brightness values are not rounded."
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10900
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 10901
    |d r clr val
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 10902
     n "{Class: SmallInteger }"
1927
d1bbdf03e5a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1919
diff changeset
 10903
     n2 "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 10904
     greyArray|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10905
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10906
    d := self bitsPerPixel.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10907
    n := 1 bitShift:d.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10908
    n >= 4096 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10909
	self error:'size not supported - too large'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10910
	^ nil
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10911
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10912
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 10913
    greyArray := Array new:n.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10914
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10915
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10916
	n2 := colorMap size.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10917
	1 to:n2 do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10918
	    (clr := colorMap at:i) isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10919
		"/ an unused color
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10920
		val := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10921
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10922
		val := range * clr brightness
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10923
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10924
	    greyArray at:i put:val
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10925
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10926
	n2 < n ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10927
	    greyArray from:n2+1 to:n put:0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10928
	]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 10929
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10930
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10931
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10932
		greyArray at:i put:(range * (self colorFromValue:(i-1)) brightness)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10933
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10934
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10935
	    r := range asFloat.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10936
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10937
		greyArray at:i put:(r / (n-1) * (i-1))
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10938
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10939
	    photometric == #blackIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10940
		"/ we are done
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10941
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10942
		photometric == #whiteIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10943
		    greyArray reverse
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10944
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10945
		    self error:'invalid format'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10946
		    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10947
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10948
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10949
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10950
    ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 10951
    ^ greyArray
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10952
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10953
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10954
     Depth8Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10955
     Depth4Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10956
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 10957
     Depth16Image new greyMapForRange:1
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10958
     Depth4Image new greyMapForRange:1
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 10959
     Depth2Image new greyMapForRange:1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 10960
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 10961
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 10962
    "Modified: 1.3.1997 / 15:48:49 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10963
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10964
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10965
magnifyRowFrom:srcBytes offset:srcStart pixels:oldPixels 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10966
	  into:dstBytes offset:dstStart factor:mX
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10967
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10968
    "magnify a single pixel row - can only magnify by integer factors,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10969
     can only magnify 1,2,4,8 and 24 bit-per-pixel images. But this is done fast."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10970
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10971
    ^ self subclassResponsibility
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10972
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10973
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 10974
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 10975
    "given the bits of a grey/color bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 10976
     pixels interpreted as greyValues, 0 is black,  
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 10977
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 10978
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10979
    |f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10980
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10981
    f := Form width:width height:height depth:depth on:aDevice.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10982
    f isNil ifTrue:[^ nil].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10983
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10984
    f bits:bits.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10985
    f initGC.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10986
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10987
    (aDevice blackpixel ~~ 0) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10988
	"/ have to invert bits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10989
	f function:#copyInverted
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 10990
    ].
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
 10991
    aDevice 
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
 10992
	drawBits:bits 
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
 10993
	depth:depth
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
 10994
	padding:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10995
	width:width height:height
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10996
	x:0 y:0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10997
	into:(f id) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10998
	x:0 y:0 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10999
	width:width height:height 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11000
	with:(f gcId).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11001
    ^ f
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11002
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11003
    "Created: 10.6.1996 / 20:10:31 / cg"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11004
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11005
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11006
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11007
    "given the bits of a monochrome bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11008
     0-bits as black, create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11009
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 11010
"/    monoBits invert.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11011
    ^ (Form width:width height:height fromArray:monoBits on:aDevice)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11012
	colorMap:(Array with:Color black with:Color white).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11013
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11014
    "Created: 10.6.1996 / 20:18:09 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 11015
    "Modified: 17.4.1997 / 01:07:38 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11016
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11017
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11018
makeDevicePixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11019
    "given the bits of a grey/color bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11020
     pixels interpreted as in the devices colormap, 
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11021
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11022
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11023
    |f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11024
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11025
    f := Form width:width height:height depth:depth on:aDevice.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11026
    f isNil ifTrue:[^ nil].
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11027
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11028
    f bits:bits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11029
    f initGC.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11030
1999
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
 11031
    aDevice 
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
 11032
	drawBits:bits 
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
 11033
	depth:depth
9ccc51eea588 always pass the padding down to device
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
 11034
	padding:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11035
	width:width height:height
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11036
	x:0 y:0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11037
	into:(f id) 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11038
	x:0 y:0 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11039
	width:width height:height 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11040
	with:(f gcId).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11041
    ^ f
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11042
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11043
    "Created: 10.6.1996 / 17:56:08 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11044
    "Modified: 10.6.1996 / 20:11:27 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11045
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11046
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11047
!Image methodsFor:'queries'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11048
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11049
alphaBitsOf:pixel
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11050
    "if the receiver is an rgb-image:
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11051
     return the alpha component of a pixelValue as integer 0..maxAlphaValue.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11052
     MaxAlphaValue is of course the largest integer representable by the number
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11053
     of alpha bits i.e. (1 bitShift:bitsAlpha)-1.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11054
     This has to be redefined by subclasses."
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11055
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11056
    |redBits greenBits blueBits alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11057
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11058
    samplesPerPixel >= 4 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11059
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11060
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11061
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11062
	alphaBits := bitsPerSample at:4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11063
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11064
	^ (pixel bitShift:(redBits + greenBits + blueBits) negated)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11065
	   bitAnd:(1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11066
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11067
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11068
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11069
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11070
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11071
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11072
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11073
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11074
alphaMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11075
    "return the mask used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11076
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11077
    |alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11078
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11079
    samplesPerPixel >= 4 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11080
	alphaBits := bitsPerSample at:4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11081
	^ (1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11082
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11083
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11084
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11085
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11086
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11087
alphaShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11088
    "return the shift amount used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11089
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11090
    |redBits greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11091
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11092
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11093
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11094
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11095
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11096
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11097
	^ (greenBits + blueBits + redBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11098
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11099
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11100
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11101
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11102
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11103
averageColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11104
    "return the average color of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11105
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11106
     (i.e. to compute shadow & light colors for viewBackgrounds).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11107
     Notice, that for the above purpose, it is usually ok to process 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11108
     a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11109
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11110
    ^ self averageColorIn:(0@0 corner:(width-1)@(height-1))
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11111
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11112
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11113
averageColorIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11114
    "return the images average color in an area.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11115
     The implementation below is slow - so you may want to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11116
     create tuned versions for DepthXImage if you plan to do
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11117
     heavy image processing ... 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11118
     (also, creating tuned versions of the enumeration messages helps a lot)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11119
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11120
    |x0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11121
     y0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11122
     x1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11123
     y1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11124
     sumRed sumGreen sumBlue n|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11125
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11126
    sumRed := sumGreen := sumBlue := 0.    
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11127
    y0 := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11128
    y1 := aRectangle bottom.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11129
    x0 := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11130
    x1 := aRectangle right.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11131
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11132
    self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY |
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11133
       sumRed := sumRed + colorAtXY red.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11134
       sumGreen := sumGreen + colorAtXY green.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11135
       sumBlue := sumBlue + colorAtXY blue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11136
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11137
    n := (x1 - x0 + 1) * (y1 - y0 + 1).    
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11138
    ^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11139
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11140
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11141
bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11142
    "return the number of bits per pixel"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11143
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11144
    ^ (bitsPerSample inject:0 into:[:sum :i | sum + i])
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11145
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11146
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11147
bitsPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11148
    "return the number of bits in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11149
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11150
    ^  width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11151
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11152
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11153
blackComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11154
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11155
     return the black component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11156
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11157
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11158
	"/ assume that the cyan bits are the leftMost bits (cmyk)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11159
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11160
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11161
	    ^ 100.0 / 255 * (pixel bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11162
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11163
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11164
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11165
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11166
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11167
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11168
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11169
blueBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11170
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11171
     return the blue bits of a pixelValue as integer 0..maxBlueValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11172
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11173
     of blue bits i.e. (1 bitShift:bitsBlue)-1.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11174
     This has to be redefined by subclasses."
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11175
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11176
    |blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11177
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11178
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11179
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11180
	^ pixel bitAnd:(1 bitShift:blueBits)-1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11181
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11182
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11183
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11184
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11185
    "Created: 8.6.1996 / 09:44:21 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11186
    "Modified: 10.6.1996 / 14:59:44 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11187
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11188
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11189
blueComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11190
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11191
     return the blue component scaled to a percentage (0 .. 100) of a pixelValue.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11192
     This has to be redefined by subclasses."
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11193
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11194
    |blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11195
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11196
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11197
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11198
	"/ assume that the red bits are the leftMost bits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11199
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11200
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11201
	blueBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11202
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11203
	s := (1 bitShift:blueBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11204
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11205
	^ 100.0 / s * (pixel bitAnd:(1 bitShift:blueBits)-1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11206
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11207
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11208
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11209
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11210
    "Created: 8.6.1996 / 08:45:22 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11211
    "Modified: 10.6.1996 / 14:55:39 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11212
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11213
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11214
blueMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11215
    "return the mask used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11216
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11217
    |blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11218
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11219
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11220
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11221
	^ (1 bitShift:blueBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11222
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11223
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11224
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11225
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11226
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11227
blueShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11228
    "return the shift amount used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11229
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11230
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11231
	^ 0
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11232
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11233
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11234
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11235
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11236
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11237
bounds
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11238
    "return my bounds (added to make images usable as VisualComponents)"
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11239
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11240
    ^ Rectangle left:0 top:0 width:width height:height
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11241
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11242
    "Created: 13.5.1996 / 10:27:06 / cg"
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11243
!
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11244
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11245
brightness
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11246
    "return the (average) brightness of the image.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11247
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11248
     (i.e. to compute shadow & light colors for viewBackgrounds).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11249
     Notice, that for the above purpose, only a subimage is inspected here"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11250
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11251
    ^ (self averageColorIn:(0@0 corner:7@7)) brightness
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11252
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11253
    "Modified: 8.6.1996 / 08:46:46 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11254
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11255
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11256
bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11257
    "return the number of bytes in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11258
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11259
    |bitsPerRow bytesPerRow|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11260
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11261
    bitsPerRow := width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11262
    bytesPerRow := bitsPerRow // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11263
    ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11264
	bytesPerRow := bytesPerRow + 1
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11265
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11266
    ^ bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11267
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11268
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11269
bytesPerRowPaddedTo:padding
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11270
    "return the number of bytes in one scanline of the image,
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11271
     if scanlines are to be padded to padding-bits."
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11272
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
 11273
    ^ self class
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11274
	bytesPerRowForWidth:width depth:(self bitsPerPixel) padding:padding
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11275
!
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11276
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11277
center
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11278
    "for compatibility with GC protocol - return the centerPoint"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11279
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11280
    ^ (width // 2) @ (height // 2)
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11281
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11282
    "Created: 22.10.1997 / 23:52:40 / cg"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11283
!
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11284
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11285
colorFromValue:pixelValue
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11286
    "given a pixel value, return the corresponding color.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11287
     Pixel values start with 0."
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11288
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11289
    |p maxPixel clr r g b c m y k|
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11290
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11291
    p := photometric.
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11292
    p isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11293
	colorMap notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11294
	    p := #palette
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11295
	] ifFalse:[
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11296
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11297
	    p := #blackIs0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11298
	]
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11299
    ].
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11300
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11301
    p == #blackIs0 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11302
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11303
	^ Color gray:(pixelValue * (100 / maxPixel)).
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11304
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11305
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11306
    p == #whiteIs0 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11307
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11308
	^ Color gray:100 - (pixelValue * (100 / maxPixel)).
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11309
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11310
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11311
    p == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11312
	pixelValue >= colorMap size ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11313
	    ^ Color black
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11314
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11315
	clr := colorMap at:(pixelValue + 1).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11316
	clr isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11317
	    ^ Color black.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11318
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11319
	^ clr.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11320
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11321
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11322
    p == #rgb ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11323
	r := self redBitsOf:pixelValue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11324
	g := self greenBitsOf:pixelValue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11325
	b := self blueBitsOf:pixelValue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11326
	"/ must scale to byte value...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11327
	r := r bitShift:(8 - (bitsPerSample at:1)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11328
	g := g bitShift:(8 - (bitsPerSample at:2)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11329
	b := b bitShift:(8 - (bitsPerSample at:3)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11330
	^ Color redByte:r greenByte:g blueByte:b
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11331
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11332
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11333
    p == #cmyk ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11334
	c := self cyanComponentOfCMYK:pixelValue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11335
	m := self magentaComponentOfCMYK:pixelValue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11336
	y := self yellowComponentOfCMYK:pixelValue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11337
	k := self blackComponentOfCMYK:pixelValue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11338
	^ Color cyan:c magenta:m yellow:y black:k.
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11339
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11340
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11341
    p == #cmy ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11342
	c := self cyanComponentOfCMY:pixelValue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11343
	m := self magentaComponentOfCMY:pixelValue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11344
	y := self yellowComponentOfCMY:pixelValue.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11345
	^ Color cyan:c magenta:m yellow:y.
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11346
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11347
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11348
    self error:'invalid (unsupported) photometric'
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11349
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11350
    "Created: 8.6.1996 / 08:46:18 / cg"
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11351
    "Modified: 28.1.1997 / 12:05:22 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11352
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11353
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11354
cyanComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11355
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11356
     return the cyan component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11357
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11358
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11359
	"/ assume that the cyan bits are the leftMost bits (cmy)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11360
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11361
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11362
	    ^ 100.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11363
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11364
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11365
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11366
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11367
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11368
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11369
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11370
cyanComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11371
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11372
     return the cyan component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11373
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11374
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11375
	"/ assume that the cyan bits are the leftMost bits (cmyk)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11376
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11377
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11378
	    ^ 100.0 / 255 * ((pixel bitShift:-24) bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11379
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11380
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11381
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11382
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11383
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11384
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11385
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11386
greenBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11387
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11388
     return the green bits of a pixelValue as integer 0..maxGreenValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11389
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11390
     of green bits i.e. (1 bitShift:bitsGreen)-1.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11391
     This has to be redefined by subclasses."
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11392
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11393
    |blueBits greenBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11394
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11395
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11396
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11397
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11398
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11399
	^ (pixel bitShift:blueBits negated) bitAnd:(1 bitShift:greenBits)-1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11400
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11401
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11402
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11403
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11404
    "Created: 8.6.1996 / 09:44:37 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11405
    "Modified: 10.6.1996 / 14:59:35 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11406
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11407
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11408
greenComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11409
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11410
     return the green component scaled to a percentage (0..100) of a pixelValue.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11411
     This has to be redefined by subclasses."
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11412
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11413
    |greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11414
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11415
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11416
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11417
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11418
	"/ assume that the red bits are the leftMost bits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11419
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11420
	greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11421
	greenBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11422
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11423
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11424
	s := (1 bitShift:greenBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11425
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11426
	^ 100.0 / s * ((pixel bitShift:blueBits negated) bitAnd:(1 bitShift:greenBits)-1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11427
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11428
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11429
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11430
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11431
    "Created: 8.6.1996 / 08:45:34 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11432
    "Modified: 10.6.1996 / 14:55:24 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11433
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11434
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11435
greenMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11436
    "return the mask used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11437
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11438
    |greenBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11439
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11440
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11441
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11442
	^ (1 bitShift:greenBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11443
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11444
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11445
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11446
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11447
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11448
greenShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11449
    "return the shift amount used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11450
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11451
    |greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11452
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11453
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11454
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11455
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11456
	^ (blueBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11457
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11458
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11459
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11460
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11461
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11462
heightOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11463
    "return my height, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11464
     since my height is independent of the device (the number of pixels),
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11465
     return the pixel-height"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11466
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11467
    ^ height
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11468
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11469
    "Created: 12.5.1996 / 21:35:06 / cg"
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11470
    "Modified: 13.5.1996 / 10:26:36 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11471
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11472
3700
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11473
isDithered
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11474
    "for compatibility with color protocol"
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11475
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11476
    ^ false
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11477
!
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11478
3507
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11479
isGrayscaleImage
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11480
    ^ (photometric ~= #palette)
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11481
      and:[photometric ~= #rgb]
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11482
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11483
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11484
    "Created: 22.4.1997 / 14:12:02 / cg"
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11485
!
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11486
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11487
isImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11488
    "return true, if the receiver is some kind of image;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11489
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11490
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11491
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11492
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11493
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11494
isImageOrForm
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11495
    "return true, if the receiver is some kind of image or form;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11496
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11497
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11498
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11499
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11500
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11501
isMask
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11502
    ^ false
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11503
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11504
    "Created: 22.4.1997 / 14:12:02 / cg"
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11505
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11506
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11507
magentaComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11508
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11509
     return the magenta component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11510
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11511
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11512
	"/ assume that the cyan bits are the leftMost bits (cmy)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11513
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11514
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11515
	    ^ 100.0 / 255 * ((pixel bitShift:-8) bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11516
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11517
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11518
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11519
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11520
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11521
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11522
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11523
magentaComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11524
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11525
     return the magenta component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11526
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11527
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11528
	"/ assume that the cyan bits are the leftMost bits (cmyk)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11529
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11530
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11531
	    ^ 100.0 / 255 * ((pixel bitShift:-16) bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11532
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11533
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11534
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11535
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11536
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11537
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11538
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11539
pixelArraySpecies
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11540
    "return the kind of pixel-value container in rowAt:/rowAt:put: methods"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11541
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 11542
    self depth > 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11543
	^ Array
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11544
    ].
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11545
    ^ ByteArray
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11546
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11547
    "Created: 6.3.1997 / 15:24:05 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 11548
    "Modified: 24.4.1997 / 15:34:34 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11549
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11550
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11551
realColorMap
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11552
    "return a collection usable as a real colormap of the image.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11553
     For palette images, this is the internal colormap; 
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11554
     for other photometrics (which do not have a real colormap), synthesize one.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11555
     This is different from #colorMap, which returns nil for non palette images."
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11556
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11557
    |d nEntries "{ Class: SmallInteger }"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11558
     colorArray|
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11559
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11560
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11561
	^ colorMap asArray
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11562
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11563
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11564
    d := self depth.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11565
    d > 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11566
	self error:'deep palette images not supported'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11567
	^ nil.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11568
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11569
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11570
    nEntries := 1 bitShift:d.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11571
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11572
    colorArray := Array new:nEntries.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11573
    1 to:nEntries do:[:idx |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11574
	colorArray at:idx put:(self colorFromValue:(idx-1)).
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11575
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11576
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11577
    ^ colorArray
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11578
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11579
    "Created: 11.7.1996 / 20:20:35 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11580
    "Modified: 11.7.1996 / 20:49:21 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11581
!
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11582
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11583
realUsedColors
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11584
    "return a collection of colors which are really used in the receiver."
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11585
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11586
    |values|
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11587
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11588
    values := self realUsedValues asArray.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11589
    ^ values collect:[:pixel | self colorFromValue:pixel]
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11590
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11591
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11592
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11593
realUsedValues
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11594
    "return a collection of color values used in the receiver.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11595
     Notice, that the interpretation of the pixels depends on the photometric
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11596
     of the image.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11597
     This is a general and therefore slow implementation; subclasses
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11598
     may want to redefine this method for more performance."
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11599
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11600
    |set last|
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11601
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11602
    set := IdentitySet new.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11603
    self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11604
	pixel ~~ last ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11605
	    set add:pixel.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11606
	    last := pixel.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11607
	]
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11608
    ].
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11609
    ^ set
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11610
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11611
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11612
     (Image fromFile:'goodies/bitmaps/garfield.gif') usedValues
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11613
     (Image fromFile:'goodies/bitmaps/SBrowser.xbm') usedValues
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11614
     (Image fromFile:'ttt.tiff') usedValues  
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11615
    "
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11616
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11617
    "Modified: / 29.7.1998 / 21:29:44 / cg"
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11618
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11619
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11620
redBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11621
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11622
     return the red component of a pixelValue as integer 0..maxRedValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11623
     MaxRedValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11624
     of red bits i.e. (1 bitShift:bitsRed)-1.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11625
     This has to be redefined by subclasses."
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11626
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11627
    |redBits greenBits blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11628
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11629
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11630
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11631
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11632
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11633
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11634
	^ (pixel bitShift:(greenBits + blueBits) negated)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11635
	   bitAnd:(1 bitShift:redBits)-1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11636
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11637
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11638
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11639
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11640
    "Created: 8.6.1996 / 09:44:51 / cg"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11641
    "Modified: 10.6.1996 / 14:59:05 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11642
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11643
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11644
redComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11645
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11646
     return the red component scaled to a percentage (0..100) of a pixelValue.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11647
     This has to be redefined by subclasses."
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11648
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11649
    |redBits   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11650
     greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11651
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11652
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11653
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11654
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11655
	"/ assume that the red bits are the leftMost bits
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11656
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11657
	redBits := bitsPerSample at:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11658
	redBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11659
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11660
	greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11661
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11662
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11663
	s := (1 bitShift:redBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11664
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11665
	^ 100.0 / s * 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11666
	  ((pixel bitShift:(greenBits + blueBits) negated)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11667
	   bitAnd:(1 bitShift:redBits)-1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11668
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11669
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11670
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11671
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11672
    "Created: 8.6.1996 / 08:45:30 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11673
    "Modified: 14.6.1996 / 17:34:00 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11674
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11675
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11676
redMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11677
    "return the mask used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11678
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11679
    |redBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11680
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11681
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11682
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11683
	^ (1 bitShift:redBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11684
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11685
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11686
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11687
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11688
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11689
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11690
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11691
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11692
redShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11693
    "return the shift amount used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11694
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11695
    |greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11696
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11697
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11698
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11699
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11700
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11701
	^ (greenBits + blueBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11702
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11703
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11704
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11705
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11706
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11707
usedColors
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11708
    "return a collection of colors used in the receiver."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11709
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11710
    |colors|
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11711
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11712
    colors := self usedColorsMax:4096.
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11713
    colors isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11714
	self error:'too many colors in image'.
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11715
    ].
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11716
    ^ colors
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11717
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11718
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11719
     (Image fromFile:'goodies/bitmaps/garfield.gif') usedColors
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11720
     (Image fromFile:'goodies/bitmaps/SBrowser.xbm') usedColors
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11721
     (Image fromFile:'ttt.tiff') usedColors  
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11722
    "
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11723
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11724
    "Modified: / 7.9.1998 / 17:56:12 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11725
!
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11726
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11727
usedColorsMax:nMax
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11728
    "return a collection of colors used in the receiver;
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11729
     however, stop if more than nMax colors have been found
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11730
     (useful when searching rgb images)."
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11731
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 11732
    |usedValues max colors|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11733
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11734
    photometric == #rgb ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11735
	usedValues := IdentitySet new.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11736
	self valuesFromX:0 y:0 toX:(width-1) y:(height-1)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11737
	  do:[:x :y :pixel |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11738
	    usedValues add:pixel.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11739
	    usedValues size > nMax ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11740
		"/ too many to be returned here (think of the mass of
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11741
		"/ data to be returned by a 24bit image ... ;-)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11742
		^ nil
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11743
	    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11744
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11745
	"/ code below is slightly faster ...
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11746
	"/ colors := usedValues collect:[:pixel | self colorFromValue:pixel].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11747
	colors := usedValues collect:[:pixel | |r g b|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11748
					r := self redBitsOf:pixel.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11749
					g := self greenBitsOf:pixel.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11750
					b := self blueBitsOf:pixel.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11751
					"/ must scale to byte value...
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11752
					r := r bitShift:(8 - (bitsPerSample at:1)).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11753
					g := g bitShift:(8 - (bitsPerSample at:2)).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11754
					b := b bitShift:(8 - (bitsPerSample at:3)).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11755
					Color redByte:r greenByte:g blueByte:b
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11756
				     ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11757
	^ colors.                
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11758
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11759
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11760
    usedValues := self usedValues asArray.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11761
    photometric == #palette ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11762
	colors := usedValues collect:[:val | (colorMap at:val+1 ifAbsent:[Color black])].
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 11763
    ] ifFalse:[
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 11764
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11765
	"/ (photometric == #blackIs0 or:[photometric == #whiteIs0])
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11766
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11767
	max := (1 bitShift:self depth) - 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11768
	colors :=  usedValues collect:[:val | (Color gray:(100 * val / max ))].
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 11769
    ].
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 11770
    ^ colors asSet
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11771
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11772
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11773
     (Image fromFile:'goodies/bitmaps/garfield.gif') usedColors
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11774
     (Image fromFile:'goodies/bitmaps/SBrowser.xbm') usedColors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11775
     (Image fromFile:'ttt.tiff') usedColors  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11776
    "
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
 11777
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11778
    "Created: / 7.9.1998 / 17:54:17 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 11779
    "Modified: / 7.9.1998 / 17:56:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11780
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11781
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11782
usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11783
    "return a collection of color values used in the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11784
     Notice, that the interpretation of the pixels depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11785
     of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11786
     This is a general and therefore slow implementation; subclasses
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11787
     may want to redefine this method for more performance."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11788
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11789
    ^ self realUsedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11790
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11791
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11792
     (Image fromFile:'goodies/bitmaps/garfield.gif') usedValues
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11793
     (Image fromFile:'goodies/bitmaps/SBrowser.xbm') usedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11794
     (Image fromFile:'ttt.tiff') usedValues  
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11795
    "
2206
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 11796
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 11797
    "Modified: / 29.7.1998 / 21:29:44 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11798
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11799
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11800
valueFromColor:color
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11801
    "given a color, return the corresponding pixel value.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11802
     Non-representable colors return nil."
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11803
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11804
    |pixel maxPixel redBits greenBits blueBits r g b|
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11805
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11806
    photometric == #whiteIs0 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11807
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11808
	^ maxPixel - (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11809
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11810
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11811
    photometric == #blackIs0 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11812
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11813
	^ (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11814
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11815
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11816
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11817
	pixel := colorMap indexOf:color.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11818
	pixel == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11819
	    "
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11820
	     the color is not in the images colormap
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11821
	    "
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11822
	    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11823
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11824
	^ pixel - 1
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11825
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11826
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11827
    photometric == #rgb ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11828
	samplesPerPixel >= 3 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11829
	    redBits := bitsPerSample at:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11830
	    greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11831
	    blueBits := bitsPerSample at:3.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11832
        
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11833
	    "/ map r/g/b to 0..255
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11834
	    r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11835
	    g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11836
	    b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11837
	    pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11838
	    ^ pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11839
	]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11840
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11841
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 11842
    ImageErrorSignal raiseErrorString:'format not supported'.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11843
    ^ nil
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11844
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 11845
    "Modified: / 30.9.1998 / 22:03:50 / cg"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11846
!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 11847
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11848
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11849
    "given a rgb bits, each in 0..maxXXXValue (i.e. according to
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11850
     r/g/b channels number of bits, return the corresponding pixel value.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11851
     For now, only useful with RGB images"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11852
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11853
    |pixel numGreenBits numBlueBits|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11854
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11855
    photometric == #rgb ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11856
	samplesPerPixel >= 3 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11857
	    numGreenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11858
	    numBlueBits := bitsPerSample at:3.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11859
        
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11860
	    pixel := (((redBits bitShift:numGreenBits) + greenBits) bitShift:numBlueBits) + blueBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11861
	    ^ pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11862
	]
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11863
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11864
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11865
    ImageErrorSignal raiseErrorString:'format not supported'.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11866
    ^ nil
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11867
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11868
    "Modified: / 30.9.1998 / 22:03:50 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11869
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11870
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11871
widthOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11872
    "return my width, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11873
     since my width is independent of the device (the number of pixels),
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11874
     return the pixel-width"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11875
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11876
    ^ width
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11877
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11878
    "Created: 12.5.1996 / 21:34:59 / cg"
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11879
    "Modified: 13.5.1996 / 10:26:42 / cg"
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11880
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11881
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11882
yellowComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11883
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11884
     return the yellow component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11885
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11886
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11887
	"/ assume that the cyan bits are the leftMost bits (cmy)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11888
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11889
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11890
	    ^ 100.0 / 255 * (pixel bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11891
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11892
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11893
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11894
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11895
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11896
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11897
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11898
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11899
yellowComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11900
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11901
     return the yellow component scaled to a percentage (0 .. 100) of a pixelValue."
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11902
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11903
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11904
	"/ assume that the cyan bits are the leftMost bits (cmyk)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11905
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11906
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11907
	    ^ 100.0 / 255 * ((pixel bitShift:-8) bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11908
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11909
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11910
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11911
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11912
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11913
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11914
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11915
!Image methodsFor:'saving on file'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11916
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11917
saveOn:aFileName
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11918
    "save the image in a aFileName. The suffix of the filename
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11919
     controls the format. Currently, not all formats may be supported
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 11920
     (see ImageReader subclasses implementing save:onFile:).
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 11921
     May raise a signal, if the image cannot be written by the
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 11922
     reader."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11923
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11924
    |suffix readerClass|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11925
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11926
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11927
    "/ from the extension, get the imageReader class
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11928
    "/ (which should know how to write images as well)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11929
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11930
    suffix := aFileName asFilename suffix.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 11931
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11932
    readerClass notNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11933
	^ self saveOn:aFileName using:readerClass
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11934
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11935
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11936
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11937
    "/ no known extension - could ask user for the format here.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11938
    "/ currently default to tiff format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11939
    "/
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 11940
    'Image [warning]: unknown extension - cannot figure out format - using tiff' errorPrintCR.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11941
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11942
    ^ self saveOn:aFileName using:TIFFReader
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 11943
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 11944
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 11945
     |image|
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 11946
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11947
     image := Image fromFile:'goodies/bitmaps/RCube.tiff'.
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 11948
     image saveOn:'myImage.tiff'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 11949
     image saveOn:'myImage.xbm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 11950
     image saveOn:'myImage.xpm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 11951
     image saveOn:'myImage.xwd'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 11952
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 11953
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 11954
    "Modified: 30.6.1997 / 22:06:34 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11955
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11956
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11957
saveOn:aFileName using:readerClass
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11958
    "save the receiver using the representation class 
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11959
     (which is usually a concrete subclasses of ImageReader).
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 11960
     May raise a signal, if the image cannot be written by the
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 11961
     reader."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11962
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 11963
    ^ readerClass save:self onFile:aFileName
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11964
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11965
    "
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 11966
     |anImage|
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 11967
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11968
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 11969
     anImage saveOn:'myImage.tiff' using:TIFFReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11970
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11971
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11972
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11973
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11974
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11975
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 11976
     anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11977
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11978
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11979
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11980
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11981
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11982
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11983
     Image cannotRepresentImageSignal handle:[:ex |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11984
	self warn:'cannot save the image in this format'
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11985
     ] do:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11986
	anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11987
     ]
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11988
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11989
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11990
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11991
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11992
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11993
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 11994
     anImage saveOn:'myImage.xpm' using:XPMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11995
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11996
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11997
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11998
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 11999
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12000
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12001
     anImage saveOn:'myImage.gif' using:GIFReader.
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12002
    "
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12003
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12004
    "Modified: 10.4.1997 / 17:49:26 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 12005
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12006
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12007
!Image methodsFor:'screen capture'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12008
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12009
from:aDrawable in:aRectangle
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12010
    "read an image from aDrawable.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12011
     This may be a device Form, a view or the rootView.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12012
     If its a view or rootView, it must be completely visible (or have
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12013
     the backingStore option turned on). Otherwise, only the clipped contents
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12014
     is returned. This is a common helper for form-to-image conversion,
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12015
     and to read hardcopy images from the screen."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12016
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12017
    | visType 
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12018
     x        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12019
     y        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12020
     w        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12021
     h        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12022
     dstIndex "{ Class: SmallInteger }" 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12023
     srcIndex "{ Class: SmallInteger }" 
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12024
     srcRow   "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12025
     dstRow   "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12026
     inData tmpData usedPixels mapSize 
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12027
     map bytesPerLine 
2534
35d91dcc4604 removed unused local
Claus Gittinger <cg@exept.de>
parents: 2533
diff changeset
 12028
     bitOrder spaceBitsPerPixel
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12029
     info bitsPerPixelIn bytesPerLineIn 
3561
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12030
     bitsR "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12031
     bitsG "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12032
     bitsB "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12033
     maskR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12034
     maskG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12035
     maskB "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12036
     shR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12037
     shG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12038
     shB "{ Class: SmallInteger }"
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 12039
     shR2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 12040
     shG2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 12041
     shB2 "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12042
     r "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12043
     g "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12044
     b "{ Class: SmallInteger }"
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12045
     word "{ Class: SmallInteger }"
2054
3d1619286006 fixed readout from 32bit servers
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
 12046
     lword 
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12047
     device ddepth isMSB|
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12048
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12049
    depth := self depth.
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12050
    bitsPerPixel := self bitsPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12051
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
 12052
    device := aDrawable graphicsDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12053
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12054
    (aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12055
	"/ a monochrome bitmap ?
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12056
	visType := #StaticGray.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12057
	ddepth := 1.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12058
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12059
	"
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12060
	 get some attributes of the display device
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12061
	"
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12062
	visType := device visualType.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12063
	ddepth := device depth.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12064
    ].
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12065
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12066
    "/ kludge for 15bit XFree server
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12067
    ddepth == 15 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12068
	ddepth := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12069
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12070
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12071
    (visType == #StaticGray) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12072
	(device blackpixel == 0) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12073
	    photometric := #blackIs0
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12074
	] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12075
	    photometric := #whiteIs0
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12076
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12077
	samplesPerPixel := 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12078
	bitsPerPixel := ddepth.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12079
	bitsPerSample := Array with:bitsPerPixel.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12080
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12081
	((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12082
	    photometric := #palette.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12083
	    samplesPerPixel := 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12084
	    bitsPerPixel := ddepth.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12085
	    bitsPerSample := Array with:bitsPerPixel.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12086
	] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12087
	    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12088
		photometric := #rgb.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12089
		samplesPerPixel := 3.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 12090
"/                bitsPerPixel := depth.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12091
"/                bitsPerSample := Array with:device bitsRed
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12092
"/                                       with:device bitsGreen
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12093
"/                                       with:device bitsBlue
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12094
		bitsPerPixel := 24.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12095
		bitsPerSample := #(8 8 8).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12096
	    ] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12097
		self error:'screen visual not supported'.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12098
		^ nil
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12099
	    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12100
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12101
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12102
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12103
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12104
     dont know yet, how the display pads; assume worst case, 
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12105
     offering enough space for 32 bit padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12106
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12107
    w := width := aRectangle width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12108
    h := height := aRectangle height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12109
    x := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12110
    y := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12111
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12112
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12113
     a kludge: we dont know in advance how much we are going to need
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12114
     (its too late when info is present ...)
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12115
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12116
    spaceBitsPerPixel := bitsPerPixel.
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12117
    (bitsPerPixel > 8) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12118
	spaceBitsPerPixel := 16.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12119
	(bitsPerPixel > 16) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12120
	    spaceBitsPerPixel := 32.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12121
	    (bitsPerPixel > 32) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12122
		spaceBitsPerPixel := bitsPerPixel.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12123
	    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12124
	]
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12125
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12126
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12127
    bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4.
3561
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12128
    "/ inData := ByteArray uninitializedNew:(bytesPerLine * height).
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12129
    inData := ByteArray new:(bytesPerLine * height).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12130
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12131
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12132
     get the pixels
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12133
    "
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 12134
    aDrawable isForm ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12135
	info := device getBitsFromPixmapId:aDrawable id x:x y:y width:w height:h into:inData. 
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 12136
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12137
	info := device getBitsFromViewId:aDrawable id x:x y:y width:w height:h into:inData. 
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 12138
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12139
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12140
    bitsPerPixelIn := info at:#bitsPerPixel.
2533
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 12141
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 12142
    isMSB := ((info at:#byteOrder) == #msbFirst).
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 12143
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12144
    "
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12145
     Note: bit- and byte ordering doesn't matter for palette images!!
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12146
    "
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12147
    photometric ~~ #palette ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12148
	"/
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12149
	"/ check if byteorder is what I like (msbFirst)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12150
	"/
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12151
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12152
	"/ now done on-the-fly (see isMSB arg)
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12153
2534
35d91dcc4604 removed unused local
Claus Gittinger <cg@exept.de>
parents: 2533
diff changeset
 12154
"/        (info at:#byteOrder) ~~ #msbFirst ifTrue:[
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12155
"/            bitsPerPixelIn == 16 ifTrue:[
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12156
"/                "/ must swap bytes
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12157
"/                inData swapBytes
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12158
"/            ] ifFalse:[
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12159
"/                bitsPerPixelIn == 32 ifTrue:[
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12160
"/                    "/ must swap longs
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12161
"/                    inData swapLongs
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12162
"/                ]
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12163
"/            ]
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12164
"/        ].
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12165
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12166
	"/
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12167
	"/ check if bitorder is what I like (msbFirst)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12168
	"/
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12169
	"/ mhmh - thats not needed
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12170
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12171
"/        bitOrder := info at:#bitOrder.
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12172
"/        bitOrder ~~ #msbFirst ifTrue:[
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12173
"/            inData 
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12174
"/                expandPixels:8 
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12175
"/                width:(inData size)
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12176
"/                height:1 
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12177
"/                into:inData
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12178
"/                mapping:(ImageReader reverseBits).
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12179
"/        ].
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 12180
    ].
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 12181
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12182
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12183
    "/ check if bitorder is what I like (msbFirst)
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12184
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12185
    "/ mhmh - thats not needed
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12186
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12187
    bitsPerPixelIn < 8 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12188
	bitOrder := info at:#bitOrder.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12189
	bitOrder ~~ #msbFirst ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12190
	    inData 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12191
		expandPixels:8 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12192
		width:(inData size)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12193
		height:1 
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12194
		into:inData
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12195
		mapping:(ImageReader reverseBits "TODO: reverseBitsForDepth:bitsPerPixelIn").
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12196
	].
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12197
    ].
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12198
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 12199
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12200
     check, if the devices padding is different ..
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12201
     or if the bitsPerPixels are different
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12202
    "
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12203
    bytesPerLineIn := (info at:#bytesPerLine).                    "what I got"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12204
    bytesPerLine := (w * bitsPerPixel + 7) // 8.                  "what I want"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12205
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12206
    maskR := info at:#redMask ifAbsent:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12207
    maskG := info at:#greenMask ifAbsent:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12208
    maskB := info at:#blueMask ifAbsent:0.
3561
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12209
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12210
    ((bytesPerLine ~~ bytesPerLineIn) 
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12211
    or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12212
	tmpData := inData.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12213
	inData := ByteArray uninitializedNew:(bytesPerLine * height).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12214
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12215
	srcRow := 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12216
	dstRow := 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12217
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12218
	bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12219
	    "/ for now, only 32 -> 24 is supported
3561
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12220
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12221
                
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12222
	    maskR == 0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12223
		bitsR := device bitsRed.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12224
		bitsG := device bitsGreen.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12225
		bitsB := device bitsBlue.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12226
		maskR := (1 bitShift:bitsR) - 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12227
		maskG := (1 bitShift:bitsG) - 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12228
		maskB := (1 bitShift:bitsB) - 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12229
		shR := device shiftRed negated.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12230
		shG := device shiftGreen negated.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12231
		shB := device shiftBlue negated.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12232
	    ] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12233
		shR := (maskR lowBit - 1) negated.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12234
		bitsR := maskR highBit - maskR lowBit + 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12235
		maskR := maskR bitShift:shR.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12236
		shG := (maskG lowBit - 1) negated.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12237
		bitsG := maskG highBit - maskG lowBit + 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12238
		maskG := maskG bitShift:shG.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12239
		shB := (maskB lowBit - 1) negated.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12240
		bitsB := maskB highBit - maskB lowBit + 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12241
		maskB := maskB bitShift:shB.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12242
	    ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12243
	    shR2 := (8 - bitsR).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12244
	    shG2 := (8 - bitsG).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12245
	    shB2 := (8 - bitsB).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12246
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12247
	    ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12248
		"/ 'reformatting 32->24...' printNL.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12249
		1 to:h do:[:hi |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12250
		    srcIndex := srcRow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12251
		    dstIndex := dstRow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12252
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12253
		    1 to:w do:[:wi |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12254
			lword := tmpData doubleWordAt:srcIndex MSB:isMSB.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12255
			r := (lword bitShift:shR) bitAnd:maskR.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12256
			g := (lword bitShift:shG) bitAnd:maskG.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12257
			b := (lword bitShift:shB) bitAnd:maskB.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12258
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12259
			inData at:dstIndex   put:r.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12260
			inData at:dstIndex+1 put:g.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12261
			inData at:dstIndex+2 put:b.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12262
			srcIndex := srcIndex + 4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12263
			dstIndex := dstIndex + 3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12264
		    ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12265
		    dstRow := dstRow + bytesPerLine.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12266
		    srcRow := srcRow + bytesPerLineIn
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12267
		]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12268
	    ] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12269
		((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12270
		    "/ 'reformatting 16->24...' printNL.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12271
		    1 to:h do:[:hi |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12272
			srcIndex := srcRow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12273
			dstIndex := dstRow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12274
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12275
			1 to:w do:[:wi |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12276
			    word := tmpData wordAt:srcIndex MSB:isMSB.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12277
			    r := (word bitShift:shR) bitAnd:maskR.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12278
			    g := (word bitShift:shG) bitAnd:maskG.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12279
			    b := (word bitShift:shB) bitAnd:maskB.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12280
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12281
			    inData at:dstIndex   put:(r bitShift:shR2).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12282
			    inData at:dstIndex+1 put:(g bitShift:shG2).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12283
			    inData at:dstIndex+2 put:(b bitShift:shB2).
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12284
"/ word print.
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12285
"/ ' -> ' print.
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12286
"/ (r bitShift:shR2) print.
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12287
"/ ' ' print. (g bitShift:shG2) print.
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12288
"/ ' ' print. (b bitShift:shB2) printCR.
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12289
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12290
			    srcIndex := srcIndex + 2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12291
			    dstIndex := dstIndex + 3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12292
			].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12293
			dstRow := dstRow + bytesPerLine.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12294
			srcRow := srcRow + bytesPerLineIn
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12295
		    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12296
		] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12297
		    ('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12298
							bitsPerPixel printString) errorPrintCR.
3561
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12299
self halt.
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12300
		    ^ nil
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12301
		]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12302
	    ].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12303
	] ifFalse:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12304
	    "
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12305
	     repad in the buffer
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12306
	    "
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12307
	    1 to:h do:[:hi |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12308
		inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12309
			      with:tmpData startingAt:srcRow.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12310
		dstRow := dstRow + bytesPerLine.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12311
		srcRow := srcRow + bytesPerLineIn
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12312
	    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12313
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12314
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12315
	(bytesPerLine * height) ~~ inData size ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12316
	    tmpData := inData.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12317
	    inData := ByteArray uninitializedNew:(bytesPerLine * height).
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12318
	    inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12319
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12320
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12321
    bytes := inData.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12322
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12323
    "info printNL."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12324
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12325
    "
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12326
      if not #palette we are done, the pixel values are the rgb/grey values
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12327
    "
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12328
    photometric == #palette ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12329
	"
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12330
	 what we have now are the color numbers - still need the r/g/b values.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12331
	 find out, which colors are in the picture
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12332
	"
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12333
	usedPixels := inData usedValues.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12334
	mapSize := usedPixels max + 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12335
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12336
	"get the palette"
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12337
	map := Array new:mapSize.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12338
	usedPixels do:[:colorIndex |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12339
	    |i|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12340
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12341
	    i := colorIndex + 1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12342
	    device getRGBFrom:colorIndex into:[:r :g :b |
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12343
		map at:i put:(Color red:r green:g blue:b)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12344
	    ]
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12345
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12346
	colorMap := map.
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 12347
    ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 12348
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12349
    "Modified: / 9.1.1998 / 21:32:36 / stefan"
2054
3d1619286006 fixed readout from 32bit servers
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
 12350
    "Modified: / 7.2.1998 / 18:23:07 / cg"
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12351
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12352
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12353
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12354
    "read an image from the display screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12355
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12356
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12357
	      (use #fromScreen:on:grab: with a false grabArg then)."
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12358
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12359
    ^ self 
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12360
	fromScreen:aRectangle 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12361
	on:Screen current
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12362
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12363
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12364
    "Modified: 26.3.1997 / 10:43:34 / cg"
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12365
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12366
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12367
fromScreen:aRectangle on:aDevice
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12368
    "read an image from aDevices display screen.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12369
     Since I have no other displays, only the MonoChrome, StaticGrey 
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12370
     and PseudoColor cases have been tested ... 
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12371
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12372
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12373
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12374
	      it may not work from within a buttonMotion
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12375
	      (use #fromScreen:on:grab: with a false grabArg then)."
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12376
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12377
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12378
	fromScreen:aRectangle 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12379
	on:aDevice 
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12380
	grab:true
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12381
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12382
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12383
     Image fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12384
     Image fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12385
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12386
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12387
    "Modified: 24.4.1997 / 18:25:13 / cg"
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12388
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12389
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12390
fromScreen:aRectangle on:aDevice grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12391
    "read an image from aDevices display screen.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12392
     If the doGrab argument is true, the display
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12393
     is grabbed (i.e. blocked for others) and a camera cursor is
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12394
     shown while the readout is done.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12395
     Since I have no other displays, only the MonoChrome, StaticGrey 
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12396
     and PseudoColor cases have been tested ... 
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12397
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12398
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12399
     WARNING: with doGrab true, this temporarily grabs the display
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12400
              and it may not work from within a buttonMotion
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12401
              (use with a false grabArg then)."
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12402
3092
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 12403
    |curs cid rootView prevGrab|
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12404
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12405
"/    doGrab ifTrue:[
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12406
"/        curs := Cursor sourceForm:(Image fromFile:'bitmaps/Camera.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12407
"/                         maskForm:(Image fromFile:'bitmaps/Camera_m.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12408
"/                          hotSpot:16@16.
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12409
"/        curs notNil ifTrue:[
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12410
"/            cid := (curs onDevice:aDevice) id
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12411
"/        ].
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12412
"/    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12413
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12414
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12415
     actually have to grabServer ... but thats not yet available
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12416
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12417
    rootView := aDevice rootView.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12418
    doGrab ifTrue:[
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12419
        prevGrab := aDevice activePointerGrab.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12420
        aDevice grabPointerInView:rootView withCursor:curs. 
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12421
    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12422
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12423
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12424
     get the pixels
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12425
    "
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12426
    [
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12427
        self from:rootView in:aRectangle.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12428
    ] ensure:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12429
        doGrab ifTrue:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12430
            aDevice ungrabPointer.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12431
            prevGrab notNil ifTrue:[
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12432
                 aDevice grabPointerInView:prevGrab.
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12433
            ]
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12434
        ]
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12435
    ]
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12436
3092
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 12437
    "
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 12438
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:false
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 12439
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:true
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 12440
    "
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12441
!
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12442
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12443
photometricFromScreen:aDevice
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12444
    "read aDevices display photometric and set my colormap for it.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12445
     This must be used after an images bits have been read from the screen
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12446
     or from an offScreen bitmap, for correct pixel interpretation."
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12447
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12448
    |depth visType bitsPerPixel|
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12449
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12450
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12451
     get some attributes of the display device
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12452
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12453
    visType := aDevice visualType.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12454
    depth := aDevice depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12455
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12456
    "/ kludge for 15bit XFree server
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12457
    depth == 15 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12458
	depth := 16
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12459
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12460
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12461
    (visType == #StaticGray) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12462
	(aDevice blackpixel == 0) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12463
	    photometric := #blackIs0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12464
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12465
	    photometric := #whiteIs0
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12466
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12467
	samplesPerPixel := 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12468
	bitsPerPixel := depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12469
	bitsPerSample := Array with:bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12470
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12471
	 were done, the pixel values are the grey values
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12472
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12473
	^ self
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12474
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12475
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12476
    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12477
	photometric := #rgb.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12478
	samplesPerPixel := 3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12479
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12480
	"/ for now - only support 24bit TrueColor
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12481
	depth ~~ 24 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12482
	    'IMAGE: unsupported display depth' errorPrintCR.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12483
	].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12484
"/                bitsPerPixel := depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12485
"/                bitsPerSample := Array with:aDevice bitsRed
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12486
"/                                       with:aDevice bitsGreen
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12487
"/                                       with:aDevice bitsBlue
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12488
	bitsPerPixel := 24.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12489
	bitsPerSample := #(8 8 8).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12490
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12491
	 were done, the pixel values are the rgb values
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12492
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12493
	^ self
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12494
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12495
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12496
    ((visType ~~ #PseudoColor) 
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12497
    and:[(visType ~~ #StaticColor) 
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12498
    and:[visType ~~ #GrayScale]]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12499
	self error:'screen visual not supported'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12500
	^ nil
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12501
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12502
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12503
    photometric := #palette.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12504
    samplesPerPixel := 1.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12505
    bitsPerPixel := depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12506
    bitsPerSample := Array with:bitsPerPixel.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12507
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12508
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12509
     still need the pixels r/g/b values ...
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12510
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12511
    colorMap := aDevice colorMap
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12512
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12513
    "Modified: 11.7.1996 / 11:11:34 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12514
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12515
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
 12516
!Image class methodsFor:'documentation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12517
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12518
version
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 12519
    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.323 2002-11-02 14:59:00 cg Exp $'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
 12520
! !
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 12521
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12522
Image initialize!