Image.st
author Claus Gittinger <cg@exept.de>
Mon, 04 Feb 2008 13:26:25 +0100
changeset 4893 137719991c5a
parent 4888 7d2d5ef445e3
child 4937 1b0ebaed9336
permissions -rw-r--r--
defaultPhotometric in #fromImage:photometric:
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
"
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
    12
"{ Package: 'stx:libview' }"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
    13
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    14
Object subclass:#Image
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
    15
	instanceVariableNames:'pixelStore bytes width height bitsPerPixel depth colorMap
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
    16
		maxPixelValue rowByteSize bitsPerSample samplesPerPixel
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
    17
		photometric device deviceForm monoDeviceForm fullColorDeviceForm
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
    18
		mask maskedPixelsAre0 fileName imageSequence'
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    19
	classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    20
		CollectGarbageWhenRunningOutOfColors ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    21
		ImageNotFoundQuerySignal BadImageFormatQuerySignal
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
    22
		ImageSaveErrorSignal ImageLoadErrorSignal FileCreationErrorSignal
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    23
		CannotRepresentImageSignal InformationLostQuerySignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    24
		UnrepresentableColorSignal'
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    25
	poolDictionaries:''
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    26
	category:'Graphics-Images'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    27
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    28
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
    29
!Image class methodsFor:'documentation'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    30
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    31
copyright
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    32
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    33
 COPYRIGHT (c) 1991 by Claus Gittinger
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
    34
	      All Rights Reserved
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    35
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    36
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    37
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    38
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    39
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    40
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    41
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    42
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    43
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    44
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    45
documentation
48194c26a46c Initial revision
claus
parents:
diff changeset
    46
"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    47
    this class provides (some time in the future) representation
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    48
    for all kinds of images (monochrome, greyscale and color)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    49
    and will finally replace Form.
622
565e2301c064 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    50
    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
    51
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    52
    An Image keeps all of its information in a device independent way,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    53
    but may be associated to a device.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    54
    The data held keeps all information which was originally present,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    55
    even if the display-device has lower resolution.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    56
    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
    57
    color information.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    58
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    59
    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
    60
    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
    61
    This gives a device independent image.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    62
    For display, a device representation is required, which can be
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    63
    aquired by sending the
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    64
	'onDevice:aDevice'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    65
    message to the image. This will create a (possibly dithered) device-form,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    66
    representing the image using the currently available colors.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    67
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    68
    In rare cases, an explicit monochrome representation of the image is needed
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    69
    (X servers take monochrome icons only), this can be created by sending
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    70
    it the message
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
    71
	'monochromeOn:aDevice'.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    72
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    73
    Also, it is planned to generate another hi-color resolution version,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    74
    which uses its own colormap and allows the use of all 256 colors on an 8bit display
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    75
    (this is not currently implemented).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    76
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    77
    An images pixel interpretation is controlled by the photometric instance variable
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    78
    and (if that is #palette) a colorMap.
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    79
    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
    80
    (and using specialized colorMaps for b&w / greyScale images).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    81
    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
    82
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    83
    To convert pictures from/to external file-formats, image readers are used
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    84
    which have the file-format knowledge built in.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    85
    There are readers for most common formats available
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    86
    (see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    87
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    88
    File formats are handled by subclasses of ImageReader, which understand
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    89
    a specific format. You can add more readers, by adding an association
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    90
    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
    91
    (see the classes #initialize method, which sets up some default, and the
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    92
    patches/display.rc files, which add more).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    93
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    94
    Some algorithms used here (especially dithering & color allocation) are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    95
    experimental and far from being perfect (some are very slow).
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    96
    For now, the most common cases have been optimized and perform reasonably
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    97
    fast - however, with uncommon depth/visualType combinations, you may
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    98
    run into slower fallback methods ...
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    99
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   100
    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
   101
    (may) be done in the future if there is a demand for it ...
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   102
    Dithering can be controlled by the DitherAlgorithm classVariable:
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   103
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   104
       DitherAlgorithm:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   105
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   106
       nil                  a simple threshold algorithm
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   107
			    (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   108
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   109
       #pattern             patterned dither
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   110
			    (for p, take dithered color to fill pixel;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   111
			     uses dithering in color-class)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   112
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   113
       #error               error diffusion dither (Floyd-Steinberg)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   114
			    planned - not yet implemented.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   115
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
    [instance variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   119
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   120
	width               <Integer>       the width in pixels
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   121
	height              <Integer>       the height in pixels
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   122
	bytes               <ByteArray>     the full image information
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   123
	photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   124
	samplesPerPixel     <Integer>       the number of planes
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   125
	bitsPerSample       <Array>         the number of bits per plane
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   126
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   127
	colorMap            <Array>         only if photometric is #palette;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   128
					    maps pixel values to r/g/b values.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   129
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   130
	device              <Workstation>   the device on which deviceForm,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   131
					    monoDeviceForm and lowResDeviceForm are
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   132
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   133
	deviceForm          <Form>          the device form which gives the best
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   134
					    possible aproximation of the image on
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   135
					    device using standard colors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   136
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   137
	monoDeviceForm      <Form>          the device form which gives a monochrome
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   138
					    aproximation of the image on device.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   139
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   140
	fullColorDeviceForm <Form>          the device form which gives the best
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   141
					    possible aproximation of the image on
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   142
					    device using private colors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   143
					    (not yet implemented)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   144
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   145
	mask                <ImageMask>     an optional mask;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   146
					    if non-nil, only pixels for which the
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   147
					    corresponding mask bit is non-zero
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   148
					    are drawn.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   149
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   150
	maskedPixelsAre0    <Boolean>       a hint for image processors and drawers
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   151
					    if true, masked pixels are known to be
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   152
					    zero in the pixel bytes.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   153
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   154
	fileName            <String>        the name of the file from which the
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   155
					    image was loaded - nil otherwise.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   156
					    Useful for image save functions
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   157
					    and for the UIPainter utility.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   158
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   159
	imageSequence                       the imageSequence, of which the
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   160
					    instance is a frame or nil,
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   161
					    if its not part of a sequence.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   162
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   163
	bitsPerPixel                        not used in ST/X
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   164
	depth                               - these have been added in instVar-slots
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   165
	maxPixelValue                       - according to the ST-80's image class.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   166
	rowByteSize                         - to allow loading of st-80 images
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   167
					    - (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
   168
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   169
    [class variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   170
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   171
	Lobby               <Registry>      keeps track of known images
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   172
					    (for resource freeing with garbage collector)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   173
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   174
	DitherAlgorithm     <Symbol>        defines how to dither
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   175
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   176
	NumberOfDitherColors <Integer>      defines, how many dither colors to use
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   177
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   178
	FileFormats         <Dictionary>    associates filename extensions to
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   179
					    image reader classes (now set-up in startup-file)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   180
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   181
	CollectGarbageWhenRunningOutOfColors
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   182
			    <Boolean>       if true, and we run out of available
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   183
					    device colors during creation of a
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   184
					    device image, collect garbage for
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   185
					    possible image reclamation.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   186
					    If false, proceed immediately.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   187
					    Default is true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   188
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   189
	ImageNotFoundQuerySignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   190
			    <QuerySignal>   raised, if an image could not be loaded
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   191
					    from a file. The parameter is the images
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   192
					    fileName.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   193
					    A handler may return a replacement
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   194
					    image or proceed with nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   195
					    If unhandled, a nil is returned from the
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   196
					    image creation.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   197
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   198
	BadImageFormatQuerySignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   199
			    <QuerySignal>   raised, if an image could not be loaded
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   200
					    from a file due to a file error or
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   201
					    unsupported format.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   202
					    A handler may return a replacement
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   203
					    image or proceed with nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   204
					    If unhandled, a nil is returned from the
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   205
					    image creation.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   206
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   207
	ImageSaveErrorSignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   208
			    <Signal>        parent of errors below.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   209
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   210
	FileCreationErrorSignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   211
			    <Signal>        file could not be created when saving an
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   212
					    image.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   213
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   214
	CannotRepresentImageSignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   215
			    <Signal>        the specified ImageReader cannot represent
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   216
					    the given image.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   217
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   218
	InformationLostQuerySignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   219
			    <Signal>        the specified ImageReader can represent
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   220
					    the given image, but some information
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   221
					    (typically color resolution) is lost.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   222
					    If unhandled, the save proceeds as usual.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   223
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   224
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   225
    caveat:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   226
	the information in
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   227
	    photometric, bitsPerPixel, bitsPerSample, samplesPerPixel, depth , colorMap and maxPixelValue
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   228
	is partially redundant and its handling stupid (not to say: braindamaged ;-).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   229
	The only excuse is that it grew over time, had to incorporate various alien/older schemes for
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   230
	compatibility reasons. All of the above belongs into the single colorMap which must migrate from
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   231
	a stupid seqColl to a color-aware real colorMap.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   232
	(we are in the process of doing so...)
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
   233
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   234
    todo:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   235
	support alpha masks
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   236
	cleanup the dithering & conversion code
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   237
	cleanup the color/photometric mess
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   238
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   239
    [See also:]
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   240
	Form Icon ImageReader
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   241
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   242
    [author:]
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   243
	Claus Gittinger
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   244
"
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   245
!
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   246
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   247
examples
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   248
"
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   249
    reading from a file (many formats are supported):
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   250
    (notice, that the bitmaps directory is searched for along
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   251
     the system path - therefore, you may add your own bitmap
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   252
     directory to the beginning of the path and thus override
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   253
     any default bitmaps, or make certain that your application
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   254
     finds its bitmaps - even if they are in a separate directory)
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   255
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   256
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   257
        (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   258
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   259
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   260
        (Image fromFile:'libtool/bitmaps/SmalltalkX.xbm') inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   261
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   262
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   263
        (Image fromFile:'goodies/bitmaps/winBitmaps/okSmily_up.bmp') inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   264
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   265
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   266
    The following examples demonstrate various depth
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   267
    and colorMap variations ...
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   268
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   269
    inline image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   270
      default: depth=1 & #blackIs0
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   271
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   272
        (Image width:8 height:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   273
               fromArray:#( 2r11111111
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   274
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   275
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   276
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   277
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   278
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   279
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   280
                            2r11111111 )) inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   281
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   282
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   283
      with #whiteIs0 photometric
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   284
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   285
        ((Image width:8 height:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   286
               fromArray:#( 2r11111111
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   287
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   288
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   289
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   290
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   291
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   292
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   293
                            2r11111111 ))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   294
            photometric:#whiteIs0)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   295
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   296
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   297
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   298
      with a colorMap
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   299
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   300
        ((Image width:8 height:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   301
               fromArray:#( 2r11111111
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   302
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   303
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   304
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   305
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   306
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   307
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   308
                            2r11111111 ))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   309
            colorMap:(Array with:(Color red)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   310
                            with:(Color yellow)))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   311
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   312
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   313
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   314
      a depth4 greyScale image:
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   315
      (default photometric is #blackIs0)
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   316
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   317
        (Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   318
             width:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   319
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   320
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   321
                            16r00 16r11 16r22 16r33
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   322
                            16r44 16r55 16r66 16r77
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   323
                            16r88 16r99 16raa 16rbb
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   324
                            16rcc 16rdd 16ree 16rff
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   325
                        ]) inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   326
                                                                        [exEnd]
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   327
      the same, magnified:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   328
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   329
        ((Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   330
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   331
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   332
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   333
                            16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   334
                            16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   335
                            16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   336
                            16rcd 16ref
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   337
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   338
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   339
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   340
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   341
      the following has the same effect:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   342
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   343
        ((Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   344
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   345
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   346
             depth:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   347
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   348
                            16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   349
                            16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   350
                            16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   351
                            16rcd 16ref
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   352
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   353
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   354
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   355
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   356
      with reverse grey-interpretation:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   357
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   358
        ((Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   359
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   360
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   361
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   362
                            16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   363
                            16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   364
                            16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   365
                            16rcd 16ref
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   366
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   367
            photometric:#whiteIs0;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   368
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   369
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   370
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   371
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   372
      with 1-bit-per-pixel rgb interpretation:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   373
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   374
        ((Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   375
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   376
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   377
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   378
                            16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   379
                            16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   380
                            16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   381
                            16rcd 16ref
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   382
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   383
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   384
            samplesPerPixel:3;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   385
            bitsPerSample:#(1 1 1);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   386
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   387
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   388
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   389
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   390
      with 1/2/1 rgb interpretation:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   391
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   392
        ((Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   393
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   394
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   395
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   396
                            16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   397
                            16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   398
                            16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   399
                            16rcd 16ref
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   400
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   401
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   402
            samplesPerPixel:3;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   403
            bitsPerSample:#(1 2 1);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   404
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   405
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   406
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   407
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   408
      a 2/2/0 rgb image (i.e. no blue):
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   409
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   410
         |i|
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   411
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   412
         i := Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   413
                    width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   414
                    height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   415
                    fromArray:#[ 16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   416
                                 16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   417
                                 16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   418
                                 16rcd 16ref ].
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   419
         i photometric:#rgb.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   420
         i samplesPerPixel:3.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   421
         i bitsPerSample:#(2 2 0).
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   422
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   423
         i := i magnifiedBy:30.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   424
         i inspect.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   425
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   426
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   427
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   428
      a 0/0/4 rgb image (i.e. no red or green):
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   429
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   430
         |i|
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   431
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   432
         i := Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   433
                    width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   434
                    height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   435
                    fromArray:#[ 16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   436
                                 16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   437
                                 16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   438
                                 16rcd 16ref ].
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   439
         i photometric:#rgb.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   440
         i samplesPerPixel:3.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   441
         i bitsPerSample:#(0 0 4).
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   442
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   443
         i := i magnifiedBy:30.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   444
         i inspect.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   445
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   446
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   447
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   448
      a 2plane greyscale image:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   449
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   450
        ((Depth2Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   451
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   452
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   453
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   454
                            4r0123
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   455
                            4r1230
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   456
                            4r2301
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   457
                            4r3012
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   458
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   459
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   460
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   461
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   462
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   463
      with colors:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   464
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   465
        ((Depth2Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   466
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   467
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   468
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   469
                            4r0123
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   470
                            4r1230
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   471
                            4r2301
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   472
                            4r3012
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   473
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   474
            colorMap:(Array with:(Color black)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   475
                            with:(Color red)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   476
                            with:(Color green)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   477
                            with:(Color blue));
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   478
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   479
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   480
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   481
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   482
      depth8 image with 3/3/2 rgb interpretation:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   483
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   484
        ((Depth8Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   485
             width:16
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   486
             height:16
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   487
             fromArray:(ByteArray withAll:(0 to:16rFF)))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   488
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   489
            samplesPerPixel:3;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   490
            bitsPerSample:#(3 3 2);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   491
            magnifiedBy:10)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   492
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   493
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   494
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   495
      depth8 image with 2/2/2 rgb interpretation:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   496
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   497
        ((Depth8Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   498
             width:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   499
             height:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   500
             fromArray:(ByteArray withAll:(0 to:16r3F)))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   501
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   502
            samplesPerPixel:3;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   503
            bitsPerSample:#(2 2 2);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   504
            magnifiedBy:10)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   505
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   506
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   507
2760
94d2d524081b example added (24-bit image)
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   508
      trueColor image:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   509
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   510
        ((Depth24Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   511
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   512
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   513
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   514
                    16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   515
                    16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   516
                    16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   517
                    16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   518
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   519
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   520
            samplesPerPixel:3;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   521
            bitsPerSample:#(8 8 8);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   522
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   523
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   524
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   525
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   526
      32bit trueColor image:
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   527
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   528
        ((Depth32Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   529
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   530
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   531
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   532
                    16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   533
                    16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   534
                    16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   535
                    16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   536
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   537
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   538
            samplesPerPixel:4;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   539
            bitsPerSample:#(8 8 8 8);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   540
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   541
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   542
                                                                        [exEnd]
2760
94d2d524081b example added (24-bit image)
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   543
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   544
    storing - only a few formats (TIFF, XBM, XPM) currently support storing:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   545
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   546
        |img|
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   547
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   548
        img := Image fromFile:'goodies/bitmaps/winBitmaps/okSmily_up.bmp'.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   549
        img saveOn:'myImage.tiff'.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   550
        (Image fromFile:'myImage.tiff') inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   551
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   552
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   553
    magnifying (any factor):
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   554
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   555
        ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   556
            magnifiedTo:(48@48))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   557
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   558
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   559
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   560
        ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   561
            magnifiedBy:0.7)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   562
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   563
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   564
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   565
    rotating:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   566
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   567
        ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   568
            rotated:90)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   569
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   570
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   571
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   572
        (((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   573
            magnifiedBy:0.3@0.7) rotated:270)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   574
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   575
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   576
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   577
        (((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   578
            ) rotated:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   579
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   580
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   581
    negative:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   582
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   583
        ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   584
            negative)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   585
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   586
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   587
"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   588
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   589
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   590
!Image class methodsFor:'initialization'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   591
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   592
addReader:aReaderClass suffix:aSuffix
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   593
    "register an additional image reader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   594
     This is provided for subclasses, to regster themself when
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   595
     loaded (or from the startup scripts)"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   596
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   597
    self obsoleteMethodWarning.
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   598
    self addReader:aReaderClass suffix:aSuffix mimeType:nil
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   599
!
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   600
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   601
addReader:aReaderClass suffix:aSuffix mimeType:mimeType
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   602
    "register an additional image reader.
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   603
     This interface is kept for backward compatibility.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   604
     The knowledge has been concentrated in MIMETypes"
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   605
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   606
    self obsoleteMethodWarning.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   607
    MIMETypes
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   608
	defineImageType:mimeType suffix:aSuffix reader:aReaderClass
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   609
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   610
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   611
     Image addReader:GIFReader suffix:'gif'
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   612
     Image addReader:GIFReader suffix:'gif' mimeType:'image/gif'
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   613
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   614
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   615
    "Modified: 30.6.1997 / 21:59:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   616
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   617
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   618
fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   619
    "return the collection of supported file formats.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   620
     The returned dictionary maps file-extensions to image reader classes."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   621
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   622
    ^ MIMETypes fileSuffixToImageReaderMapping
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   623
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   624
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   625
     Image fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   626
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   627
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   628
    "Modified: 30.6.1997 / 22:05:58 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   629
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   630
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   631
flushDeviceImages
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   632
    "simply release all deviceForms"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   633
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   634
    Lobby do:[:anImage |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   635
	anImage release
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   636
    ]
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   637
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   638
    "Modified: 15.6.1996 / 15:45:02 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   639
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   640
48194c26a46c Initial revision
claus
parents:
diff changeset
   641
initialize
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   642
    "initialize class constants"
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   643
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   644
    "setup tracker of known pictures"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   645
    Lobby isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   646
	Lobby := Registry new.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   647
	ObjectMemory addDependent:self.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   648
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   649
	"/ define the algorithm to use for dithering -
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   650
	"/ supported values are:
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   651
	"/      #threshold
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   652
	"/      #ordered
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   653
	"/      #floydSteinberg
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   654
	"/      #burkes
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   655
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   656
	DitherAlgorithm := #floydSteinberg.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   657
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   658
	(Display notNil and:[Display hasGrayscales]) ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   659
	    NumberOfDitherColors := 64
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   660
	] ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   661
	    "as far as I remember, this is about the number of grey values, the eye can distinguish"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   662
	    NumberOfDitherColors := 100
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   663
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   664
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   665
	"define reader classes"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   666
	self initializeFileFormatTable.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   667
	self initializeMIMETable.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   668
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   669
	CollectGarbageWhenRunningOutOfColors := false.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   670
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   671
	ImageErrorSignal := Error newSignalMayProceed:true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   672
	ImageErrorSignal nameClass:self message:#imageErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   673
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   674
	ImageSaveErrorSignal := ImageErrorSignal newSignalMayProceed:true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   675
	ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   676
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   677
	FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   678
	FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   679
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   680
	CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   681
	CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   682
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   683
	ImageLoadErrorSignal := QuerySignal new.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   684
	ImageLoadErrorSignal nameClass:self message:#imageLoadErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   685
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   686
	ImageNotFoundQuerySignal := QuerySignal new.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   687
	ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   688
	ImageNotFoundQuerySignal parent:ImageLoadErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   689
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   690
	InformationLostQuerySignal := QuerySignal new.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   691
	InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   692
	InformationLostQuerySignal parent:ImageLoadErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   693
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   694
	BadImageFormatQuerySignal := QuerySignal new.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   695
	BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   696
	BadImageFormatQuerySignal parent:ImageLoadErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   697
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   698
	UnrepresentableColorSignal := ImageErrorSignal newSignalMayProceed:true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   699
	UnrepresentableColorSignal nameClass:self message:#unrepresentableColorSignal.
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
   700
    ]
748
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   701
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
   702
    "Modified: / 18.5.1999 / 15:50:03 / cg"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   703
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   704
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   705
initializeFileFormatTable
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   706
    "initialize a default table to map from file extension to reader class.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   707
     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
   708
     see the 'smalltalk.rc'/'display.rc' startup files for a real (full) map."
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   709
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   710
    MIMETypes notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   711
	MIMETypes imageReaderForSuffix:'xbm'  put:XBMReader.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   712
	MIMETypes imageReaderForSuffix:'tiff' put:TIFFReader.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   713
	MIMETypes imageReaderForSuffix:'gif'  put:GIFReader.
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   714
    ].
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   715
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   716
    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   717
     Image initializeFileFormatTable
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   718
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   719
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   720
    "Modified: 30.6.1997 / 22:07:28 / cg"
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   721
!
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   722
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   723
initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   724
    "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
   725
     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
   726
     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
   727
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   728
    MIMETypes notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   729
	MIMETypes mimeTypeForSuffix:'gif'       put:'image/gif'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   730
	MIMETypes mimeTypeForSuffix:'tiff'      put:'image/tiff'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   731
	MIMETypes mimeTypeForSuffix:'tif'       put:'image/tiff'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   732
	MIMETypes mimeTypeForSuffix:'xbm'       put:'image/x-xbitmap'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   733
	MIMETypes mimeTypeForSuffix:'xpm'       put:'image/x-xpixmap'.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   734
    ].
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   735
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   736
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   737
     Image initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   738
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   739
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   740
    "Created: 27.6.1997 / 16:43:48 / cg"
1815
50212910fc13 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   741
    "Modified: 21.7.1997 / 17:33:59 / cg"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   742
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   743
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   744
update:something with:aParameter from:changedObject
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   745
    "flush all device specific stuff when restarted from a snapshot"
48194c26a46c Initial revision
claus
parents:
diff changeset
   746
48194c26a46c Initial revision
claus
parents:
diff changeset
   747
    (something == #restarted) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   748
	self flushDeviceImages
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   749
    ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   750
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   751
    "Created: 21.6.1996 / 19:47:43 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   752
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   753
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   754
!Image class methodsFor:'instance creation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   755
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   756
extent:ext
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   757
    "create a new image, given extent.
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   758
     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
   759
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   760
    ^ 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
   761
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   762
    "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
   763
    "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
   764
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   765
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   766
extent:ext depth:d
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   767
    "ST-80 compatibility"
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   768
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   769
    ^ self width:ext x height:ext y depth:d
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   770
!
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   771
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   772
extent:ext depth:d bits:bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   773
    "ST-80 compatibility; assume 32-bit padding"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   774
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   775
    ^ self extent:ext depth:d bits:bits pad:32
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   776
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   777
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   778
extent:ext depth:d bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   779
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   780
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   781
    ^ self width:ext x height:ext y depth:d fromArray:bits pad:padding
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   782
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   783
1276
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   784
extent:ext depth:d bitsPerPixel:bpp palette:aColormap usingBits:bits
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   785
    "ST-80 compatibility"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   786
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   787
    |img|
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   788
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   789
    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
   790
    img colorMap:aColormap.
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   791
    ^ img
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   792
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   793
    "Created: 25.1.1997 / 03:50:22 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   794
    "Modified: 25.1.1997 / 12:27:35 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   795
!
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   796
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   797
extent:ext depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   798
    "create & return a blank image of the given size.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   799
     ST-80 compatibility"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   800
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   801
    |newImage emptyBits|
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   802
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   803
    newImage := (self implementorForDepth:d) new.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   804
    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
   805
    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   806
    newImage bits:emptyBits.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   807
    ^ newImage
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   808
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   809
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   810
     Image extent:16@16 depth:8 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   811
     Image extent:16@16 depth:4 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   812
     Image extent:16@16 depth:2 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   813
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   814
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   815
    "Created: 6.3.1997 / 15:24:01 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   816
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   817
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   818
extent:ext depth:d palette:aColormap bits:bits
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   819
    "ST-80 compatibility"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   820
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   821
    ^ self extent:ext depth:d palette:aColormap bits:bits pad:16
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   822
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   823
    "Modified: 7.10.1996 / 11:32:16 / cg"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   824
!
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   825
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   826
extent:ext depth:d palette:aColormap bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   827
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   828
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   829
    |img|
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   830
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   831
    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
   832
    img colorMap:aColormap.
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   833
    ^ img
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   834
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   835
    "Modified: 7.10.1996 / 11:32:00 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   836
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   837
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   838
extent:ext fromArray:bits offset:offset
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   839
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   840
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   841
    ^ self width:ext x height:ext y fromArray:bits
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   842
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   843
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   844
fromForm:aForm
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   845
    "create & return an Image given a aForm"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   846
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   847
    ^ self fromSubForm:(0@0 extent:aForm extent) in:aForm
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   848
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   849
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   850
     |f|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   851
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   852
     f := Form width:16 height:16.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   853
     f clear.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   854
     f displayLineFromX:0 y:0 toX:15 y:15.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   855
     f inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   856
     (Image fromForm:f) inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   857
    "
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   858
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   859
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   860
     |f|
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   861
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   862
     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
   863
     f clear.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   864
     f paint:(Color red).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   865
     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
   866
     f paint:(Color green).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   867
     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
   868
     f inspect.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   869
     (Image fromForm:f) inspect
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   870
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   871
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   872
    "Modified: 11.7.1996 / 11:21:42 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   873
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   874
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   875
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   876
    "create & return an Image given another image. This can be used to
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   877
     convert an image to another depth."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   878
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   879
    ^ 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
   880
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   881
    "
3448
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   882
     |i i2 idx|
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   883
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   884
     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
   885
     i2 := i deepCopy.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   886
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   887
     idx := i2 colorMap indexOfPaintNearest:(Color green).
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   888
     i2 colorMap at:idx put:Color red.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   889
     i2 inspect.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
   890
     i inspect.
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   891
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   892
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   893
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   894
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   895
    "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
   896
     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
   897
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   898
    (self == Image
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   899
    or:[anImage class == self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
   900
	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
   901
    ^ self new fromImage:anImage photometric:photometricOrNil.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   902
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   903
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   904
     |i1 i8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   905
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
   906
     i1 := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   907
     i8 := Depth8Image fromImage:i1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   908
     i8 inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   909
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   910
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   911
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   912
fromSubForm:aRectangle in:aForm
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   913
    "create & return an subImage given a aForm"
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
    |depth device vis img|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   916
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   917
    depth := aForm depth.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   918
    device := aForm device.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   919
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   920
    (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
   921
	"/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   922
	"/ for truecolor displays, return a Depth24Image
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   923
	"/ (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
   924
	"/  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
   925
	"/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   926
	vis := device visualType.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   927
	(vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   928
	    depth > 8 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   929
		depth := 24.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   930
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   931
	].
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   932
    ].
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
   933
    img := self newForDepth:depth.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   934
    device isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   935
	^ img from:aForm in:aRectangle.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   936
    ].
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   937
    ^ img from:aForm in:aRectangle
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
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   941
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   942
     f := Form width:16 height:16.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   943
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   944
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   945
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   946
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   947
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   948
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   949
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   950
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   951
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   952
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   953
     f := Form width:16 height:16 depth:(Display depth) on:Display.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   954
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   955
     f paint:(Color red).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   956
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   957
     f paint:(Color green).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   958
     f displayLineFromX:15 y:0 toX:0 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   959
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   960
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   961
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   962
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   963
!
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   964
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   965
fromSubImage:anImage in:aRectangle
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   966
    "create & return an Image from a rectangular area in another image.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   967
     This can also be used to get a subimage in another depth."
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   968
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
   969
    |cls newImage|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   970
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   971
    self == Image ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   972
	cls := (self implementorForDepth:anImage depth).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   973
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   974
	cls := self.
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
   975
    ].
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
   976
    newImage := cls new.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   977
    ^ newImage fromSubImage:anImage in:aRectangle.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   978
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   979
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   980
     |i1 i8|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   981
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
   982
     i1 := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   983
     i8 := Depth8Image fromSubImage:i1 in:(0@0 corner:20@20).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   984
     i8 inspect
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
   985
    "
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   986
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   987
     |i1 i8|
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   988
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
   989
     i1 := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   990
     i8 := Depth8Image fromSubImage:i1 in:(70@50 extent:50@50).
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   991
     i8 inspect
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   992
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   993
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   994
     |i1 i8|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   995
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
   996
     i1 := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   997
     i8 := Image fromSubImage:i1 in:(70@50 extent:50@50).
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   998
     i8 inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   999
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1000
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1001
    "Created: 20.9.1995 / 01:05:43 / claus"
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1002
    "Modified: 24.4.1997 / 23:13:02 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1003
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1004
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1005
new
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1006
    "create a new image. Redefined to set the photometric to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1007
     greyScale with black being 0 as default."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1008
4416
fb209558d622 proper #initialize
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
  1009
    ^ self basicNew initialize
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1010
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1011
    "Modified: 10.6.1996 / 18:08:37 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1012
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1013
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1014
newForDepth:depth
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1015
    "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
  1016
     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
  1017
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1018
    |cls|
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1019
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1020
    cls := self implementorForDepth:depth.
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1021
    ^ cls new
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1022
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1023
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1024
     Image newForDepth:8
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1025
    "
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1026
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1027
    "Modified: / 27-05-2007 / 16:57:09 / cg"
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1028
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1029
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1030
width:w height:h
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1031
    "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
  1032
     Assume a depth of 1, unless an explicit imageClass is the receiver."
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1033
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1034
    |cls|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1035
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1036
    cls := self.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1037
    cls == Image ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1038
        cls := self implementorForDepth:1
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1039
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1040
    ^ cls new width:w height:h
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1041
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1042
    "Modified: / 06-06-2007 / 11:10:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1043
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1044
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1045
width:w height:h depth:d
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1046
    "create a new image, given width, height and depth"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1047
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1048
    ^ (self newForDepth:d)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1049
	width:w height:h depth:d
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1050
!
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1051
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1052
width:w height:h depth:d fromArray:pixelData
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1053
    "create a new image, given width, height, depth and data.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1054
     Data must be a ByteArray containing correctly aligned bits for the specified
134
claus
parents: 132
diff changeset
  1055
     depth (8-bit padded)."
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1056
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1057
    ^ (self newForDepth:d)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1058
	width:w height:h depth:d fromArray:pixelData
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1059
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1060
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1061
     Image width:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1062
	   height:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1063
	   depth:1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1064
	   fromArray:#[2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1065
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1066
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1067
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1068
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1069
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1070
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1071
		       2r00110011].
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1072
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1073
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1074
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1075
     Image width:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1076
	   height:8
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1077
	   depth:2
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1078
	   fromArray:#[4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1079
		       4r0011 4r0011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1080
		       4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1081
		       4r0011 4r0011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1082
		       4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1083
		       4r0011 4r0011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1084
		       4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1085
		       4r0011 4r0011].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1086
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1087
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1088
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1089
     Image width:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1090
	   height:8
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1091
	   depth:4
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1092
	   fromArray:#[16r00 16r01 16rf0 16rf1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1093
		       16r02 16r03 16rf2 16rf3
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1094
		       16r04 16r05 16rf4 16rf5
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1095
		       16r06 16r07 16rf6 16rf7
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1096
		       16r08 16r09 16rf8 16rf9
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1097
		       16r0a 16r0b 16rfa 16rfb
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1098
		       16r0c 16r0d 16rfc 16rfd
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1099
		       16r0e 16r0f 16rfe 16rff].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1100
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1101
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1102
    "Modified: 10.6.1996 / 18:18:10 / cg"
132
claus
parents: 125
diff changeset
  1103
!
claus
parents: 125
diff changeset
  1104
134
claus
parents: 132
diff changeset
  1105
width:w height:h depth:d fromArray:pixelData pad:padding
claus
parents: 132
diff changeset
  1106
    "create a new image, given width, height, depth and data.
claus
parents: 132
diff changeset
  1107
     Data must be a ByteArray containing correctly aligned bits for the specified
claus
parents: 132
diff changeset
  1108
     depth."
claus
parents: 132
diff changeset
  1109
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1110
    |img newBits
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1111
     srcRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1112
     dstRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1113
     nextDstIndex "{ Class: SmallInteger }"
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1114
     srcIndex "{ Class: SmallInteger }"
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1115
     dstIndex "{ Class: SmallInteger }" |
134
claus
parents: 132
diff changeset
  1116
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1117
    img := (self newForDepth:d) width:w height:h depth:d .
134
claus
parents: 132
diff changeset
  1118
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1119
    srcRowBytes := ((w * d + padding - 1) bitShift:-5) bitShift:2.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1120
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1121
    (padding ~~ 8 and:[srcRowBytes \\ 4 ~~ 0]) ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1122
        "must repad; ST/X uses byte padding, while ST-80 uses longword
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1123
         padding. This is stupid, and may be changed in ST/X with future versions.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1124
        "
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1125
        dstRowBytes := img bytesPerRow.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1126
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1127
        newBits := ByteArray uninitializedNew:(dstRowBytes * h).
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1128
        srcIndex := 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1129
        dstIndex := 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1130
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1131
        1 to:h do:[:row |
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1132
            nextDstIndex := dstIndex + dstRowBytes.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1133
            newBits replaceFrom:dstIndex
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1134
                             to:(nextDstIndex - 1)
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1135
                           with:pixelData
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1136
                     startingAt:srcIndex.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1137
            srcIndex := srcIndex + srcRowBytes.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1138
            dstIndex := nextDstIndex.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1139
        ].
134
claus
parents: 132
diff changeset
  1140
    ] ifFalse:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1141
        pixelData class isBytes ifFalse:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1142
            newBits := ByteArray withAll:pixelData
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1143
        ] ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1144
            newBits := pixelData
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1145
        ]
134
claus
parents: 132
diff changeset
  1146
    ].
claus
parents: 132
diff changeset
  1147
    img bits:newBits.
claus
parents: 132
diff changeset
  1148
    ^ img
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1149
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1150
    "Modified: / 27-05-2007 / 14:01:32 / cg"
134
claus
parents: 132
diff changeset
  1151
!
claus
parents: 132
diff changeset
  1152
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1153
width:w height:h fromArray:anArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1154
    "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
  1155
     receiving class is Image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1156
     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
  1157
     (i.e. 8 bits per byte)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1158
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1159
    |cls d pixels|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1160
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1161
    cls := self.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1162
    cls == Image ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1163
	cls := self implementorForDepth:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1164
	d := 1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1165
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1166
	d := cls imageDepth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1167
    ].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1168
    anArray class isBytes ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1169
	pixels := ByteArray withAll:anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1170
    ] ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1171
	pixels := anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1172
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1173
    ^ cls new width:w height:h depth:d fromArray:pixels
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1174
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1175
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1176
     Image width:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1177
	   height:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1178
	   fromArray:#[2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1179
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1180
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1181
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1182
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1183
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1184
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1185
		       2r00110011].
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1186
    "
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1187
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1188
    "Modified: 8.6.1996 / 10:07:26 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1189
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1190
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1191
!Image class methodsFor:'Signal constants'!
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1192
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1193
badImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1194
    "return the (query-) signal, which is raised if some
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1195
     bitmap-image could not be loaded due to an unrecognized format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1196
     If unhandled, the image-load returns nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1197
     Otherwise, it returns whatever the handler proceeds with.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1198
     The exception gets either the images fileName or an input stream
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1199
     as parameter"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1200
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1201
    ^ BadImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1202
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1203
    "Created: 1.2.1997 / 14:40:29 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1204
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1205
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1206
cannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1207
    "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
  1208
     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
  1209
     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
  1210
     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
  1211
     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
  1212
     (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
  1213
     format then."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1214
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1215
    ^ CannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1216
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1217
    "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
  1218
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1219
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1220
fileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1221
    "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
  1222
     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
  1223
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1224
    ^ FileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1225
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1226
    "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
  1227
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1228
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1229
imageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1230
    "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
  1231
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1232
    ^ ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1233
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1234
    "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
  1235
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1236
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1237
imageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1238
    "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
  1239
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1240
    ^ ImageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1241
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1242
    "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
  1243
!
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1244
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1245
imageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1246
    "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
  1247
     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
  1248
     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
  1249
     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
  1250
     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
  1251
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1252
    ^ ImageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1253
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1254
    "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
  1255
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1256
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1257
imageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1258
    "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
  1259
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1260
    ^ ImageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1261
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1262
    "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
  1263
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1264
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1265
informationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1266
    "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
  1267
     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
  1268
     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
  1269
     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
  1270
     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
  1271
     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
  1272
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1273
    ^ InformationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1274
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1275
    "Created: 27.2.1997 / 12:43:50 / cg"
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1276
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1277
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1278
unrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1279
    "return the signal, which is raised if some color is not
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1280
     representable in the image (when storing a pixel)."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1281
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1282
    ^ UnrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1283
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1284
    "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
  1285
! !
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1286
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1287
!Image class methodsFor:'cleanup'!
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1288
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1289
releaseResourcesOnDevice:aDevice
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1290
    "this is sent when a display connection is closed,
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1291
     to release all cached Images from that device"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1292
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1293
    Lobby
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1294
	unregisterAllForWhich:[:eachImage |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1295
	    |ok|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1296
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1297
	    ok := eachImage graphicsDevice == aDevice.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1298
	    ok ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1299
		eachImage releaseFromDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1300
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1301
	    ok
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1302
	]
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1303
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1304
    "Created: 16.1.1997 / 19:30:44 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1305
    "Modified: 16.1.1997 / 19:33:49 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1306
! !
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1307
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1308
!Image class methodsFor:'file reading'!
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1309
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1310
fromFile:aFileName
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1311
    "read an image from a file - this methods tries to find
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1312
     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
  1313
     and lets the appropriate reader read the file.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1314
     Also, all bitmap directories along the searchPath are checked
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1315
     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
  1316
     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
  1317
     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
  1318
     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
  1319
     proceed with some replacement image. If unhandled, nil is returned."
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1320
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1321
    |image name fn nm inStream suffix readerClass
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1322
     mustDecompress inPipe readersErrorMsg|
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1323
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1324
    "before trying each reader, check if the file is readable"
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1325
4158
930761d24ab2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4156
diff changeset
  1326
    name := aFileName asFilename.
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1327
    name isAbsolute ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1328
        fn := name asFilename.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1329
    ] ifFalse:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1330
        inStream := Smalltalk systemFileStreamFor:name.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1331
        inStream isNil ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1332
            inStream := Smalltalk bitmapFileStreamFor:name.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1333
            inStream isNil ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1334
                "this signal is a query - if noone seems to care, return nil.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1335
                 However, a handler may provide a replacement image."
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1336
                ^ ImageNotFoundQuerySignal
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1337
                            raiseRequestWith:aFileName
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1338
                            errorString:('IMAGE [warning]: ''' , name pathName, ''' does not exist or is not readable').
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1339
            ].
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1340
        ].
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1341
        fn := inStream pathName asFilename.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1342
        inStream close.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1343
    ].
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1344
4158
930761d24ab2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4156
diff changeset
  1345
    nm := fn name.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1346
    suffix := fn suffix.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1347
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1348
    "handle compressed-suffix"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1349
    (#('Z' 'gz') includes:suffix) ifTrue:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1350
        fn := fn withoutSuffix.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1351
        nm := fn name.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1352
        suffix := fn suffix.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1353
        mustDecompress := true.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1354
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1355
    suffix isEmpty ifTrue:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1356
        suffix := nm.
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1357
    ].
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1358
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1359
    "get the imageReader class from the files extension and ask it first"
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1360
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1361
    readerClass notNil ifTrue:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1362
        mustDecompress == true ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1363
            inPipe := PipeStream readingFrom:'gunzip <' , fn pathName.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1364
            inPipe notNil ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1365
                [
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1366
                    image := readerClass fromStream:inPipe.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1367
                ] ensure:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1368
                    inPipe close
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1369
                ].
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1370
            ]
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1371
        ] ifFalse:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1372
            BadImageFormatQuerySignal handle:[:ex |
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1373
                Transcript showCR:(readersErrorMsg := ex description).
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1374
                image := nil.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1375
                ex return.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1376
            ] do:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1377
                image := readerClass fromFile:fn.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1378
            ].
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1379
        ].
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1380
        image notNil ifTrue:[^ image].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1381
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1382
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1383
    (readerClass isNil or:[readersErrorMsg notNil]) ifTrue:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1384
        "no known extension (or wrong extension)
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1385
         - ask all readers if they know this format ...
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1386
         ... these look into the file, and investigate the header.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1387
         therefore, it takes a bit longer."
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1388
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1389
        MIMETypes imageReaderClasses do:[:mimeReaderClass |
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1390
            (mimeReaderClass notNil
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1391
            and:[mimeReaderClass ~~ readerClass]) ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1392
               (mimeReaderClass isValidImageFile:name) ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1393
                    image := mimeReaderClass fromFile:name.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1394
                    image notNil ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1395
                        ^ image
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1396
                    ]
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1397
                ]
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1398
            ]
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1399
        ].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1400
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1401
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1402
    "nope - unknown format
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1403
     this signal is a query - if noone seems to care, return nil.
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1404
     However, a handler may provide a replacement image."
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1405
3656
11670e0e6fcb invalid format notification fixed
Claus Gittinger <cg@exept.de>
parents: 3623
diff changeset
  1406
    ^ BadImageFormatQuerySignal
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1407
        raiseRequestWith:aFileName
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1408
        errorString:(readersErrorMsg ? ('IMAGE [warning]: unknown image file format: ''' , aFileName asFilename pathName , '''')).
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1409
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1410
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1411
     Image fromFile:'goodies/bitmaps/gifImages/claus.gif'
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1412
     Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1413
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1414
     Image fromFile:'goodies/bitmaps/winBitmaps/a11.ico'
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1415
     Image fromFile:'goodies/bitmaps/xpmBitmaps/countries/czech.xpm'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1416
     Image fromFile:'goodies/bitmaps/xpmBitmaps/countries/czech.xpm.gz'
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
  1417
     Image fromFile:'clients/Demos/bitmaps/hello_world.icon'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1418
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1419
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1420
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1421
     Image fromFile:'fooBar'
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1422
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1423
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1424
    "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
  1425
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1426
     Image imageNotFoundQuerySignal
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1427
     handle:[:ex |
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1428
        Transcript showCR:ex description.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1429
        ex proceedWith:nil
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1430
     ] do:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1431
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1432
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1433
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1434
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1435
    "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
  1436
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1437
     Image imageNotFoundQuerySignal
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
  1438
     answer:(Image fromFile:'libtool/bitmaps/SmalltalkX.xbm')
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1439
     do:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1440
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1441
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1442
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1443
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1444
    "Modified: / 19-11-2007 / 15:50:52 / cg"
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1445
!
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1446
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1447
fromFile:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1448
    "read an image for a package from a file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1449
     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
  1450
     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
  1451
     and lets the appropriate reader read the file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1452
     Also, all bitmap directories along the searchPath are checked
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1453
     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
  1454
     separate directory, thereby overriding system bitmaps easily.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1455
     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
  1456
     the ImageNotFoundQuerySignal is raised, which may be handled to
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1457
     proceed with some replacement image. If unhandled, nil is returned."
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1458
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1459
    ^ Smalltalk imageFromFileNamed:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1460
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1461
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1462
     Image fromFile:'libtool/bitmaps/SBrowser.xbm'
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1463
     Image fromFile:'bitmaps/SBrowser.xbm' inPackage:'stx:libtool'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1464
     Image fromFile:'garfield.gif' inPackage:'stx:goodies/bitmaps/gifImages'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1465
    "
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1466
!
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1467
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1468
fromFile:aFileName on:aDevice
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1469
    "read an image from a file and prepare a device representation.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1470
     Return nil (or whatever a handler returned),
1307
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
    |img|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1474
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1475
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1476
    img notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1477
	^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1478
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1479
    ^ nil
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1480
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1481
    "Modified: 1.2.1997 / 14:48:07 / cg"
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1482
!
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1483
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1484
fromFile:aFileName resolution:res
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1485
    "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
  1486
     as appropriate (only req'd for very high resolution displays).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1487
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1488
     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
  1489
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1490
    ^ self fromFile:aFileName resolution:res on:nil
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1491
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1492
    "Created: 19.12.1996 / 14:02:13 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1493
    "Modified: 1.2.1997 / 14:48:16 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1494
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1495
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1496
fromFile:aFileName resolution:dpi on:aDevice
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1497
    "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
  1498
     as appropriate (only req'd with very high resolution displays).
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1499
     Prepare a device representation.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1500
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1501
     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
  1502
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1503
    |img dev dpiH mag|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1504
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1505
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1506
    img isNil ifTrue:[^ nil].
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
    "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
  1509
    dev := aDevice.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1510
    dev isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1511
	"should not happen ..."
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1512
	dev := Screen current
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1513
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1514
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1515
    dev notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1516
	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
  1517
    ] ifFalse:[
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1518
	dpiH := 90
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1519
    ].
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1520
    ((dpi >= (dpiH * 0.75)) and:[dpi <= (dpiH * 1.5)]) ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1521
    mag := (dpiH / dpi) rounded.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1522
    mag = 0 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1523
    mag = 1 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1524
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1525
    img := img magnifiedBy:(mag @ mag).
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1526
    aDevice notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1527
	^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1528
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1529
    ^ img
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1530
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1531
    "Modified: 1.2.1997 / 14:48:20 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1532
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1533
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1534
fromStream:aStream
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1535
    "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
  1536
     out the file format itself (by contents)
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1537
     and lets the appropriate reader read the file.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1538
     To do this, the stream must be positionable.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1539
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1540
     if the stream does not contain an appropriate image."
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1541
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1542
    |image|
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1543
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1544
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1545
     ask all readers if they know
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1546
     this format ...
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1547
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1548
    MIMETypes imageReaderClasses do:[:readerClass |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1549
	readerClass notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1550
	    image := readerClass fromStream:aStream.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1551
	    image notNil ifTrue:[^ image].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1552
	]
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1553
    ].
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1554
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
     nope - unknown format
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1557
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1558
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1559
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1560
    ^ ImageNotFoundQuerySignal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1561
		raiseRequestWith:aStream
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1562
		errorString:('IMAGE [warning]: unknown image file format in stream').
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1563
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1564
    "
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1565
     Image fromFile:'goodies/bitmaps/gifImages/claus.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1566
     Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1567
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1568
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1569
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm.Z'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1570
     Image fromFile:'clients/Demos/bitmaps/hello_world.icon'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1571
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1572
     Image fromFile:'librun/stx.ico'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1573
     Image fromFile:'libwidg3/bitmaps/wall.tiff'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1574
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1575
     Image fromFile:'goodies/bitmaps/test.fax'
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1576
     Image fromFile:'fileIn/bitmaps/founders.im8'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1577
     Image fromFile:'goodies/faces/next.com/steve.face'
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1578
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1579
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1580
    "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
  1581
    "Modified: 30.6.1997 / 22:03:59 / cg"
1307
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
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1584
fromStream:aStream using:aReaderClass
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1585
    "read an image from a stream, given an imageReaderClass.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1586
     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
  1587
     extension (or non-definite header), so #fromStream: could not
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1588
     find out the images format.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1589
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1590
     if the stream does not contain an appropriate image."
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1591
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1592
    |image|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1593
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1594
    image := aReaderClass fromStream:aStream.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1595
    image notNil ifTrue:[^ image].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1596
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1597
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1598
     nope - unknown format
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1599
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1600
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1601
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1602
    ^ ImageNotFoundQuerySignal
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1603
		raiseRequestWith:aStream
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1604
		errorString:('IMAGE: unknown image file format in stream').
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1605
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1606
    "Created: 1.2.1997 / 14:46:20 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1607
    "Modified: 1.2.1997 / 14:48:53 / cg"
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1608
! !
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1609
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1610
!Image class methodsFor:'misc'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1611
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1612
ditherAlgorithm
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1613
    "return the way we dither -
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1614
	#threshold, or nil        -> no dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1615
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1616
	#error or #floydSteinberg -> errorDiffusion; much better
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1617
	#burkes                   -> errorDiffusion; even better."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1618
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1619
    ^ DitherAlgorithm
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1620
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1621
    "Created: 17.6.1996 / 18:57:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1622
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1623
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1624
ditherAlgorithm:aSymbol
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1625
    "define how to dither -
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1626
	#threshold, or nil        -> no dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1627
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1628
	#error or #floydSteinberg -> errorDiffusion; much better
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1629
	#burkes                   -> errorDiffusion; even better."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1630
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1631
    DitherAlgorithm := aSymbol
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1632
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1633
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1634
     Image dither:#pattern
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1635
     Image dither:#floydSteinberg
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1636
     Image dither:#burkes
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1637
     Image dither:nil
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1638
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1639
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1640
    "Modified: 10.6.1996 / 12:27:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1641
    "Created: 17.6.1996 / 18:57:19 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1642
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1643
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1644
numberOfDitherColors:n
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1645
    "define how many colors (i.e. patterns) to use when
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1646
     doing a pattern dither"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1647
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1648
    NumberOfDitherColors := n
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1649
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1650
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1651
orderedDitherMatrixOfSize:sz
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1652
    sz == 2 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1653
	^ #[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1654
		0 2
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1655
		3 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1656
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1657
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1658
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1659
    sz == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1660
	^ #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1661
		 0  8  2 10
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1662
		12  4 14  6
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1663
		 3 11  1  9
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1664
		15  7 13  5
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1665
	   ].
798
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
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1668
    sz == 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1669
	^  #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1670
		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
  1671
	       48 16 56 24   50 18 58 26
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1672
	       12 44  4 36   14 46  6 38
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1673
	       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
  1674
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1675
		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
  1676
	       51 19 59 27   49 17 57 25
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1677
	       15 47  7 39   13 45  5 37
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1678
	       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
  1679
	    ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1680
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1681
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1682
    ^ nil
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1683
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1684
    "Created: 7.6.1996 / 14:15:05 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1685
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1686
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1687
!Image class methodsFor:'queries'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1688
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1689
bytesPerRowForWidth:width depth:bitsPerPixel padding:padding
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1690
    "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
  1691
     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
  1692
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1693
    |bitsPerRow paddedUnitsPerRow|
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1694
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1695
    bitsPerRow := width * bitsPerPixel.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1696
    paddedUnitsPerRow := bitsPerRow // padding.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1697
    ((bitsPerRow \\ padding) ~~ 0) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1698
	paddedUnitsPerRow := paddedUnitsPerRow + 1
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1699
    ].
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1700
    ^ paddedUnitsPerRow * (padding // 8)
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1701
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1702
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1703
!
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1704
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1705
defaultPhotometric
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1706
    "return the default photometric pixel interpretation"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1707
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1708
    ^ #blackIs0
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1709
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1710
    "Modified: 20.4.1996 / 23:40:41 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1711
    "Created: 10.6.1996 / 18:08:12 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1712
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1713
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1714
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1715
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1716
     this class.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1717
     Must be redefined in concrete subclasses"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1718
2913
c51ac85e9aa2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2891
diff changeset
  1719
    ^ self subclassResponsibility
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1720
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1721
    "Modified: 20.4.1996 / 23:40:41 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1722
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1723
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1724
imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1725
    "return a collection of suffixes which are recognized as image-file suffix"
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1726
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1727
    ^ MIMETypes imageFileSuffixes
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1728
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1729
    "
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1730
     Image imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1731
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1732
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1733
    "Modified: 30.6.1997 / 22:04:39 / cg"
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1734
!
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1735
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1736
imageReaderClassForMIME:mimeType
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1737
    "return an appropriate imageReader class for a given mime type;
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)"
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1739
1801
3dff7fb2bd59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1800
diff changeset
  1740
    ^ MIMETypes imageReaderForType:mimeType
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1741
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1742
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1743
     Image imageReaderClassForMIME:'image/tiff'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1744
     Image imageReaderClassForMIME:'image/x-portable-pixmap'
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
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1747
    "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
  1748
    "Modified: 30.6.1997 / 21:54:10 / cg"
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1749
!
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1750
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1751
imageReaderClassForSuffix:aSuffix
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1752
    "return an appropriate imageReader class for a given file-suffix;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1753
     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
  1754
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1755
    ^ MIMETypes imageReaderForSuffix:aSuffix
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1756
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1757
    "
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1758
     Image imageReaderClassForSuffix:'tiff'
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1759
     Image imageReaderClassForSuffix:'foo'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1760
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1761
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1762
    "Modified: 30.6.1997 / 22:05:14 / cg"
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1763
!
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1764
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  1765
implementorForDepth:depth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1766
    "return the class, which best implements images of depth"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1767
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1768
    depth == 1 ifTrue:[^ Depth1Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1769
    depth == 2 ifTrue:[^ Depth2Image].
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1770
    depth <= 4 ifTrue:[^ Depth4Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1771
    depth <= 8 ifTrue:[^ Depth8Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1772
    depth <= 16 ifTrue:[^ Depth16Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1773
    depth <= 24 ifTrue:[^ Depth24Image].
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1774
    depth <= 32 ifTrue:[^ Depth32Image].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1775
    ^ self
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1776
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1777
    "Modified: 24.4.1997 / 19:04:52 / cg"
1611
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1778
!
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1779
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1780
isImageFileSuffix:aSuffix
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1781
    "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
  1782
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1783
     ^ self imageFileSuffixes includes:(aSuffix asLowercase)
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1784
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1785
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1786
     Image isImageFileSuffix:'gif'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1787
     Image isImageFileSuffix:'xbm'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1788
     Image isImageFileSuffix:'foo'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1789
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1790
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1791
    "Created: 18.4.1997 / 14:55:28 / cg"
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1792
!
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1793
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1794
mimeTypeFromSuffix:suffix
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1795
    "search my suffix information for a mime type and
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1796
     return it; return nil if unknown"
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1797
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1798
    ^ MIMETypes mimeTypeForSuffix:suffix
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1799
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1800
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1801
     Image mimeTypeFromSuffix:'gif'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1802
     Image mimeTypeFromSuffix:'tiff'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1803
     Image mimeTypeFromSuffix:'foobar'
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1804
    "
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1805
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1806
    "Modified: 1.7.1997 / 00:17:27 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1807
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1808
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1809
!Image class methodsFor:'screen capture'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1810
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1811
fromScreen
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1812
    "return an image of the full screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1813
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1814
	      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
  1815
	      (use #fromScreen:on:grab: with a false grabArg then)."
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
    |display|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1818
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1819
    display := Screen current.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1820
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1821
	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
  1822
	on:display
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1823
	grab:true
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1824
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1825
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1826
     Image fromScreen
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1827
     Image fromScreen inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1828
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1829
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1830
    "Modified: 26.3.1997 / 10:44:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1831
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1832
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1833
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1834
    "return an image of a part of the screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1835
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1836
	      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
  1837
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1838
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1839
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1840
	fromScreen:aRectangle
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1841
	on:Screen current
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1842
	grab:true
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1843
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1844
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1845
     Image fromScreen:(0@0 corner:100@100)
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1846
     (Image fromScreen:(0@0 corner:100@100)) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1847
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1848
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1849
    "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
  1850
!
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
fromScreen:aRectangle on:aDevice
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1853
    "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
  1854
     another display device.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1855
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1856
	      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
  1857
	      (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
  1858
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1859
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1860
	fromScreen:aRectangle
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1861
	on:aDevice
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1862
	grab:true
1487
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
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1865
     Image fromScreen:(0@0 corner:100@100)
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1866
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1867
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1868
    "get a snapshot of your friends screen ...
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1869
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1870
     |dpy2|
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1871
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1872
     dpy2 := XWorkstation new initializeFor:'idefix:0'.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1873
     (Image fromScreen:(dpy2 bounds) on:dpy2) inspect
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1874
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1875
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1876
    "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
  1877
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1878
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1879
fromScreen:aRectangle on:aDisplay grab:doGrab
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1880
    "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
  1881
     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
  1882
     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
  1883
     shown while the readout is done.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1884
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1885
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1886
	      (use with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1887
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1888
    |depth vis img|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1889
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1890
    depth := aDisplay depth.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1891
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1892
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1893
    "/ 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
  1894
    "/ (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
  1895
    "/  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
  1896
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1897
    vis := aDisplay visualType.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1898
    (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1899
	depth > 8 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1900
	    depth := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1901
	]
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1902
    ].
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1903
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1904
    img := self newForDepth:depth.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1905
    ^ img fromScreen:aRectangle on:aDisplay grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1906
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
  1907
    "Modified: / 26.1.1998 / 22:23:08 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1908
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1909
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1910
fromScreenArea
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1911
    "return an image of a part of the screen;
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1912
     let user specify screen area.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1913
     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
  1914
     Use #fromUser for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1915
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1916
	      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
  1917
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1918
2102
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1919
    |r|
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1920
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1921
    [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
  1922
    r := Rectangle fromUser.
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1923
    r width == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1924
    r height == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  1925
    ^ self fromScreen:r
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1926
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1927
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1928
     Image fromScreenArea
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1929
     Image fromScreenArea inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1930
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1931
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  1932
    "Modified: / 10.9.1998 / 15:59:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1933
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1934
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1935
fromUser
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1936
    "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
  1937
     Same as fromScreenArea, for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1938
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1939
	      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
  1940
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1941
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1942
    ^ self fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1943
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1944
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1945
     Image fromUser
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1946
     Image fromUser inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1947
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1948
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1949
    "Modified: 26.3.1997 / 10:45:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1950
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1951
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1952
fromView:aView
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1953
    "return an image taken from a views contents as currently
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1954
     on the screen. The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1955
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1956
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1957
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1958
     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
  1959
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1960
	      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
  1961
	      (use #fromView:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1962
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1963
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1964
	fromView:aView
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1965
	grab:true
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1966
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1967
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1968
     Image fromView:(Launcher allInstances first window topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1969
     Image fromView:(BrowserView allInstances first topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1970
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1971
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1972
    "get a snapshot from whichever view is active:
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1973
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1974
     |active|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1975
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1976
     active := WindowGroup activeGroup topViews first.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1977
     (Image fromView:active) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1978
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1979
1043
0688425d02c9 Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents: 1041
diff changeset
  1980
    "Modified: 9.9.1996 / 22:41:01 / stefan"
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1981
    "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
  1982
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1983
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1984
fromView:aView grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1985
    "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
  1986
     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
  1987
     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
  1988
     shown while the readout is done.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1989
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1990
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1991
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1992
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1993
     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
  1994
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1995
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1996
	      (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  1997
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  1998
    ^ self fromView:aView grab:doGrab withDecoration:false
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  1999
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2000
    "Created: / 26.3.1997 / 10:34:20 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2001
    "Modified: / 10.10.2001 / 14:13:29 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2002
!
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2003
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2004
fromView:aView grab:doGrab withDecoration:withDecoration
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2005
    "return an image taken from a views contents as currently
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2006
     on the screen, optionally with decoration included.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2007
     If the doGrab argument is true, the display
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2008
     is grabbed (i.e. blocked for others) and a camera cursor is
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2009
     shown while the readout is done.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2010
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2011
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2012
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2013
     the returned Image is NOT correct.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2014
     You may want to raise the view before using this method.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2015
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2016
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2017
	      (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2018
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2019
    |org ext device cH bW bH|
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2020
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2021
    device := aView graphicsDevice.
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2022
    org := device translatePoint:(0@0) fromView:aView toView:nil.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2023
    ext := aView extent.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2024
    withDecoration ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2025
	device platformName = 'WIN32' ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2026
	    cH := device captionHeight.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2027
	    bW := (device getSystemMetrics: #SM_CXFRAME )
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2028
		  "+ ( device getSystemMetrics: #borderFrameWidth )".
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2029
	    bH := (device getSystemMetrics: #SM_CYFRAME )
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2030
		  " + ( device getSystemMetrics: #borderFrameHeight )".
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2031
	    org := org - (bW @ (bH + cH)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2032
	    ext := ext + ((bW + bW) @ (bH+bH+cH)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2033
	].
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2034
    ].
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2035
    ^ self fromScreen:(org extent:ext) on:device grab:doGrab
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2036
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2037
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2038
     Transcript topView raise. (Image fromView:Transcript topView grab:false withDecoration:false) inspect
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2039
     Transcript topView raise. (Image fromView:Transcript topView grab:false withDecoration:true) inspect
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2040
    "
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2041
4574
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2042
    "Created: / 26-03-1997 / 10:34:20 / cg"
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2043
    "Modified: / 08-09-2006 / 15:41:41 / cg"
157
claus
parents: 154
diff changeset
  2044
! !
claus
parents: 154
diff changeset
  2045
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2046
!Image methodsFor:'Compatibility-Squeak'!
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2047
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2048
boundingBox
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2049
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2050
    ^ self bounds
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2051
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2052
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2053
colormapIfNeededForDepth:d
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2054
    ^ nil
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2055
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2056
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2057
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2058
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2059
fill:aRectangle fillColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2060
    "fill the rectangular area specified by aRectangle with the given color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2061
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2062
    self fillRectangle:aRectangle withColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2063
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2064
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2065
fillBlack:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2066
    "fill the rectangular area specified by aRectangle with the black color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2067
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2068
    self fillRectangle:aRectangle withColor:Color black
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2069
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2070
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2071
     |img|
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2072
     img := Image extent:100@100 depth:24.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2073
     img photometric:#rgb.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2074
     img data:(ByteArray new:100*100*3).
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2075
     img fillWhite:(0@0 corner:100@100).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2076
     img fillBlack:(10@10 corner:90@90).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2077
     img inspect.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2078
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2079
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2080
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2081
fillWhite:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2082
    "fill the rectangular area specified by aRectangle with the white color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2083
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2084
    self fillRectangle:aRectangle withColor:Color white
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2085
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2086
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2087
isTransparentAt:aPoint
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2088
    mask isNil ifTrue:[ ^ false].
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2089
    ^ (mask pixelAt:aPoint) == 0
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2090
! !
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2091
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2092
!Image methodsFor:'Compatibility-VW'!
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2093
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2094
asCachedImage
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2095
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2096
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2097
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2098
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2099
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2100
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2101
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2102
!
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2103
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2104
asRetainedMedium
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2105
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2106
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2107
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2108
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2109
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2110
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2111
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2112
    "Created: 27.1.1997 / 15:49:08 / cg"
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2113
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2114
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2115
bounds:newBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2116
    ^ self
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2117
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2118
    "Created: 10.2.1997 / 12:44:46 / cg"
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
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2121
containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2122
    "in st-80, images are visualComponents ..."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2123
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2124
    ^ self bounds containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2125
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2126
    "Created: 6.3.1997 / 15:24:12 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2127
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2128
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2129
convertToPalette:aColormap renderedBy:anImageRenderer
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2130
    "this does not really mimicri the corresponding ST-80 functionality"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2131
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2132
    |monoBits convertedImage|
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2133
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2134
    aColormap size == 2 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2135
	anImageRenderer class == OrderedDither ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2136
	    monoBits := self orderedDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2137
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2138
	    monoBits := self floydSteinbergDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2139
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2140
	(((aColormap at:1) = Color black)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2141
	and:[(aColormap at:2) = Color white]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2142
	    "/ ok
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2143
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2144
	    (((aColormap at:1) = Color white)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2145
	    and:[(aColormap at:2) = Color black]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2146
		monoBits invert
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2147
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2148
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2149
	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
  2150
	convertedImage palette:aColormap.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2151
	^ convertedImage
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2152
    ].
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2153
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2154
    self error:'unimplemented operation'.
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2155
    ^ self
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2156
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2157
    "Modified: 1.3.1997 / 17:25:50 / cg"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2158
!
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2159
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2160
paintBasis
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2161
    "huh - whats that;
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2162
     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
  2163
     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
  2164
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2165
    ^ ColorValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2166
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2167
    "Created: 6.3.1997 / 15:24:19 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2168
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2169
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2170
preferredBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2171
    ^ self bounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2172
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2173
    "Created: 10.2.1997 / 12:42:36 / cg"
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2174
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2175
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2176
tile:bounds from:origin in:tile rule:rule
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2177
    |orgX orgY tW tH|
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2178
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2179
    origin ~= (0@0) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2180
	self halt:'unimplemented'.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2181
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2182
    bounds ~= self bounds ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2183
	self halt:'unimplemented'.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2184
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2185
    rule ~= #over ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2186
	self halt:'unimplemented'.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2187
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2188
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2189
    orgX := origin x.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2190
    orgY := origin y.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2191
    tW := tile width.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2192
    tH := tile height.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2193
    (bounds top) to:(bounds bottom) by:tH do:[:dstY |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2194
	(bounds left) to:(bounds right) by:(tile width) do:[:dstX |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2195
	    self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2196
		copyFrom:tile
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2197
		x:orgX y:orgY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2198
		toX:dstX y:dstY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2199
		width:tW height:tH.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2200
	].
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2201
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2202
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2203
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2204
valueAtPoint:aPoint put:aColorValue
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2205
    aColorValue isInteger ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2206
	self colorAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2207
    ] ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2208
	self pixelAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2209
    ]
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2210
! !
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2211
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2212
!Image methodsFor:'accessing'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2213
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2214
bitsPerSample
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2215
    "return the number of bits per sample.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2216
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2217
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2218
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2219
    ^ Array with:self depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2220
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2221
    "Modified: 10.6.1996 / 18:04:21 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2222
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2223
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2224
colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2225
    "return the colormap"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2226
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2227
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2228
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2229
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2230
colorMap:aColorMap
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2231
    "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
  2232
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2233
    |newSize "{ Class: SmallInteger }"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2234
     oldSize "{ Class: SmallInteger }"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2235
     sameColors|
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2236
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2237
    (aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2238
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2239
    photometric == #palette ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2240
	"/ any change at all ?
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2241
	(newSize := aColorMap size) >= (oldSize := colorMap size) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2242
	    sameColors := true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2243
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2244
	    1 to:oldSize do:[:idx |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2245
		(aColorMap at:idx) = (colorMap at:idx) ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2246
		    sameColors := false.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2247
		]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2248
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2249
	].
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2250
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2251
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2252
    self setColorMap:aColorMap.
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2253
    sameColors ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2254
	^ self
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2255
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2256
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2257
    colorMap notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2258
	photometric := #palette.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2259
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2260
	(photometric == #palette) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2261
	    photometric := #blackIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2262
	]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2263
    ].
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2264
    deviceForm notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2265
	self release
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2266
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2267
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2268
    "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
  2269
    "Modified: / 22.8.1998 / 12:29:58 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2270
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2271
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2272
colorMapFromArray: anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2273
    "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
  2274
     The (byte-)Array argument should be of the form:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2275
	#( 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
  2276
     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
  2277
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2278
    self colorMap:(MappedPalette rgbBytesVector:anArray)
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2279
!
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2280
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2281
colorMapFromRGBValueArray:anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2282
    "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
  2283
     The (integer-)Array argument should be of the form:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2284
	#( rgb0 rgb1  ... rgbN)
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2285
     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
  2286
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2287
    self colorMap:(MappedPalette rgbValueVector:anArray)
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2288
!
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2289
757
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2290
container:aVisualContainer
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2291
    "ignored here - added to allow images to be used like
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2292
     VisualComponents (later, Image should inherit from it)"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2293
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2294
    "Created: 28.5.1996 / 23:43:49 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2295
    "Modified: 29.5.1996 / 10:22:23 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2296
!
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2297
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2298
depth
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2299
    "return the depth of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2300
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2301
    ^ self bitsPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2302
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2303
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2304
device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2305
    "return the device, the receiver is associated with.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2306
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2307
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2308
    ^ device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2309
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2310
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2311
extent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2312
    "return the images extent"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2313
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2314
    ^ width@height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2315
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2316
1950
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2317
fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2318
    "return the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2319
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2320
    ^ fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2321
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2322
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2323
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2324
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2325
fileName:something
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2326
    "set the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2327
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2328
    fileName := something.
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2329
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2330
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2331
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2332
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2333
fullColorId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2334
    "return the id of the full color image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2335
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2336
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2337
    fullColorDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2338
    ^ fullColorDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2339
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2340
728
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2341
graphicsDevice
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2342
    "same as #device - for ST-80 compatibility"
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2343
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2344
    ^ device
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2345
!
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
  2346
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2347
height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2348
    "return the height of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2349
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2350
    ^ height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2351
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2352
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2353
id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2354
    "return the id of the image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2355
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2356
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2357
    deviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2358
    ^ deviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2359
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2360
2081
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2361
imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2362
    "return the frameSequence of which this image is a part of;
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2363
     nil if it is not part of a sequence."
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2364
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2365
    ^ imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2366
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2367
    "Created: / 1.4.1998 / 14:43:00 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2368
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2369
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2370
imageSequence:aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2371
    "private entry for imageReaders - set the frameSequence of which
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2372
     this image is a part of"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2373
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2374
    imageSequence := aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2375
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2376
    "Created: / 1.4.1998 / 14:42:36 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2377
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2378
896
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2379
mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2380
    ^ mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2381
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2382
    "Created: 21.6.1996 / 12:57:44 / cg"
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2383
!
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2384
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2385
mask:anotherImage
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2386
    "set the images mask - currently, this may be nil or a Depth1Image.
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2387
     (it is planned to support alpha information in a Depth8 maskImage in
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2388
      the near future).
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2389
     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
  2390
		       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
  2391
		       0-bit mask pixels lead to transparent pixels.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2392
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2393
     For depth8 masks: (future):
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2394
		       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
  2395
		       which specifies the transparency of that pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2396
		       0 means completely transparent, 255 means completely
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2397
		       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
  2398
		       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
  2399
		       alpha value of 255."
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2400
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2401
    mask := anotherImage.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2402
    maskedPixelsAre0 := false.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2403
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2404
    "Created: 27.6.1996 / 17:45:22 / cg"
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2405
    "Modified: 12.4.1997 / 12:04:39 / cg"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2406
!
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2407
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2408
maskedPixelsAre0
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2409
    "return true if masked pixels have been cleared to zero"
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2410
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2411
    ^ maskedPixelsAre0 == true
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2412
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2413
    "Modified: / 22.8.1998 / 11:27:22 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2414
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2415
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2416
maskedPixelsAre0:aBoolean
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2417
    "set/clear the flag which states if masked pixels
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2418
     have been set to zero. Knowing this to be true allows
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2419
     faster drawing of the image later; (however, not setting
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2420
     it will still produce correct output).
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2421
     This flag is typically set by image readers."
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2422
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2423
    maskedPixelsAre0 := aBoolean
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2424
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2425
    "Modified: 12.4.1997 / 12:08:42 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2426
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2427
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2428
monochromeId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2429
    "return the id of the monochrome image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2430
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2431
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2432
    monoDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2433
    ^ monoDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2434
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2435
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2436
palette
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2437
    "return the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2438
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2439
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2440
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2441
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2442
palette:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2443
    "set the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2444
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2445
    self colorMap:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2446
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2447
    "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
  2448
    "Modified: 8.6.1996 / 09:54:02 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2449
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2450
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2451
photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2452
    "return the photometric, a symbol such as #palette, #rgb etc."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2453
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2454
    ^ photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2455
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2456
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2457
samplesPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2458
    "return the number of samples per pixel in the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2459
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2460
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2461
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2462
    ^ 1
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2463
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2464
    "Modified: 10.6.1996 / 18:03:30 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2465
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2466
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2467
setColorMap:aColorMap
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2468
    (aColorMap isNil or:[aColorMap isKindOf:Colormap]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2469
	colorMap := MappedPalette withColors:aColorMap
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2470
    ] ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2471
	colorMap := aColorMap
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2472
    ]
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2473
!
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2474
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2475
width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2476
    "return the width of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2477
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2478
    ^ width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2479
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2480
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  2481
!Image methodsFor:'accessing-pixels'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2482
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2483
at:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2484
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2485
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2486
     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
  2487
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2488
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2489
     retrieve the pixel at aPoint; return a color.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2490
     Pixels start at 0@0 for upper left pixel, end at
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2491
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2492
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2493
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2494
     (it is meant to access individual pixels - for example, in a bitmap editor)"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2495
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2496
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2497
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2498
    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
  2499
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2500
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2501
    "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
  2502
    "Modified: / 9.1.1998 / 20:33:52 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2503
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2504
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2505
at:aPoint put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2506
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2507
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2508
     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
  2509
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2510
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2511
     set the pixel at aPoint to aColor.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2512
     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
  2513
     (width-1)@(height-1) for lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2514
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2515
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2516
     (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
  2517
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2518
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2519
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2520
    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
  2521
    ^ self colorAtX:aPoint x y:aPoint y put:aColor
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2522
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2523
    "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
  2524
    "Modified: / 9.1.1998 / 20:34:15 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2525
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2526
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2527
atImageAndMask:aPoint put:aColorOrPixelOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2528
    "set the pixel at x/y to aColor.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2529
     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
  2530
     otherwise to 1. Nil is treated like noColor.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2531
     (used by the bitmap editor)"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2532
2523
4c197af8cc50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2502
diff changeset
  2533
    |maskVal|
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2534
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2535
    (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
  2536
	maskVal := 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2537
	aColorOrPixelOrNil isInteger ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2538
	    self pixelAt:aPoint put:aColorOrPixelOrNil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2539
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2540
	    self colorAt:aPoint put:aColorOrPixelOrNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2541
	]
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2542
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2543
	maskVal := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2544
	self pixelAt:aPoint put:0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2545
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2546
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2547
	mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2548
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2549
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2550
    "Modified: / 30.9.1998 / 22:42:44 / cg"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2551
!
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2552
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2553
atImageAndMask:aPoint putValue:aPixelValueOrNil
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2554
    "set the pixel at x/y to aColor.
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2555
     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
  2556
     otherwise to 1.
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2557
     (used by the bitmap editor)"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2558
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2559
    |pixVal maskVal|
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2560
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2561
    aPixelValueOrNil notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2562
	pixVal := aPixelValueOrNil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2563
	maskVal := 1.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2564
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2565
	pixVal := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2566
	maskVal := 0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2567
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2568
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2569
	mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2570
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2571
    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
  2572
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2573
    "Modified: / 30.9.1998 / 22:42:44 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2574
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2575
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2576
atPoint:aPoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2577
    "ST-80 compatibility: return the pixelValue at:aPoint."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2578
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2579
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2580
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2581
    "Modified: 24.4.1997 / 16:18:44 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2582
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2583
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2584
atPoint:aPoint put:aPixelValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2585
    "ST-80 compatibility: set the pixelValue at:aPoint."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2586
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2587
    ^ self pixelAtX:aPoint x y:aPoint y put:aPixelValue
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
    "Modified: 24.4.1997 / 17:17:59 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2590
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2591
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2592
atX:x y:y
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2593
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2594
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2595
     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
  2596
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2597
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2598
     Retrieve a pixel at x/y; return a color.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2599
     Pixels start at 0@0 for upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2600
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2601
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2602
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2603
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2604
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2605
    '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
  2606
    ^ self colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2607
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2608
    "Modified: 21.6.1997 / 13:10:32 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2609
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2610
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2611
atX:x y:y put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2612
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2613
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2614
     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
  2615
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2616
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2617
     set the pixel at x/y to aColor.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2618
     Pixels start at 0@0 for the upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2619
     (width-1)@(height-1) for the lower right pixel.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2620
     This method checks if the color can be stored in the image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2621
     (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
  2622
     You should not use this method for image-processing, it is very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2623
     (it is meant to access individual pixels - for example, in a bitmap editor)"
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2624
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2625
    aColor isInteger ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2626
	'Image [warning]: the Image>>atX:y:put: will change semantics soon; use #colorAtX:y:put:' infoPrintCR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2627
	^ self pixelAtX:x y:y put:aColor
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2628
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2629
    ^ self colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2630
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2631
    "Modified: 21.6.1997 / 13:10:44 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2632
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2633
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2634
atX:x y:y putValue:aPixelValue
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2635
    "set the pixel at x/y to aPixelValue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2636
     The interpretation of the pixelValue depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2637
     and the colormap. (see also: Image>>atX:y:put:)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2638
     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
  2639
     (width-1) @ (height-1) for the lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2640
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2641
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2642
     (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
  2643
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2644
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2645
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2646
    self obsoleteMethodWarning:'use #pixelAtX:y:put:'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2647
    ^ self pixelAtX:x y:y put:aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2648
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2649
    "Modified: 24.4.1997 / 17:15:45 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2650
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2651
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2652
bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2653
    "return the raw image data; depending on the photometric,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2654
     this has to be interpreted as monochrome, greyscale,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2655
     palette or rgb data.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2656
     It is also packed to be dense, so a 4 bitPerSample palette image
4415
be0fa075e4c4 comment
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
  2657
     will store 2 pixels per byte, whereas a 2-bitPerPixel image will store
be0fa075e4c4 comment
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
  2658
     4 pixels per byte."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2659
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2660
    ^ bytes
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2661
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2662
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2663
colorAt:aPoint
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2664
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2665
     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
  2666
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2667
     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
  2668
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2669
     (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
  2670
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2671
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2672
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2673
    "Created: 24.4.1997 / 17:02:31 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2674
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2675
1962
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2676
colorAt: aPoint put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2677
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2678
    self colorAtX: aPoint x y: aPoint y put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2679
!
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2680
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2681
colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2682
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2683
     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
  2684
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2685
     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
  2686
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2687
     (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
  2688
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2689
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2690
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2691
    pixel := self pixelAtX:x y:y.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2692
    ^ self colorFromValue:pixel
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2693
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2694
    "Modified: 24.4.1997 / 16:18:53 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2695
    "Created: 24.4.1997 / 17:00:52 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2696
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2697
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2698
colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2699
    "set the pixel at x/y to aColor.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2700
     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
  2701
     (width-1)@(height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2702
     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
  2703
     (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
  2704
     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
  2705
     (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
  2706
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2707
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2708
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2709
    pixel := self valueFromColor:aColor.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2710
    pixel isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2711
	^ UnrepresentableColorSignal raiseErrorString:'cannot store color - not in colormap'.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2712
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2713
    self pixelAtX:x y:y put:pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2714
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2715
    "Modified: 24.4.1997 / 17:36:20 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2716
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2717
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2718
data
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2719
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2720
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2721
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2722
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2723
    self obsoleteMethodWarning:'use #bits'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  2724
    ^ self bits
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2725
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2726
    "Modified: 24.4.1997 / 17:37:57 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2727
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2728
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2729
data:aByteArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2730
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2731
4175
a9e65365e590 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 4173
diff changeset
  2732
    <resource:#obsolete>
3966
950a2db201c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3964
diff changeset
  2733
    self obsoleteMethodWarning:'use #bits:'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  2734
    self bits:aByteArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2735
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2736
    "Modified: 24.4.1997 / 17:38:18 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2737
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2738
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2739
maskAt:aPoint
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2740
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2741
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2742
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2743
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2744
    ^ self maskAtX:aPoint x y:aPoint y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2745
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2746
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2747
maskAt:aPoint put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2748
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2749
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2750
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2751
    ^ self maskAtX:aPoint x y:aPoint y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2752
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2753
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2754
maskAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2755
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2756
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2757
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2758
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2759
    mask isNil ifTrue:[^ 1].
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2760
    ^ mask pixelAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2761
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2762
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2763
maskAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2764
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2765
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2766
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2767
    mask isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  2768
	maskValue == 1 ifTrue:[^ self].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  2769
	self error:'image has no mask'.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2770
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2771
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2772
    ^ mask pixelAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2773
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2774
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2775
pixelAt:aPoint
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2776
    "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
  2777
     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
  2778
     (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
  2779
     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
  2780
     very slow ...
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2781
     (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
  2782
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2783
    ^ 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
  2784
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2785
    "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
  2786
!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2787
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2788
pixelAt:aPoint put:aPixelValue
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2789
    "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
  2790
     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
  2791
     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
  2792
     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
  2793
     (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
  2794
     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
  2795
     very slow ...
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2796
     (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
  2797
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2798
    ^ 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
  2799
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2800
    "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
  2801
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2802
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2803
pixelAtX:x y:y
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2804
    "retrieve the pixelValue at aPoint; return an integer number.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2805
     Pixels start at 0/0 for upper left pixel, and end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2806
     width-1@height-1 for lower right pixel.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2807
     The returned numbers interpretation depends on the photometric
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2808
     and the colormap. (see also Image>>at: and Image>>atX:y:)
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2809
     You should not use this method for image-processing of
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2810
     big images, its very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2811
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2812
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2813
    ^ self subclassResponsibility
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2814
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2815
    "Created: 24.4.1997 / 16:06:56 / cg"
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
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2818
pixelAtX:x y:y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2819
    "set the pixel at x/y to aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2820
     The interpretation of the pixelValue depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2821
     and the colormap. (see also: Image>>atX:y:put:)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2822
     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
  2823
     (width-1) @ (height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2824
     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
  2825
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2826
     (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
  2827
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2828
    ^ self subclassResponsibility
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
    "Created: 24.4.1997 / 17:05:11 / cg"
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
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2833
rgbValueAt:aPoint
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2834
    "retrieve a pixels rgb value at x/y; return a 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2835
     Pixels start at 0@0 for upper left pixel, end at (width-1)@(height-1) for lower right pixel."
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2836
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2837
    ^ self rgbValueAtX:(aPoint x) y:(aPoint y)
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2838
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2839
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2840
rgbValueAtX:x y:y
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2841
    "retrieve a pixels rgb value at x/y; return a 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2842
     Pixels start at 0@0 for upper left pixel, end at (width-1)@(height-1) for lower right pixel."
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2843
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2844
    |pixel|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2845
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2846
    pixel := self pixelAtX:x y:y.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2847
    ^ self rgbFromValue:pixel
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2848
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2849
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  2850
rgbValueAtX:x y:y put:newRGBValue         
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  2851
    |value|
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  2852
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  2853
    value := self valueFromRGB:newRGBValue.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  2854
    self pixelAtX:x y:y put:value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  2855
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  2856
    "Created: / 15-01-2008 / 15:56:10 / cg"
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  2857
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  2858
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2859
rowAt:y
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2860
    "retrieve an array filled with pixel values from
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2861
     a single row.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2862
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2863
     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
  2864
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2865
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2866
    |pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2867
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2868
    pixelArray := self pixelArraySpecies new:width.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2869
    self rowAt:y into:pixelArray startingAt:1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2870
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2871
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2872
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2873
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2874
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  2875
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2876
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2877
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2878
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2879
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2880
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  2881
     i := Image fromFile:'libtool/bitmaps/SBrowser.xbm'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2882
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2883
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2884
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2885
    "Modified: 24.4.1997 / 15:51:24 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2886
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2887
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2888
rowAt:y into:aPixelBuffer
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2889
    "fill aBuffer with pixel values retrieved from a single row.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2890
     Notice: row coordinate starts at 0."
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2891
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2892
    ^ self rowAt:y into:aPixelBuffer startingAt:1
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2893
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2894
    "Created: 24.4.1997 / 15:44:46 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2895
    "Modified: 24.4.1997 / 15:51:35 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2896
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2897
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2898
rowAt:y into:aPixelBuffer startingAt:startIndex
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2899
    "fill aBuffer with pixel values retrieved from a single row.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2900
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2901
     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
  2902
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2903
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2904
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2905
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2906
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2907
    0 to:w do:[:col |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2908
	aPixelBuffer at:(col + startIndex) put:(self pixelAtX:col y:y)
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2909
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2910
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2911
    "Created: 24.4.1997 / 15:05:21 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2912
    "Modified: 24.4.1997 / 16:52:43 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2913
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2914
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2915
rowAt:y putAll:pixelArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2916
    "store a single rows pixels from bits in the argument;
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2917
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2918
     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
  2919
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2920
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2921
    ^ self rowAt:y putAll:pixelArray startingAt:1
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2922
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2923
    "Modified: 24.4.1997 / 15:51:58 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2924
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2925
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2926
rowAt:y putAll:pixelArray startingAt:startIndex
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2927
    "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
  2928
     return the pixelArray.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  2929
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2930
     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
  2931
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2932
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2933
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2934
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2935
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2936
    0 to:w do:[:col |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2937
	self pixelAtX:col y:y put:(pixelArray at:(col + startIndex))
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2938
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2939
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2940
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2941
    "Modified: 24.4.1997 / 17:05:57 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2942
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2943
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2944
valueAt:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2945
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2946
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2947
     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
  2948
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2949
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2950
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2951
     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
  2952
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2953
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2954
     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
  2955
     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
  2956
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2957
     (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
  2958
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2959
    '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
  2960
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2961
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2962
    "Modified: 21.6.1997 / 13:11:19 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2963
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2964
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2965
valueAtX:x y:y
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2966
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2967
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2968
     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
  2969
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2970
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2971
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2972
     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
  2973
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2974
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2975
     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
  2976
     You should not use this method for image-processing of
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2977
     big images, its very slow ...
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2978
     (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
  2979
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2980
    '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
  2981
    ^ self pixelAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2982
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2983
    "Modified: 21.6.1997 / 13:11:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2984
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2985
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  2986
!Image methodsFor:'accessing-private'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2987
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2988
bits:aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2989
    "set the raw data.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2990
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2991
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2992
     instances or by image readers. Calling for a change of an
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  2993
     existing image may confuse later pixel interpretation
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  2994
     (it does not care for colormaps and/or cached device image flushing)."
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2995
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2996
    bytes := aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2997
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2998
    "Modified: 23.4.1996 / 11:08:28 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2999
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3000
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
  3001
bitsPerSample:aCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3002
    "set the number of bits per sample.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3003
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3004
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3005
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3006
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3007
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
  3008
    bitsPerSample := aCollection
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3009
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3010
    "Modified: 23.4.1996 / 11:08:31 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3011
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3012
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3013
depth:d
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3014
    "set the depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3015
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3016
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3017
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3018
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3019
1362
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  3020
    depth := self depth.
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  3021
    bitsPerPixel := d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3022
    d == 24 ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3023
        samplesPerPixel := 3.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3024
        bitsPerSample := #[8 8 8]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3025
    ] ifFalse:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3026
        d == 32 ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3027
            samplesPerPixel := 4.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3028
            bitsPerSample := #[8 8 8 8]
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3029
        ] ifFalse:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3030
            d == 16 ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3031
                samplesPerPixel := 3.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3032
                bitsPerSample := #[5 5 5]
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3033
            ] ifFalse:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3034
                samplesPerPixel := 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3035
                bitsPerSample := ByteArray with:d
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3036
            ]
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3037
        ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3038
    ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3039
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3040
    "Modified: / 27-05-2007 / 16:59:47 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3041
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3042
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3043
extent:anExtent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3044
    "set the images extent.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3045
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3046
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3047
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3048
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3049
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3050
    width := anExtent x.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3051
    height := anExtent y
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3052
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3053
    "Modified: 23.4.1996 / 11:08:38 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3054
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3055
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3056
height:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3057
    "set the height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3058
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3059
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3060
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3061
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3062
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3063
    height := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3064
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3065
    "Modified: 23.4.1996 / 11:08:40 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3066
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3067
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3068
photometric:aSymbol
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3069
    "set the photometric interpretation of the pixel values.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3070
     The argument, aSymbol is one of:
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3071
	#blackIs0, #whiteIs0, #palette, #rgb
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3072
     See TIFF documentation, from which the photometric concept is borrowed.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3073
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3074
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3075
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3076
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3077
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3078
    |b|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3079
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3080
    photometric := aSymbol.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3081
    bitsPerSample isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3082
	photometric == #rgb ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3083
	    b := self class imageDepth // 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3084
	    bitsPerSample := ByteArray with:b with:b with:b
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3085
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3086
	    bitsPerSample := ByteArray with:(self class imageDepth)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3087
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3088
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3089
    samplesPerPixel isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3090
	photometric == #rgb ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3091
	    samplesPerPixel := 3
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3092
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3093
	    samplesPerPixel := 1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3094
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3095
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3096
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3097
    "Modified: 10.6.1996 / 18:21:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3098
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3099
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3100
samplesPerPixel:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3101
    "set the array of samples per pixel.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3102
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3103
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3104
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3105
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3106
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3107
    samplesPerPixel := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3108
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3109
    "Modified: 23.4.1996 / 11:08:45 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3110
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3111
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3112
width:aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3113
    "set the width of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3114
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3115
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3116
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3117
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3118
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3119
    width := aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3120
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3121
    "Modified: 23.4.1996 / 11:08:48 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3122
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3123
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3124
width:w height:h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3125
    "set the width and height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3126
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3127
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3128
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3129
     existing image may confuse later pixel interpretation."
283
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
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3132
    height := h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3133
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3134
    "Modified: 23.4.1996 / 11:08:53 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3135
!
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3136
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3137
width:w height:h depth:d
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3138
    "set the width, height and depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3139
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3140
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3141
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3142
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3143
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3144
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3145
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3146
    self depth:d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3147
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3148
    "Modified: 23.4.1996 / 11:08:56 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3149
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3150
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3151
width:w height:h depth:d fromArray:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3152
    "set the width, height, depth and pixels of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3153
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3154
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3155
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3156
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3157
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3158
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3159
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3160
    self depth:d.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3161
    self bits:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3162
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3163
    "Modified: 23.4.1996 / 11:08:59 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3164
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3165
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3166
width:w height:h depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3167
    "set the width, height and depth of the image.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3168
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3169
     This interface is only to be used when initializing
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3170
     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
  3171
     existing image may confuse later pixel interpretation."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3172
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3173
    width := w.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3174
    height := h.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3175
    self depth:d.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3176
    self setColorMap:aColormap.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3177
    aColormap notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3178
	photometric := #palette
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3179
    ]
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3180
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3181
    "Modified: 23.4.1996 / 11:08:56 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3182
    "Created: 6.3.1997 / 15:23:57 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3183
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3184
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3185
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
  3186
    "set all relevant internal state of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3187
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3188
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3189
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3190
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3191
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3192
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3193
	width:w
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3194
	height:h
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3195
	photometric:p
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3196
	samplesPerPixel:spp
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3197
	bitsPerSample:bps
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3198
	colorMap:cm
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3199
	bits:pixels
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3200
	mask:nil
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3201
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3202
    "Modified: 20.6.1996 / 17:10:24 / cg"
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3203
!
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3204
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3205
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
  3206
    "set all relevant internal state of the image.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3207
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3208
     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
  3209
     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
  3210
     existing image may confuse later pixel interpretation."
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3211
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3212
    width := w.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3213
    height := h.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3214
    photometric := p.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3215
    samplesPerPixel := spp.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3216
    bitsPerSample := bps.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3217
    self setColorMap:cm.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3218
    self bits:pixels.
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3219
    mask := m.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3220
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3221
    "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
  3222
    "Created: 20.6.1996 / 17:09:53 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3223
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  3224
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3225
!Image methodsFor:'conversion helpers'!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3226
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3227
rgbColormapFor:aDevice
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3228
    "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
  3229
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3230
    |nColors    "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3231
     scaleRed scaleGreen scaleBlue
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3232
     redShift   "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3233
     greenShift "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3234
     blueShift  "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3235
     colorValues|
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3236
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3237
    "/ 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
  3238
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3239
    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
  3240
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3241
    "/ 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
  3242
    "/ (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
  3243
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3244
    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
  3245
    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
  3246
    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
  3247
    redShift := aDevice shiftRed.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3248
    greenShift := aDevice shiftGreen.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3249
    blueShift := aDevice shiftBlue.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3250
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3251
    colorValues := Array uninitializedNew:nColors.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3252
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3253
    0 to:nColors-1 do:[:pixel |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3254
	|clr rv gv bv v "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3255
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3256
	clr := self colorFromValue:pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3257
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3258
	rv := (clr red * scaleRed) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3259
	gv := (clr green * scaleGreen) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3260
	bv := (clr blue * scaleBlue) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3261
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3262
	v := rv bitShift:redShift.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3263
	v := v bitOr:(gv bitShift:greenShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3264
	v := v bitOr:(bv bitShift:blueShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3265
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3266
	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
  3267
"/ clr print. ' ' print.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3268
"/ 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
  3269
"/ ' -> ' print. v printNL.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3270
    ].
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3271
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3272
    ^ colorValues
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3273
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3274
    "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
  3275
! !
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3276
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3277
!Image methodsFor:'converting'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3278
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3279
asBurkesDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3280
    "return a burkes dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3281
     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
  3282
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3283
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3284
     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
  3285
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3286
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3287
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3288
    monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3289
    ^ 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
  3290
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
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3293
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3294
     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
  3295
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3296
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3297
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3298
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3299
    "
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
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3303
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3304
     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
  3305
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3306
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3307
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3308
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3309
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3310
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3311
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3312
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3313
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3314
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3315
	     width:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3316
	     height:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3317
	     fromArray:#[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3318
			    16r01 16r23
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3319
			    16r45 16r67
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3320
			    16r89 16rab
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3321
			    16rcd 16ref
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3322
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3323
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3324
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3325
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3326
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3327
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3328
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3329
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3330
    "Created: 10.6.1996 / 12:34:44 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3331
    "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
  3332
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3333
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3334
asDitheredImageUsing:colors
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3335
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3336
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3337
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3338
    ^ self asDitheredImageUsing:colors depth:self depth
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3339
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3340
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3341
asDitheredImageUsing:colors depth:d
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3342
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3343
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3344
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3345
    |newBits|
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3346
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3347
    newBits := self floydSteinbergDitheredDepth8BitsColors:colors map:(0 to:colors size - 1).
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3905
diff changeset
  3348
    newBits isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3349
	self error:'dithering failed'
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3905
diff changeset
  3350
    ].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  3351
    ^ (self class newForDepth:d) extent:(self extent); depth:d; palette:colors; bits:newBits
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3352
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3353
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3354
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3355
asErrorDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3356
    "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
  3357
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3358
    DitherAlgorithm == #burkes ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3359
	^ self asBurkesDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3360
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3361
    DitherAlgorithm == #stevensonArce ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3362
	^ self asStevensonArceDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3363
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3364
    ^ self asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3365
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3366
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3367
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3368
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3369
     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
  3370
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3371
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3372
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3373
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3374
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3375
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3376
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3377
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3378
     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
  3379
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3380
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3381
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3382
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3383
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3384
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3385
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3386
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3387
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3388
	     width:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3389
	     height:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3390
	     fromArray:#[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3391
			    16r01 16r23
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3392
			    16r45 16r67
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3393
			    16r89 16rab
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3394
			    16rcd 16ref
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3395
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3396
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3397
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3398
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3399
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3400
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3401
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3402
    "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
  3403
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3404
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3405
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3406
    "return a floyd-steinberg dithered pseudoForm from the picture.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3407
     Use the colors in the fixColors array.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3408
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3409
     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
  3410
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3411
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3412
    |pseudoBits f deviceDepth map|
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3413
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3414
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3415
    deviceDepth == 8 ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3416
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3417
            ^ nil.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3418
        ]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3419
    ].
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3420
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3421
    pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3422
    pseudoBits isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3423
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3424
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3425
    f isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3426
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3427
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3428
    "/ have to create a funny colorMap, where
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3429
    "/ color at:index == color colorId:index
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3430
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3431
    map := Array new:256.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3432
    fixColors do:[:clr |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3433
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3434
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3435
    f colorMap:map.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3436
    f initGC.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3437
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3438
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3439
        drawBits:pseudoBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3440
        bitsPerPixel:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3441
        depth:deviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3442
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3443
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3444
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3445
        into:(f id) x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3446
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3447
        with:(f gcId).
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3448
    ^ f
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3449
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3450
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3451
     example:
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3452
        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
  3453
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3454
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3455
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3456
     map := #(
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3457
                  (0     0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3458
                  (0     0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3459
                  (0    50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3460
                  (0    50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3461
                  (0   100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3462
                  (0   100 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3463
                  (100   0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3464
                  (100   0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3465
                  (100  50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3466
                  (100  50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3467
                  (100 100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3468
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3469
                                                      green:(rgb at:2)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3470
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3471
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3472
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3473
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3474
                      colors:map
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3475
                        nRed:2
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3476
                      nGreen:3
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3477
                       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3478
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3479
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3480
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3481
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3482
    "Modified: 14.6.1996 / 16:52:34 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3483
    "Created: 23.6.1997 / 15:25:37 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3484
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3485
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3486
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3487
    "return a floyd-steinberg dithered pseudoForm from the palette picture.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3488
     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
  3489
     colors assigned to aDevice, such as the preallocated colors of the
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3490
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3491
     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
  3492
     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
  3493
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3494
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3495
    |pseudoBits f deviceDepth map|
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3496
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3497
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3498
    deviceDepth == 8 ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3499
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3500
            ^ nil
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3501
        ]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3502
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3503
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3504
    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
  3505
    pseudoBits isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3506
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3507
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3508
    f isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3509
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3510
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3511
    "/ have to create a funny colorMap, where
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3512
    "/ color at:index == color colorId:index
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3513
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3514
    map := Array new:256.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3515
    fixColors do:[:clr |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3516
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3517
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3518
    f colorMap:map.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3519
    f initGC.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3520
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3521
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3522
        drawBits:pseudoBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3523
        bitsPerPixel:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3524
        depth:deviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3525
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3526
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3527
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3528
        into:(f id) x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3529
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3530
        with:(f gcId).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3531
    ^ f
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3532
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3533
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3534
     example:
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3535
        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
  3536
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3537
     |img8 reducedImg8 img4 map form|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3538
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3539
     map := #(
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3540
                  (0     0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3541
                  (0     0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3542
                  (0    50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3543
                  (0    50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3544
                  (0   100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3545
                  (0   100 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3546
                  (100   0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3547
                  (100   0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3548
                  (100  50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3549
                  (100  50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3550
                  (100 100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3551
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3552
                                                      green:(rgb at:2)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3553
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3554
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3555
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3556
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3557
                      colors:map
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3558
                        nRed:2
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3559
                      nGreen:3
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3560
                       nBlue:2.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3561
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3562
     img4 := Depth4Image fromImage:img8.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3563
    "
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3564
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3565
    "Modified: 14.6.1996 / 16:52:34 / cg"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3566
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3567
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3568
asFloydSteinbergDitheredGrayFormOn:aDevice
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3569
    "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
  3570
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3571
    |depth bits|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3572
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3573
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3574
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3575
    or:[aDevice hasGrayscales not]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3576
	"/ for monochrome, there is specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3577
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3578
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3579
	bits := self floydSteinbergDitheredMonochromeBits.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3580
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3581
	bits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3582
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3583
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3584
    ^ 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
  3585
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3586
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3587
     |i|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3588
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3589
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3590
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3591
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3592
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3593
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3594
     |i|
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3595
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3596
     i := Image fromFile:'bitmaps/granite.tiff'.
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3597
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3598
    "
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3599
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3600
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3601
    "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
  3602
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3603
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3604
asFloydSteinbergDitheredGrayImageDepth:depth
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3605
    "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
  3606
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3607
    |ditheredBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3608
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3609
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3610
	^ self asFloydSteinbergDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3611
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3612
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1778
diff changeset
  3613
    ditheredBits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3614
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3615
	width:width height:height fromArray:ditheredBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3616
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
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3619
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3620
     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
  3621
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3622
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3623
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3624
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3625
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3626
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3627
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3628
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3629
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3630
     i := Depth24Image width:4 height:1
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3631
	  fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3632
	    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
  3633
	    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
  3634
	    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
  3635
	    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
  3636
     i := i magnifiedBy:4@1.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3637
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3638
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3639
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3640
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3641
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3642
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3643
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3644
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3645
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3646
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3647
     i := Depth24Image width:4 height:6
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3648
	  fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3649
	    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
  3650
	    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
  3651
	    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
  3652
	    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
  3653
	    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
  3654
	    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
  3655
     i := i magnifiedBy:30.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3656
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3657
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3658
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3659
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3660
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3661
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3662
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3663
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3664
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3665
     i := Image fromFile:'granite.tiff'.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3666
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3667
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3668
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3669
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3670
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3671
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3672
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3673
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3674
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3675
     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
  3676
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3677
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3678
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3679
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3680
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3681
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3682
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3683
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3684
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3685
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3686
	     width:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3687
	     height:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3688
	     fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3689
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3690
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3691
			    16r89 16rab
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3692
			    16rcd 16ref
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3693
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3694
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3695
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3696
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3697
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3698
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3699
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3700
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3701
    "Created: 10.6.1996 / 12:33:47 / cg"
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  3702
    "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
  3703
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3704
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3705
asFloydSteinbergDitheredMonochromeFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3706
    "return a dithered moncohrome form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3707
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3708
    |monoBits|
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3709
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3710
    monoBits := self floydSteinbergDitheredMonochromeBits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3711
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3712
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3713
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3714
     |i f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3715
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3716
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3717
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3718
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3719
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3720
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3721
     |i f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3722
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3723
     i := Depth2Image width:8 height:8
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3724
	  fromArray:#[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3725
			4r0000 4r0000
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3726
			4r0000 4r0000
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3727
			4r1111 4r1111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3728
			4r1111 4r1111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3729
			4r2222 4r2222
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3730
			4r2222 4r2222
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3731
			4r3333 4r3333
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3732
			4r3333 4r3333
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3733
		     ].
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3734
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3735
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3736
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3737
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3738
    "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
  3739
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3740
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3741
asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3742
    "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
  3743
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3744
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3745
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3746
    monoBits := self floydSteinbergDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3747
    ^ 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
  3748
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3749
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3750
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3751
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3752
     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
  3753
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3754
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3755
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3756
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3757
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3758
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3759
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3760
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3761
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3762
     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
  3763
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3764
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3765
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3766
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3767
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3768
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3769
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3770
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3771
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3772
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3773
	     width:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3774
	     height:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3775
	     fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3776
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3777
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3778
			    16r89 16rab
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3779
			    16rcd 16ref
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3780
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3781
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3782
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3783
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3784
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3785
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3786
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3787
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3788
    "Created: 10.6.1996 / 12:33:47 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3789
    "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
  3790
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3791
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3792
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3793
    "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
  3794
     using colors in colors for dithering."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3795
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3796
    |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
  3797
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3798
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3799
    has8BitImage := (deviceDepth == 8)
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3800
                    or:[ (aDevice supportedImageFormatForDepth:8) notNil ].
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3801
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3802
    has8BitImage ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3803
        deviceDepth == 4 ifFalse:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3804
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3805
        pseudoBits8 := self nfloydSteinbergDitheredDepth8BitsColors:colors.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3806
        pseudoBits8 isNil ifTrue:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3807
        "/ convert to devices depth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3808
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3809
        pseudoBits := ByteArray new:(width*4+7//8 * height).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3810
        pseudoBits8 compressPixels:4 width:width height:height into:pseudoBits mapping:nil.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3811
        d := 4.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3812
    ] ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3813
        pseudoBits := self nfloydSteinbergDitheredDepth8BitsColors:colors.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3814
        pseudoBits isNil ifTrue:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3815
        d := 8.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3816
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3817
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3818
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3819
    f isNil ifTrue:[^ nil].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3820
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3821
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3822
    "/ have to create a funny colorMap, where
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3823
    "/ color at:index == color colorId:index
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3824
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3825
    map := Array new:256 withAll:0.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3826
    colors do:[:clr |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3827
        clr notNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3828
            map at:clr colorId + 1 put:clr
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3829
        ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3830
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3831
    f colorMap:map.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3832
    f initGC.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3833
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3834
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3835
        drawBits:pseudoBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3836
        bitsPerPixel:d
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3837
        depth:deviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3838
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3839
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3840
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3841
        into:(f id) x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3842
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3843
        with:(f gcId).
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3844
    ^ f
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3845
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3846
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3847
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3848
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3849
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3850
     (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
  3851
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3852
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3853
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3854
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3855
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3856
     (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
  3857
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3858
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3859
    "Created: 17.6.1996 / 12:13:35 / cg"
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3860
    "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
  3861
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3862
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3863
asFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3864
    "get a device form, with best possible approximation.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3865
     remember it in case someone asks again."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3866
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3867
    |form visual|
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3868
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3869
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3870
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  3871
    mask notNil ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3872
        mask := mask onDevice:aDevice
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  3873
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  3874
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3875
    (aDevice depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3876
    or:[aDevice hasGrayscales not]) ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3877
        form := self asMonochromeFormOn:aDevice.
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  3878
    ] ifFalse:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3879
        ((visual := aDevice visualType) == #StaticGray) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3880
            form := self asGrayFormOn:aDevice.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3881
        ] ifFalse:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3882
            (visual == #PseudoColor
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3883
             or:[visual == #StaticColor]) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3884
                form := self asPseudoFormQuickOn:aDevice.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3885
            ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3886
        ]
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  3887
    ].
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  3888
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  3889
    form isNil ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3890
        (photometric == #palette) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3891
            form := self paletteImageAsFormOn:aDevice
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3892
        ] ifFalse:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3893
            (photometric == #rgb or:[photometric == #rgba]) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3894
                form := self rgbImageAsFormOn:aDevice
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3895
            ] ifFalse:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3896
                (photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3897
                    form := self rgbImageAsFormOn:aDevice
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3898
                ] ifFalse:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3899
                    form := self greyImageAsFormOn:aDevice
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3900
                ]
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3901
            ]
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3902
        ].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3903
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  3904
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3905
    (device isNil or:[aDevice == device]) ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3906
        "remember this form in the receiver ..."
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3907
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3908
        form notNil ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3909
            form := form asImageForm.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3910
            deviceForm := form.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3911
            maskedPixelsAre0 := nil.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3912
            device isNil ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3913
                device := aDevice.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3914
                Lobby register:self
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3915
            ] ifFalse:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3916
                Lobby registerChange:self
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3917
            ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3918
            "
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3919
             can save space, by not keeping the images data-bits
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3920
             twice (here and in the device form)
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3921
            "
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3922
            form forgetBits
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3923
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3924
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  3925
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  3926
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3927
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  3928
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  3929
     |i|
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  3930
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  3931
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  3932
     (i asFormOn:Display) inspect.
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  3933
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  3934
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3935
    "Modified: / 06-06-2007 / 12:18:43 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3936
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3937
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3938
asGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3939
    "get a gray device form"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3940
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3941
    ^ self asGrayFormOn:aDevice dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3942
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3943
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3944
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3945
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3946
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3947
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3948
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3949
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3950
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3951
    "Created: 10.6.1996 / 18:44:42 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3952
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3953
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3954
asGrayFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3955
    "get a greyscale device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3956
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3957
    |depth|
813
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
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3960
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3961
    or:[aDevice hasGrayscales not]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3962
	^ self asMonochromeFormOn:aDevice
813
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
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3965
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3966
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3967
	^ self asThresholdGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3968
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3969
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3970
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3971
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3972
	^ self asOrderedDitheredGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3973
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3974
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3975
    ^ self asFloydSteinbergDitheredGrayFormOn:aDevice.
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
    "Created: 10.6.1996 / 18:42:01 / cg"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  3978
    "Modified: 14.6.1996 / 15:17:28 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3979
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3980
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3981
asGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3982
    "get a gray image from the receiver"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3983
4418
b07a714ee5fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4417
diff changeset
  3984
    (self colorMap notNil and:[depth == self depth]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3985
	^ self copyWithColorMapProcessing:[:clr | Color brightness:(clr brightness)].
4417
5e5d9b696293 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3986
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3987
    ^ self asGrayImageDepth:depth dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3988
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3989
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3990
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3991
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3992
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3993
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3994
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3995
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3996
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3997
    "Created: 10.6.1996 / 19:07:08 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3998
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3999
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4000
asGrayImageDepth:depth dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4001
    "get a greyscale image, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4002
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4003
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4004
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4005
	^ self asThresholdGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4006
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4007
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4008
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4009
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4010
	^ self asOrderedDitheredGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4011
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4012
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4013
    ^ self asFloydSteinbergDitheredGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4014
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4015
    "Created: 10.6.1996 / 19:08:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4016
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4017
4423
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4018
asImageWithDepth:depth
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4019
    "return a new image with another depth. Notice that this
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4020
     may raise an error, if the depth is smaller than the receivers depths
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4021
     and the number of colors is greater than the number of possible colors
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4022
     for the new depth - i.e. you should use this only to convert to a higher depth.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4023
     In the other case, use one of the dithering converters"
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4024
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4025
    |imageClass|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4026
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4027
    imageClass := Image implementorForDepth:depth.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4028
    ^ imageClass fromImage:self
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4029
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4030
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4031
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4032
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4033
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4034
     (i asImageWithDepth:24) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4035
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4036
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4037
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4038
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4039
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4040
     (i asImageWithDepth:4) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4041
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4042
!
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4043
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4044
asMonochromeFormOn:aDevice
48194c26a46c Initial revision
claus
parents:
diff changeset
  4045
    "get a monochrome device form"
48194c26a46c Initial revision
claus
parents:
diff changeset
  4046
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4047
    |form|
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4048
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4049
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm].
4390
8d752f4cd9e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  4050
    self depth == 1 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4051
	((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4052
	^ self asFormOn:aDevice
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4053
    ].
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4054
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4055
    form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4056
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4057
    (device isNil or:[aDevice == device]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4058
	"remember this form in the receiver ..."
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4059
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4060
	form notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4061
	    form := form asImageForm.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4062
	    monoDeviceForm := form.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4063
	    device isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4064
		device := aDevice.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4065
		Lobby register:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4066
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4067
		Lobby registerChange:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4068
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4069
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4070
	     can save space, by not keeping the images data-bits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4071
	     twice (here and in the device form)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4072
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4073
	    form forgetBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4074
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4075
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4076
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4077
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4078
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4079
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4080
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4081
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4082
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4083
     (i asMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4084
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4085
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4086
    "Modified: 23.10.1997 / 00:44:59 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4087
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4088
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4089
asMonochromeFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4090
    "get a monochrome device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4091
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4092
    |monoBits|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4093
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4094
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4095
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4096
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4097
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4098
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4099
    aDitherAlgorithm == #burkes ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4100
	monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4101
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4102
	aDitherAlgorithm == #stevensonArce ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4103
	    monoBits := self stevensonArceDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4104
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4105
	    (aDitherAlgorithm == #pattern
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4106
	    or:[aDitherAlgorithm == #ordered]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4107
		^ self asOrderedDitheredGrayFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4108
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4109
		^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4110
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4111
	]
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4112
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4113
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4114
    "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4115
    "/ make its pixel interpretation correct for the device
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4116
    "/
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4117
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4118
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4119
    "Modified: 10.6.1996 / 20:18:05 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4120
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4121
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4122
asNearestPaintDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4123
    "return a nearest paint pseudoForm from the palette picture.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4124
     Use the colors in the fixColors array.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4125
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4126
     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
  4127
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4128
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4129
    ^ self asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nil nGreen:nil nBlue:nil.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4130
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4131
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4132
     example:
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4133
	color reduction from Depth8 to Depth4 can be done by:
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4134
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4135
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4136
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4137
     map := #(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4138
		  (0     0   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4139
		  (0     0 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4140
		  (0    50   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4141
		  (0    50 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4142
		  (0   100   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4143
		  (0   100 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4144
		  (100   0   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4145
		  (100   0 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4146
		  (100  50   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4147
		  (100  50 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4148
		  (100 100   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4149
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4150
						      green:(rgb at:2)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4151
						       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4152
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4153
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4154
     form := img8 asNearestPaintDepth8FormOn:Display
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4155
		      colors:map
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4156
			nRed:2
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4157
		      nGreen:3
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4158
		       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4159
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4160
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4161
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4162
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4163
    "Modified: 17.6.1996 / 18:52:47 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4164
    "Created: 23.6.1997 / 15:26:09 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4165
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4166
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4167
asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4168
    "return a nearest paint pseudoForm from the palette picture.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4169
     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
  4170
     colors assigned to aDevice, such as the preallocated colors of the
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4171
     Color class.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4172
     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
  4173
     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
  4174
     for example to create dithered Depth4Images from Depth8Images."
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4175
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4176
    |pseudoBits f deviceDepth map|
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4177
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4178
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4179
    deviceDepth == 8 ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4180
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4181
            ^ nil
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4182
        ]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4183
    ].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4184
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4185
    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
  4186
    pseudoBits isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4187
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4188
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4189
    f isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4190
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4191
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4192
    "/ have to create a funny colorMap, where
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4193
    "/ color at:index == color colorId:index
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4194
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4195
    map := Array new:256.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4196
    fixColors do:[:clr |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4197
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4198
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4199
    f colorMap:map.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4200
    f initGC.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4201
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4202
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4203
        drawBits:pseudoBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4204
        bitsPerPixel:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4205
        depth:deviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4206
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4207
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4208
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4209
        into:(f id) x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4210
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4211
        with:(f gcId).
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4212
    ^ f
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4213
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4214
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4215
     example:
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4216
        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
  4217
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4218
     |img8 reducedImg8 img4 map form|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4219
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4220
     map := #(
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4221
                  (0     0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4222
                  (0     0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4223
                  (0    50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4224
                  (0    50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4225
                  (0   100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4226
                  (0   100 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4227
                  (100   0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4228
                  (100   0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4229
                  (100  50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4230
                  (100  50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4231
                  (100 100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4232
                  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4233
                                                      green:(rgb at:2)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4234
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4235
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4236
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4237
     form := img8 asNearestPaintDepth8FormOn:Display
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4238
                      colors:map
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4239
                        nRed:2
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4240
                      nGreen:3
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4241
                       nBlue:2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4242
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4243
     img4 := Depth4Image fromImage:img8.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4244
    "
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4245
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4246
    "Created: 17.6.1996 / 18:47:46 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4247
    "Modified: 17.6.1996 / 18:52:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4248
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4249
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4250
asNearestPaintImageDepth:d colors:colors
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4251
    "return a threshold image from the receiver picture, using colors in colors."
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4252
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4253
    |newBits|
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4254
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4255
    d ~~ 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  4256
	self error:'unsupported depth'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4257
    ].
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4258
    newBits := self nearestPaintDepth8BitsColors:colors nRed:nil nGreen:nil nBlue:nil.
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4259
    newBits isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  4260
	self error:'conversion failed'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4261
    ].
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4262
    ^ (self class newForDepth:d) extent:(self extent); depth:d; palette:colors; bits:newBits
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4263
!
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4264
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4265
asOrderedDitheredGrayFormOn:aDevice
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4266
    "return a dithered depth-x grey form from the receiver image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4267
     Uses an 8x8 dithermatrix."
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4268
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4269
    |depth bits|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4270
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4271
    depth := aDevice depth.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4272
    (depth == 1
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4273
    or:[aDevice hasGrayscales not]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4274
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4275
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4276
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4277
	^ self asOrderedDitheredMonochromeFormOn:aDevice
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4278
    ].
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4279
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4280
    bits := self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4281
		orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4282
		ditherWidth:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4283
		depth:depth.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4284
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4285
    ^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4286
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4287
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4288
     |i|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4289
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4290
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4291
     (i asOrderedDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4292
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4293
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4294
    "Modified: 24.6.1997 / 22:19:30 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4295
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4296
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4297
asOrderedDitheredGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4298
    "return a dithered depth-x grey image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4299
     Uses an 8x8 dithermatrix."
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
    |dither|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4302
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4303
    dither := self class orderedDitherMatrixOfSize:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4304
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4305
    (depth == 1) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4306
	"/ for monochrome, there is highly specialized
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4307
	"/ monochrome dither code available
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4308
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4309
	^ Depth1Image
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4310
	    width:width
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4311
	    height:height
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4312
	    fromArray:(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4313
		self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4314
		    orderedDitheredMonochromeBitsWithDitherMatrix:dither
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4315
		    ditherWidth:8)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4316
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4317
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4318
    ^ (self class implementorForDepth:depth)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4319
	width:width
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4320
	height:height
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4321
	fromArray:(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4322
	    self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4323
		orderedDitheredGrayBitsWithDitherMatrix:dither
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4324
		ditherWidth:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4325
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4326
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4327
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4328
     |i i1 i2 i4 i8|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4329
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4330
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4331
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4332
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4333
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4334
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4335
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4336
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4337
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4338
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4339
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4340
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4341
     i8 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4342
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4343
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4344
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4345
     |i i1 i2 i4 i8|
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4346
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4347
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4348
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4349
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4350
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4351
     i2 inspect.
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
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4354
     i4 inspect.
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
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4357
     i8 inspect.
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4358
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4359
     i2 := i8 asOrderedDitheredGrayImageDepth:2.
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4360
     i2 inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4361
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4362
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4363
    "Created: 7.6.1996 / 18:03:54 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4364
    "Modified: 24.6.1997 / 22:19:36 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4365
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4366
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4367
asOrderedDitheredMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4368
    "return a dithered monochrome form from the grey image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4369
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4370
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4371
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4372
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4373
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4374
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4375
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4376
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4377
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4378
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4379
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4380
	asOrderedDitheredMonochromeFormOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4381
	ditherMatrix:(self class orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4382
	ditherWidth:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4383
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4384
"/    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4385
"/        asOrderedDitheredMonochromeFormOn:aDevice
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4386
"/        ditherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4387
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4388
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4389
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4390
     |i f|
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/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4393
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4394
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4395
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4396
     |i f|
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/winBitmaps/a11.ico') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4399
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4400
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4401
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4402
     |i f|
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/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4405
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4406
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4407
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4408
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4409
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4410
     i := (Image fromFile:'doc/online/pictures/PasteButton.gif') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4411
     f := i asOrderedDitheredMonochromeFormOn:Display.
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
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4415
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4416
     i := (Image fromFile:'goodies/bitmaps/gifImages/blue-ball.gif') magnifiedBy:1.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4417
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4418
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4419
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4420
    "Created: 7.6.1996 / 14:52:32 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4421
    "Modified: 17.4.1997 / 01:10:10 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4422
!
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
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4425
    "return a dithered monochrome form from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4426
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4427
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4428
    |monoBits|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4429
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4430
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4431
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4432
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4433
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4434
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4435
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4436
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4437
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4438
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4439
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4440
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4441
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4442
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4443
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4444
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4445
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4446
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4447
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4448
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4449
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4450
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
798
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
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4453
    "Created: 7.6.1996 / 14:51:42 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4454
    "Modified: 17.4.1997 / 01:08:24 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4455
!
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
asOrderedDitheredMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4458
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4459
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4460
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4461
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4462
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4463
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4464
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4465
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4466
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4467
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4468
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4469
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4470
	asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4471
	ditherWidth:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4472
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4473
"/    ^ self
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4474
"/        asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4475
"/        ditherWidth:8
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
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4478
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4479
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4480
     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
  4481
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4482
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4483
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4484
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4485
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4486
     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
  4487
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4488
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4489
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4490
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4491
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4492
     i := (Image fromFile:'doc/online/pictures/PasteButton.gif') magnifiedBy:10.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4493
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4494
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4495
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4496
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4497
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4498
     i := (Image fromFile:'goodies/bitmaps/gifImages/blue-ball.gif') magnifiedBy:1.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4499
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4500
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4501
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4502
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4503
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4504
     i := Image fromFile:'libwidg3/bitmaps/granite.tiff'.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4505
     i asOrderedDitheredMonochromeImage inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4506
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4507
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4508
    "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
  4509
    "Modified: 10.6.1996 / 11:15:09 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4510
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4511
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4512
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4513
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4514
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4515
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4516
    |monoBits|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4517
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4518
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4519
    ^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4520
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4521
    "order-4 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4522
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4523
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4524
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4525
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4526
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4527
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4528
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4529
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4530
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4531
    "order-6 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4532
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4533
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4534
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4535
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4536
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4537
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4538
	ditherWidth:8
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4539
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4540
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4541
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4542
    "thresholding at:0.5 (all above 0.5 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4543
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4544
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4545
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4546
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4547
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4548
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4549
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4550
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4551
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4552
    "thresholding at: 0.25 (all above 0.25 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4553
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4554
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4555
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4556
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4557
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4558
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4559
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4560
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4561
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4562
    "thresholding at: 0.75 (all above 0.75 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4563
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4564
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4565
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4566
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4567
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4568
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4569
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4570
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4571
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4572
    "Modified: 7.6.1996 / 17:23:47 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4573
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4574
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4575
asPseudoFormQuickOn:aDevice
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4576
    "return a pseudo-deviceForm from the image.
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  4577
     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
  4578
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4579
    |f d
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4580
     temp temp8 bits clr cMap idMap
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4581
     w            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4582
     h            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4583
     dDev         "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4584
     nClr         "{ Class: SmallInteger }"
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4585
     bytesPerLine "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  4586
     usedColors pix fmt bytes|
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4587
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4588
    d := self depth.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4589
    (d == 1
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4590
    or:[d == 2
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4591
    or:[d == 4
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4592
    or:[d == 8]]]) ifFalse:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4593
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  4594
    bytes := self bits.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4595
    w := width.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4596
    h := height.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4597
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4598
    "/ 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
  4599
    "/ if the padding is not supported: fail
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4600
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4601
    dDev := aDevice depth.
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4602
    (bytesPerLine := dDev) == 8 ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4603
        bytesPerLine := (w * dDev + 7) // 8.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4604
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4605
2532
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
  4606
    fmt := aDevice supportedImageFormatForDepth:dDev.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4607
    fmt isNil ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4608
        "/ cannot draw directly
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4609
        ^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4610
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4611
    (bytesPerLine * 8) \\ (fmt at:#padding) == 0 ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4612
        "/ mhmh - ought to repad here;
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4613
        "/ however, the nonQuick converter does it.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4614
        ^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4615
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4616
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4617
    "/ see if all of the images colors are representable
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4618
    "/ on the device
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4619
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4620
    bits := self bitsPerPixel.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4621
    nClr := (1 bitShift:bits).
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4622
    cMap := Array new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4623
    idMap := ByteArray new:nClr.
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
    photometric == #palette ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4626
        nClr := nClr min:(colorMap size)
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4627
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4628
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  4629
    d == 8 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4630
        usedColors := bytes usedValues.    "gets us an array filled with used values"
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4631
        1 to:nClr do:[:pixel |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4632
            (usedColors includes:(pixel - 1)) ifFalse:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4633
                clr := Color black
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4634
            ] ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4635
                clr := self colorFromValue:pixel-1.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4636
                clr := clr exactOn:aDevice.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4637
                clr isNil ifTrue:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4638
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4639
            (pix := clr colorId) isNil ifTrue:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4640
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4641
            cMap at:(pixel) put:clr.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4642
            idMap at:(pixel) put:pix.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4643
        ].
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  4644
    ] ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4645
        1 to:nClr do:[:pixel |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4646
            clr := self colorFromValue:pixel-1.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4647
            clr := clr exactOn:aDevice.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4648
            clr isNil ifTrue:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4649
            (pix := clr colorId) isNil ifTrue:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4650
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4651
            cMap at:(pixel) put:clr.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4652
            idMap at:(pixel) put:pix.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4653
        ].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4654
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4655
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4656
    "/ got all colors; good - simply change depth & translate pixels
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4657
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4658
    (d == 8 and:[dDev == 8]) ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4659
        "/ only translate
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4660
        temp := ByteArray uninitializedNew:(w * h).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4661
        bytes expandPixels:8         "xlate only"
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4662
                    width:w
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4663
                   height:h
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4664
                     into:temp
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4665
                  mapping:idMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4666
    ] ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4667
        "/ stupid: expandPixels can only handle any-to-8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4668
        "/ compressPixels can only handle 8-to-any
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4669
        "/ However, those methods are faster
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4670
        "/ - even if we convert twice.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4671
        "/ Therefore, convert first from myDepth to 8,
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4672
        "/ then from 8 to the device depth.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4673
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4674
        d ~~ 8 ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4675
            temp8 := ByteArray uninitializedNew:(w * h).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4676
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4677
            bytes expandPixels:d
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4678
                         width:w
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4679
                        height:h
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4680
                          into:temp8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4681
                       mapping:idMap.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4682
            idMap := nil.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4683
        ] ifFalse:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4684
            temp8 := bytes.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4685
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4686
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4687
        dDev ~~ 8 ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4688
            temp := ByteArray uninitializedNew:(bytesPerLine * h).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4689
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4690
            temp8 compressPixels:dDev
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4691
                         width:w
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4692
                        height:h
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4693
                          into:temp
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4694
                       mapping:idMap.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4695
        ] ifFalse:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4696
            temp := temp8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4697
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4698
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4699
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4700
    f := Form width:w height:h depth:dDev onDevice:aDevice.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4701
    f isNil ifTrue:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4702
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4703
    f colorMap:cMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4704
    f initGC.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4705
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4706
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4707
        drawBits:temp
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4708
        depth:dDev
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4709
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4710
        width:w
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4711
        height:h
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4712
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4713
        into:(f id) x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4714
        width:w
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4715
        height:h
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4716
        with:(f gcId).
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4717
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4718
    ^ f
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4719
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4720
    "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4721
     (
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4722
        (((Depth4Image
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4723
             width:4
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4724
             height:4
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4725
             fromArray:#[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4726
                            16r01 16r23
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4727
                            16r45 16r67
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4728
                            16r89 16rab
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4729
                            16rcd 16ref
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4730
                        ]))
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4731
               magnifiedBy:30
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4732
         )
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4733
          asPseudoFormQuickOn:Display
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4734
      ) inspect
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4735
     "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4736
2113
c64f89f9ffba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2102
diff changeset
  4737
    "Modified: / 7.5.1998 / 19:40:47 / cg"
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4738
!
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4739
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4740
asStevensonArceDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4741
    "return a stevenson-arce dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4742
     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
  4743
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4744
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4745
     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
  4746
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4747
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4748
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4749
    monoBits := self stevensonArceDitheredMonochromeBits.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4750
    ^ (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
  4751
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4752
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4753
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4754
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4755
     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
  4756
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4757
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4758
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4759
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4760
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4761
    "
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
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4764
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4765
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4766
     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
  4767
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4768
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4769
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4770
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4771
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4772
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4773
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4774
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4775
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4776
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4777
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4778
	     width:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4779
	     height:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4780
	     fromArray:#[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4781
			    16r01 16r23
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4782
			    16r45 16r67
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4783
			    16r89 16rab
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4784
			    16rcd 16ref
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4785
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4786
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4787
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4788
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4789
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4790
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4791
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4792
    "Created: 10.6.1996 / 12:38:29 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4793
    "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
  4794
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4795
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4796
asThresholdGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4797
    "return a thresholded grey form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4798
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4799
    |depth|
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
    (depth := aDevice depth) == 1 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4802
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4803
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4804
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4805
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4806
	makeDeviceGrayPixmapOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4807
	depth:depth
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4808
	fromArray:(self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4809
			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
  4810
			ditherWidth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4811
			depth:depth)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4812
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4813
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4814
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4815
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4816
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4817
     (i asThresholdGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4818
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4819
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4820
    "Created: 10.6.1996 / 18:38:31 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4821
    "Modified: 24.6.1997 / 22:19:46 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4822
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4823
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4824
asThresholdGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4825
    "return a thresholded depth-x grey image from the receiver image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4826
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4827
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4828
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4829
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4830
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4831
	^ Depth1Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4832
	    width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4833
	    height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4834
	    fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4835
		self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4836
		    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
  4837
		    ditherWidth:4)
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4838
    ].
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4839
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4840
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4841
	width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4842
	height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4843
	fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4844
	    self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4845
		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
  4846
		ditherWidth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4847
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4848
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4849
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4850
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4851
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4852
     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
  4853
     (i asThresholdGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4854
     (i asThresholdGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4855
     (i asThresholdGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4856
     (i asThresholdGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4857
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4858
     (i asOrderedDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4859
     (i asOrderedDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4860
     (i asOrderedDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4861
     (i asOrderedDitheredGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4862
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4863
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4864
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4865
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4866
     (i asFloydSteinbergDitheredGrayImageDepth:8) inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4867
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4868
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4869
    "Created: 7.6.1996 / 18:13:33 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4870
    "Modified: 24.6.1997 / 22:19:52 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4871
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4872
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4873
asThresholdMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4874
    "return a threshold monochrome form from the image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4875
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4876
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4877
	asOrderedDitheredMonochromeFormOn:aDevice
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4878
	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
  4879
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4880
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4881
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4882
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4883
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4884
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4885
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4886
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4887
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4888
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4889
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4890
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4891
     i := (Image fromFile:'goodies/bitmaps/a11.ico') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4892
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4893
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4894
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4895
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4896
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4897
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4898
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4899
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4900
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4901
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4902
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4903
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4904
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4905
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4906
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4907
     (i asThresholdMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4908
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4909
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4910
    "Created: 7.6.1996 / 16:15:17 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4911
    "Modified: 10.6.1996 / 17:44:29 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4912
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4913
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4914
asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4915
    "return a threshold monochrome image from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4916
     Threshold means: brightness < 0.5 -> black / otherwise white"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4917
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4918
    ^ self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4919
	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
  4920
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4921
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4922
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4923
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4924
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4925
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4926
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4927
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4928
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4929
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4930
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4931
     i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4932
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4933
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4934
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4935
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4936
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4937
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4938
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4939
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4940
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4941
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4942
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4943
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4944
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4945
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4946
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4947
    "Created: 7.6.1996 / 16:15:17 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4948
    "Modified: 7.6.1996 / 17:16:10 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4949
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4950
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4951
asThresholdMonochromeImage:thresholdBrighness
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4952
    "return a threshold monochrome image from the image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4953
     The argument (0..1) gives the threshold value;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4954
     Threshold means: brightness < threshold -> black / otherwise white"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4955
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4956
    |value ditherMatrix|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4957
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4958
    value := thresholdBrighness * 255.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4959
    ditherMatrix := ByteArray new:256 withAll:(value truncated).
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4960
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4961
    ^ self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4962
	asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4963
	ditherWidth:16
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4964
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4965
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4966
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4967
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4968
     i := Image width:4 height:4 depth:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4969
		fromArray:#[ 16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4970
			     16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4971
			     16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4972
			     16rcd 16ref ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4973
     i := i magnifiedBy:30.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4974
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4975
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4976
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4977
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4978
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4979
     (i asThresholdMonochromeImage:1) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4980
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4981
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4982
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4983
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4984
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4985
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4986
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4987
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4988
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4989
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4990
     (i asThresholdMonochromeImage:0.625) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4991
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4992
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4993
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4994
    "Created: 7.6.1996 / 16:15:17 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4995
    "Modified: 8.6.1996 / 14:51:57 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4996
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4997
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4998
clearMaskedPixels
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  4999
    "assuming that I already have a device representation
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5000
     in deviceForm, clear any masked pixels.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5001
     This will allow faster drawing in the future."
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5002
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5003
    maskedPixelsAre0 == true ifTrue:[^ self].   "/ already cleared
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5004
    mask isNil ifTrue:[^ self].         "/ no mask
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5005
    deviceForm isNil ifTrue:[^ self].   "/ no device rep.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5006
    mask depth ~~ 1 ifTrue:[^ self].    "/ not done with alpha masks
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5007
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5008
    deviceForm foreground:Color allColor background:Color noColor.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5009
    deviceForm function:#and.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5010
    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
  5011
    maskedPixelsAre0 := true.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5012
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5013
    "Created: 12.4.1997 / 12:18:05 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5014
    "Modified: 12.4.1997 / 12:20:19 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5015
!
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5016
3104
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5017
exactOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5018
    "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
  5019
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5020
    ^ self onDevice:aDevice
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5021
!
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5022
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5023
exactOrNearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5024
    "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
  5025
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5026
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5027
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5028
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5029
fromForm:aForm
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5030
    "setup the receiver from a form"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5031
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5032
    |map c0 c1|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5033
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5034
    width := aForm width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5035
    height := aForm height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5036
    bitsPerSample := self bitsPerSample.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5037
    samplesPerPixel := self samplesPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5038
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5039
    aForm hasBits ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5040
	"/ must read the data from the device
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5041
	self from:aForm in:(0@0 extent:aForm extent).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5042
	^ self
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5043
    ].
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5044
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5045
    "/ the form has all data available
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5046
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5047
    self bits:(aForm bits).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5048
    map := aForm colorMap.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5049
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5050
    aForm depth == 1 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5051
	map isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5052
	    photometric := #whiteIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5053
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5054
	    c0 := map at:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5055
	    c1 := map at:2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5056
	    ((c0 = Color white)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5057
	    and:[c1 = Color black]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5058
		photometric := #whiteIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5059
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5060
		((c0 = Color black)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5061
		and:[c1 = Color white]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5062
		    photometric := #blackIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5063
		] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5064
		    photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5065
		    self setColorMap:(Array with:c0 with:c1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5066
		]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5067
	    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5068
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5069
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5070
	map notNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5071
	    photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5072
	    self setColorMap:(map copy).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5073
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5074
	    "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5075
	     photometric stays at default
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5076
	     (which is rgb for d24, greyscale for others)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5077
	    "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5078
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5079
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5080
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5081
    "Modified: 5.7.1996 / 16:24:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5082
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5083
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5084
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5085
    "setup the receiver from another image.
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5086
     Color precision may be lost, if conversion is from a higher depth image.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5087
     WARNING:
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5088
     This implementation is a slow fallback (the loop over the
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5089
     source pixels is very slow). If this method is used heavily, you
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5090
     may want to redefine it in concrete subclasses for common source images."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5091
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5092
    ^ 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
  5093
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5094
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5095
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5096
    "setup the receiver from another image and optionally set the photometric.
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5097
     Color precision may be lost, if conversion is from a higher depth image.
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5098
     WARNING:
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5099
     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
  5100
     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
  5101
     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
  5102
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5103
    |map clr mappedRowPixels samePhotometric
1784
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5104
     h "{ Class: SmallInteger }"
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5105
     w "{ Class: SmallInteger }"|
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5106
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5107
    width := anImage width.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5108
    height := anImage height.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5109
    bitsPerSample := self bitsPerSample.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5110
    samplesPerPixel := self samplesPerPixel.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5111
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5112
    photometricOrNil isNil ifTrue:[
4893
137719991c5a defaultPhotometric in #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 4888
diff changeset
  5113
        photometric := self class defaultPhotometric
137719991c5a defaultPhotometric in #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 4888
diff changeset
  5114
        "/ photometric := anImage photometric
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5115
    ] ifFalse:[
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5116
        photometric := photometricOrNil
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5117
    ].
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5118
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5119
    photometric == #palette ifTrue:[
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5120
        self colormapFromImage:anImage photometric:photometric.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5121
    ].
1374
ab515c0576c6 preserve mask when creating an image from another image.
Claus Gittinger <cg@exept.de>
parents: 1362
diff changeset
  5122
    self mask:anImage mask.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5123
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5124
    samePhotometric := (photometric == anImage photometric).
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5125
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5126
    ((self depth = anImage depth)
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5127
    and:[samePhotometric]) ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5128
        self bits:(anImage bits copy).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5129
        ^ self.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5130
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5131
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5132
    self bits:(ByteArray uninitializedNew:(self bytesPerRow * height)).
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5133
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5134
    self depth >= anImage depth ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5135
        anImage depth <= 12 ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5136
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5137
            "/ if my depth is greater, all colors can be represented,
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5138
            "/ and the loop can be done over pixel values ...
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5139
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5140
            (colorMap isNil or:[samePhotometric not]) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5141
                map := Array new:(1 bitShift:anImage depth).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5142
                1 to:map size do:[:i |
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5143
                    clr := anImage colorFromValue:(i - 1).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5144
                    map at:i put:(self valueFromColor:clr).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5145
                ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5146
            ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5147
            mappedRowPixels := self pixelArraySpecies new:width.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5148
            h := height-1.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5149
            w := width.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5150
            0 to:h do:[:row |
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5151
                anImage rowAt:row into:mappedRowPixels startingAt:1.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5152
                map notNil ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5153
                    1 to:w do:[:i |
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5154
                        mappedRowPixels at:i put:(map at:(mappedRowPixels at:i)+1)
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5155
                    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5156
                ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5157
                self rowAt:row putAll:mappedRowPixels
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5158
            ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5159
            ^ self
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5160
        ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5161
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5162
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5163
    anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr |
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5164
        self colorAtX:x y:y put:clr
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5165
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5166
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5167
    "
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5168
     |i i2 i4 i8 i16 i24|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5169
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5170
     i := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5171
     i inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5172
     i2 := Depth2Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5173
     i2 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5174
     i4 := Depth4Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5175
     i4 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5176
     i8 := Depth8Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5177
     i8 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5178
     i24 := Depth24Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5179
     i24 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5180
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5181
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5182
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5183
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5184
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5185
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5186
     Transcript showCR:(
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5187
        Time millisecondsToRun:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5188
            i24 := Depth24Image fromImage:i.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5189
        ]
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5190
     ).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5191
     i24 inspect.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5192
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5193
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5194
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5195
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5196
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5197
     MessageTally spyOn:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5198
        i24 := Depth24Image fromImage:i.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5199
     ]
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5200
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5201
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5202
    "Modified: / 05-06-2007 / 23:56:52 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5203
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5204
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5205
fromSubImage:anImage in:aRectangle
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5206
    "setup the receiver from another image, extracting a rectangular
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5207
     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
  5208
     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
  5209
     represented.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5210
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5211
     WARNING:
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5212
       This implementation is a slow fallback (the loop over the
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5213
       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
  5214
       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
  5215
       of creating a subImage with the same depth & palette."
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5216
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5217
    |xL yT xR yB maskClass|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5218
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5219
    width := aRectangle width.
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5220
    height := aRectangle height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5221
    self createPixelStore.
3458
b2e098e6288b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3457
diff changeset
  5222
    depth := self depth.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5223
    bitsPerSample := self bitsPerSample.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5224
    bitsPerPixel := self bitsPerPixel.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5225
    samplesPerPixel := self samplesPerPixel.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5226
    self colormapFromImage:anImage.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5227
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5228
    xL := aRectangle left.
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5229
    yT := aRectangle top.
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5230
    xR := xL + aRectangle width - 1.
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5231
    yB := yT + aRectangle height - 1.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5232
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5233
    ((photometric == anImage photometric)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5234
    and:[self bitsPerPixel = anImage bitsPerPixel
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5235
    and:[colorMap = anImage colorMap]]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5236
	"/ can do it by value
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5237
	anImage
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5238
	    valuesFromX:xL y:yT toX:xR y:yB
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5239
	    do:[:x :y :pixelValue |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5240
		    self pixelAtX:x-xL y:y-yT put:pixelValue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5241
	       ]
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5242
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5243
	"/ must do it by colors
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5244
	anImage
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5245
	    colorsFromX:xL y:yT toX:xR y:yB
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5246
	    do:[:x :y :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5247
		    self colorAtX:x-xL y:y-yT put:clr.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5248
	       ]
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5249
    ].
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5250
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5251
    anImage mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5252
	anImage mask depth == 1 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5253
	    maskClass := ImageMask
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5254
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5255
	    maskClass := anImage mask class.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5256
	].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5257
	mask := maskClass new
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5258
		    fromSubImage:anImage mask in:aRectangle
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5259
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5260
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5261
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5262
     |i i2 i4 i8 i16 i24|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5263
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5264
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5265
     i inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5266
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5267
     i4 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5268
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5269
     i8 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5270
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5271
     i24 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5272
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5273
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5274
    "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
  5275
    "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
  5276
    "Modified: / 18.5.1999 / 20:06:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5277
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5278
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5279
monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5280
    "return a monochrome device image of the receiver for aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5281
     (monochrome, even if device supports colors)"
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
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5284
    (device notNil and:[aDevice ~~ device]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5285
	"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
  5286
	 - need a copy ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5287
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5288
	^ self copy monochromeOn:aDevice
283
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
    monoDeviceForm := self asMonochromeFormOn:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5291
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5292
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5293
nearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5294
    "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
  5295
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5296
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5297
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5298
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5299
on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5300
    "return an image with the same pixels as the receiver, but
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5301
     associated to aDevice. If the receiver is not yet bound to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5302
     a device, this will be the receiver. Otherwise, a new image
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5303
     is returned."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5304
3623
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5305
    "/ send out a warning: #on: is typically used to create views
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5306
    "/ operating on a model.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5307
    "/ Please use #onDevice: to avoid confusion.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5308
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5309
    <resource:#obsolete>
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5310
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5311
    self obsoleteMethodWarning:'use #onDevice:'.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5312
    ^ self onDevice:aDevice
1496
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5313
!
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5314
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5315
onDevice:aDevice
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5316
    "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
  5317
     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
  5318
     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
  5319
     is returned."
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5320
2980
409e9547a45c ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  5321
    aDevice isNil ifTrue:[^ self].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5322
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5323
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5324
    (device notNil and:[aDevice ~~ device]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5325
	"oops, I am already accociated to another device
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5326
	 - need a copy ...
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5327
	"
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5328
	^ self copy onDevice:aDevice
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5329
    ].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5330
    deviceForm := self asFormOn:aDevice.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5331
    maskedPixelsAre0 := nil.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5332
    device := aDevice.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5333
    Lobby register:self
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5334
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5335
    "Modified: / 22.8.1998 / 13:34:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5336
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5337
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5338
!Image methodsFor:'converting greyscale images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5339
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5340
greyImageAsFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5341
    "return a grey-deviceForm from the grey image."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5342
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5343
    |pictureDepth nPlanes|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5344
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5345
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5346
    nPlanes := samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5347
    (nPlanes == 2) ifTrue:[
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
  5348
        'Image [info]: alpha plane ignored' infoPrintCR.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  5349
    ].
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  5350
    "/ first plane only
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5351
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5352
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5353
    "monochrome is very easy ..."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5354
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5355
    (pictureDepth == 1) ifTrue:[
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
  5356
        ^ Form width:width height:height fromArray:self bits onDevice:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5357
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5358
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5359
    (aDevice visualType == #TrueColor) ifTrue:[
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
  5360
        ^ self greyImageAsTrueColorFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5361
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5362
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5363
    "/ PseudoColor conversion also works for StaticColor,
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5364
    "/ GrayScale and DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5365
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5366
    ^ self greyImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5367
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5368
    "Modified: 19.10.1997 / 05:17:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5369
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5370
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5371
greyImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5372
    "return an 8-bit pseudo Form from the grey image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5373
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5374
    |wideBits pictureDepth f map
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5375
     colorMap usedColors nUsed aColor
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5376
     nColors "{ Class: SmallInteger }"
1766
08b918d293a6 fixed conversion of greyScale images with colorCube
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
  5377
     range id
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5378
     cube nR nG nB grayColors
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5379
     fit|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5380
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5381
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5382
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5383
    (#(2 4 8) includes:pictureDepth) ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5384
        self error:'currently only depth-2, 4 or 8 supported'.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5385
        ^ nil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5386
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5387
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5388
    wideBits := ByteArray uninitializedNew:(width * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5389
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5390
    (pictureDepth == 8) ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5391
        "for 8bits, we scan for used colors first;
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5392
         to avoid allocating too many colors"
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5393
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5394
        (grayColors := aDevice fixGrayColors) notNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5395
            DitherAlgorithm == #floydSteinberg ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5396
                f := self
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5397
                       asFloydSteinbergDitheredDepth8FormOn:aDevice
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5398
                       colors:grayColors
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5399
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5400
            f notNil ifTrue:[^ f].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5401
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5402
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5403
        (cube := aDevice fixColors) notNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5404
            nR := aDevice numFixRed.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5405
            nG := aDevice numFixGreen.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5406
            nB := aDevice numFixBlue.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5407
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5408
            DitherAlgorithm == #floydSteinberg ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5409
                f := self
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5410
                       asFloydSteinbergDitheredDepth8FormOn:aDevice
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5411
                       colors:cube
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5412
                       nRed:nR
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5413
                       nGreen:nG
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5414
                       nBlue:nB.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5415
            ] ifFalse:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5416
                f := self
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5417
                       asNearestPaintDepth8FormOn:aDevice
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5418
                       colors:cube
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5419
                       nRed:nR
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5420
                       nGreen:nG
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5421
                       nBlue:nB.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5422
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5423
            f notNil ifTrue:[^ f].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5424
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5425
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5426
        usedColors := self bits usedValues.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5427
        nUsed := usedColors max + 1.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5428
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5429
        colorMap := Array new:nUsed.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5430
        range := 100 / 255.0.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5431
        usedColors do:[:grey |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5432
            colorMap at:(grey + 1) put:(Color gray:(range * grey))
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5433
        ].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5434
    ] ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5435
        nColors := (1 bitShift:pictureDepth).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5436
        colorMap := Array new:nColors.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5437
        range := 100 / (nColors - 1) asFloat.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5438
        1 to:nColors do:[:i |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5439
            colorMap at:i put:(Color gray:(i - 1) * range).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5440
        ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5441
    ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5442
    photometric ~~ #blackIs0 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5443
        colorMap reverse
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5444
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5445
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5446
    "allocate those colors & setup the translation map"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5447
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5448
    fit := true.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5449
    map := ByteArray uninitializedNew:256.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5450
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5451
    1 to:nColors do:[:i |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5452
        aColor := colorMap at:i.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5453
        aColor notNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5454
            aColor := aColor onDevice:aDevice.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5455
            colorMap at:i put:aColor.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5456
            id := aColor colorId.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5457
            id isNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5458
                id := 0.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5459
                fit := false.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5460
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5461
            map at:i put:id
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5462
        ]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5463
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5464
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5465
    fit ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5466
        "/ here comes the hard part - some grey value
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5467
        "/ could not be allocated.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5468
        "/ Must dither.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5469
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5470
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5471
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5472
    "expand & translate"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5473
    self bits
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5474
        expandPixels:pictureDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5475
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5476
        into:wideBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5477
        mapping:map.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5478
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5479
    f := Form width:width height:height depth:8 onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5480
    f isNil ifTrue:[^ nil].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5481
    f colorMap:colorMap.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5482
    f initGC.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5483
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5484
        drawBits:wideBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5485
        depth:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5486
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5487
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5488
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5489
        into:(f id)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5490
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5491
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5492
        with:(f gcId).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5493
    ^ f
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  5494
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5495
    "Modified: 19.10.1997 / 05:19:44 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5496
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5497
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5498
greyImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5499
    "return a true-color device-form for the grey-image receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5500
     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
  5501
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5502
    |depth
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5503
     myDepth    "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5504
     nColors    "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5505
     colorValues
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5506
     scaleDown
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5507
     scaleRed   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5508
     scaleGreen "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5509
     scaleBlue  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5510
     redShift   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5511
     blueShift  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5512
     greenShift "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5513
     form bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  5514
     greyValue  "{ Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5515
     h          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5516
     w          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5517
     pixelArray newPixelArray i|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5518
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5519
    "/ this is a slow fallback method; this ought to be
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5520
    "/ redefined in DepthxImage for more performance.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5521
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5522
    depth := aDevice depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5523
    myDepth := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5524
    myDepth > 12 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5525
        self error:'unsupported trueColor depth in greyImageAsTrueColorFormOn:'.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5526
        ^ nil
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5527
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  5528
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5529
    "/ compute scale to map from my pixels into devices range
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5530
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5531
    scaleDown := 1 bitShift:myDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5532
    scaleRed := (1 bitShift:aDevice bitsRed).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5533
    scaleGreen := (1 bitShift:aDevice bitsGreen).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5534
    scaleBlue := (1 bitShift:aDevice bitsBlue).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5535
    redShift := aDevice shiftRed.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5536
    greenShift := aDevice shiftGreen.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5537
    blueShift := aDevice shiftBlue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5538
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5539
    "/ prepare the map
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5540
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5541
    nColors := (1 bitShift:myDepth).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5542
    colorValues := Array new:nColors.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5543
    1 to:nColors do:[:i |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5544
        |v gv bv rv nv|
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5545
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5546
        "/ scale down to 0..1
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5547
        v := (i-1) / scaleDown.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5548
        rv := (v * scaleRed) truncated.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5549
        gv := (v * scaleGreen) truncated.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5550
        bv := (v * scaleBlue) truncated.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5551
        nv := rv bitShift:redShift.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5552
        nv := nv bitOr:(gv bitShift:greenShift).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5553
        nv := nv bitOr:(bv bitShift:blueShift).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5554
        colorValues at:i put:nv
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5555
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5556
    photometric == #whiteIs0 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5557
        "/ reverse the order; 0 is brightest
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5558
        colorValues reverse
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5559
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5560
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5561
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5562
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5563
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5564
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5565
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5566
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5567
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  5568
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  5569
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5570
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5571
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5572
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5573
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5574
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5575
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5576
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5577
    w := width - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5578
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5579
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5580
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5581
    0 to:h do:[:y |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5582
        self rowAt:y into:pixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5583
        0 to:w do:[:x |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5584
            greyValue := pixelArray at:(x+1).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5585
            newPixelArray at:(x+1) put:(colorValues at:greyValue + 1).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5586
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5587
        i rowAt:y putAll:newPixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5588
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5589
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5590
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5591
    form isNil ifTrue:[^ nil].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5592
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5593
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5594
    form
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5595
        copyBitsFrom:imageBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5596
        bitsPerPixel:usedDeviceBitsPerPixel
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5597
        depth:usedDeviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5598
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5599
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5600
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5601
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5602
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5603
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5604
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5605
    "Created: 20.10.1995 / 22:05:10 / cg"
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  5606
    "Modified: 24.4.1997 / 23:11:16 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5607
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  5608
48194c26a46c Initial revision
claus
parents:
diff changeset
  5609
!Image methodsFor:'converting palette images'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5610
48194c26a46c Initial revision
claus
parents:
diff changeset
  5611
paletteImageAsFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  5612
    "return a device-form for the palette-image receiver"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  5613
380
c5ffc6d48a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
  5614
    |type ddepth|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5615
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5616
    ddepth := aDevice depth.
379
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  5617
3940
b1b7dc76d7d7 not ifTrue -> ifFalse
Claus Gittinger <cg@exept.de>
parents: 3939
diff changeset
  5618
    aDevice hasGrayscales ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5619
	^ self asMonochromeFormOn:aDevice
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5620
    ].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5621
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5622
    ((type := aDevice visualType) == #StaticGray) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5623
	ddepth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5624
	    ^ self paletteImageAsGray8FormOn:aDevice
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5625
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5626
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5627
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5628
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5629
    (type == #TrueColor) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5630
	DitherAlgorithm == #floydSteinberg ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5631
	    ddepth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5632
		self depth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5633
		    "/ use fixColor dither algorithm
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5634
		    ^ self asDitheredTrueColor8FormOn:aDevice
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5635
		]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5636
	    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5637
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5638
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5639
	^ self paletteImageAsTrueColorFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5640
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5641
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5642
    "/ the PseudoColor conversion also works for
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5643
    "/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5644
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5645
    ^ self paletteImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5646
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5647
    "Modified: 14.6.1996 / 19:31:01 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5648
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5649
48194c26a46c Initial revision
claus
parents:
diff changeset
  5650
paletteImageAsPseudoFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  5651
    "return a pseudo-deviceForm from the palette image."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5652
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5653
    |tempImage d temp8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5654
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5655
    d := self depth.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5656
    (#(1 2 4 8) includes:d) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5657
	"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5658
	 fallback code for some depth's:
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5659
	 create a temporary Depth8Image and use its conversion method
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5660
	"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5661
	temp8 := ByteArray uninitializedNew:(width * height).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5662
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5663
	self bits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5664
	    expandPixels:d
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5665
	    width:width height:height
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5666
	    into:temp8
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5667
	    mapping:nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5668
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5669
	tempImage := Image width:width height:height depth:8 fromArray:temp8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5670
	tempImage colorMap:colorMap.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5671
	^ tempImage paletteImageAsPseudoFormOn:aDevice
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5672
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  5673
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5674
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5675
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5676
paletteImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5677
    "return a true-color device-form for the palette-image receiver."
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5678
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5679
    |depth
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  5680
     nColors "{ Class: SmallInteger }"
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  5681
     h       "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  5682
     pixel   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5683
     colorValues
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5684
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5685
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5686
     i pixelArray newPixelArray
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5687
     clr r g b rv gv bv v "{ Class: SmallInteger }" |
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5688
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5689
    "/ this is a slow fallback method; this ought to be
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5690
    "/ redefined in DepthxImage for more performance.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5691
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5692
    depth := aDevice depth.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5693
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5694
    bestFormat := self bestSupportedImageFormatFor:aDevice.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5695
    usedDeviceDepth := bestFormat at:#depth.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5696
    usedDeviceDepth == 1 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5697
        ^ self asMonochromeFormOn:aDevice.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5698
    ].
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5699
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5700
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5701
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5702
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5703
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5704
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 255.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5705
    redShift := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5706
    greenShift := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5707
    blueShift := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5708
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5709
    nColors := colorMap size.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5710
    nColors <= 4096 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5711
        "/ precompute scales to map from 0..100 into devices range
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5712
        "/ (this may be different for the individual components)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5713
        colorValues := Array uninitializedNew:nColors.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5714
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5715
        1 to:nColors do:[:index |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5716
            r := colorMap redByteAt:index.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5717
            g := colorMap greenByteAt:index.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5718
            b := colorMap blueByteAt:index.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5719
"/        clr := colorMap at:index.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5720
            true "clr notNil" ifTrue:[
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5721
"/            r := clr red.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5722
"/            g := clr green.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5723
"/            b := clr blue.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5724
                rv := (r * scaleRed) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5725
                gv := (g * scaleGreen) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5726
                bv := (b * scaleBlue) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5727
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5728
                v := rv bitShift:redShift.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5729
                v := v bitOr:(gv bitShift:greenShift).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5730
                v := v bitOr:(bv bitShift:blueShift).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5731
                colorValues at:index put:v.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5732
"/ clr print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5733
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5734
"/ ' -> ' print. v printNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5735
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5736
            ]
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5737
        ].
2864
dd151bfdff9d care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents: 2832
diff changeset
  5738
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5739
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5740
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5741
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5742
1665
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  5743
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  5744
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5745
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5746
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5747
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5748
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5749
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5750
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5751
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5752
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5753
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5754
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5755
    colorValues notNil ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5756
        0 to:h do:[:y |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5757
            self rowAt:y into:pixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5758
            1 to:width do:[:x |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5759
                pixel := pixelArray at:x.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5760
                newPixelArray at:x put:(colorValues at:pixel + 1).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5761
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5762
            i rowAt:y putAll:newPixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5763
        ].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5764
    ] ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5765
        0 to:h do:[:y |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5766
            self rowAt:y into:pixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5767
            1 to:width do:[:x |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5768
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5769
                pixel := pixelArray at:x.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5770
                clr := self colorFromValue:pixel.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5771
                r := clr redByte.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5772
                g := clr greenByte.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5773
                b := clr blueByte.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5774
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5775
                rv := (r * scaleRed) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5776
                gv := (g * scaleGreen) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5777
                bv := (b * scaleBlue) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5778
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5779
                v := rv bitShift:redShift.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5780
                v := v bitOr:(gv bitShift:greenShift).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5781
                v := v bitOr:(bv bitShift:blueShift).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5782
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5783
                newPixelArray at:x put:v.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5784
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5785
            i rowAt:y putAll:newPixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5786
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5787
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5788
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5789
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5790
    form isNil ifTrue:[^ nil].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5791
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5792
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5793
    form
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5794
        copyBitsFrom:imageBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5795
        bitsPerPixel:usedDeviceBitsPerPixel
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5796
        depth:usedDeviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5797
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5798
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5799
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5800
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5801
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5802
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5803
2185
756d58c52113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2182
diff changeset
  5804
    "Modified: / 24.7.1998 / 00:56:14 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5805
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  5806
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5807
!Image methodsFor:'converting rgb images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5808
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5809
asDitheredTrueColor8FormOn:aDevice
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5810
    "convert an rgb image to a dithered depth8-form on aDevice.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5811
     Return the device-form.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  5812
     This method is only valid for trueColor displays."
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5813
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5814
    |fixColors pixel
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5815
     dstIdx     "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5816
     shiftRed   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5817
     shiftGreen "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5818
     shiftBlue  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5819
     nRed    "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5820
     nGreen  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5821
     nBlue   "{ Class: SmallInteger }"|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5822
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5823
    shiftRed := aDevice shiftRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5824
    shiftGreen := aDevice shiftGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5825
    shiftBlue := aDevice shiftBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5826
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5827
    nRed := (1 bitShift:aDevice bitsRed).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5828
    nGreen := (1 bitShift:aDevice bitsGreen).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5829
    nBlue := (1 bitShift:aDevice bitsBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5830
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5831
    fixColors := Array new:(nRed * nGreen * nBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5832
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5833
    dstIdx := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5834
    0 to:nRed - 1 do:[:sR |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5835
	0 to:nGreen - 1 do:[:sG |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5836
	    0 to:nBlue - 1 do:[:sB |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5837
		pixel := (sR bitShift:shiftRed)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5838
			 + (sG bitShift:shiftGreen)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5839
			 + (sB bitShift:shiftBlue).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5840
		fixColors at:dstIdx put:(Color colorId:(pixel)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5841
		dstIdx := dstIdx + 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5842
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5843
	]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5844
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5845
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5846
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5847
	asFloydSteinbergDitheredDepth8FormOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5848
	colors:fixColors
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5849
	nRed:nRed nGreen:nGreen nBlue:nBlue
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  5850
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5851
    "Created: 14.6.1996 / 17:23:52 / cg"
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  5852
    "Modified: 23.6.1997 / 15:22:36 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5853
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5854
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5855
rgbImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5856
    "convert am rgb image to a device-form on aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5857
     Return the device-form."
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
    |visual|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5860
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5861
    visual := aDevice visualType.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5862
    (visual == #StaticGray) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5863
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5864
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5865
    (visual == #TrueColor) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5866
	^ self rgbImageAsTrueColorFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5867
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5868
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5869
    "/ PseudoColor conversion also works for StaticColor, GrayScale
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5870
    "/ and DirectColor displays; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5871
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5872
    ^ self rgbImageAsPseudoFormOn:aDevice
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5873
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5874
    "Modified: 14.6.1996 / 19:30:06 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5875
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5876
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5877
rgbImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5878
    "return a pseudocolor form from the rgb-picture"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5879
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5880
    |n     "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5881
     depth "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5882
     palette f|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5883
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5884
    (depth := self depth) <= 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5885
	"/ simulate it via a temporary palette image
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5886
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5887
	palette := Array new:(1 bitShift:depth).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5888
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5889
	n := (1 bitShift:depth)-1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5890
	0 to:n do:[:pixelValue |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5891
	    palette at:(pixelValue+1) put:(self colorFromValue:pixelValue)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5892
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5893
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5894
	self setColorMap:palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5895
	photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5896
	f := self paletteImageAsPseudoFormOn:aDevice.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5897
	self setColorMap:nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5898
	photometric := #rgb.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5899
	^ f
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5900
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5901
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5902
    ^ self subclassResponsibility
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5903
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  5904
    "Modified: 8.6.1996 / 10:58:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5905
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5906
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5907
rgbImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5908
    "return a truecolor form from the rgb-picture."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5909
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5910
    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5911
     form|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5912
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5913
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5914
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5915
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5916
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5917
    "/ 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
  5918
    usedDeviceBitsPerPixel == 15 ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5919
        usedDeviceBitsPerPixel := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  5920
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  5921
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5922
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5923
    "/ only the trivial case, where the depths match
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5924
    "/ is handled here; conversions are supposed to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5925
    "/ be done in concrete subclasses (see D24Image)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5926
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5927
    self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5928
        'Image [warning]: unimplemented trueColor depth in rgbImageAsTrueColorFormOn: ' errorPrint. self bitsPerPixel errorPrintCR.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5929
        ^ self asMonochromeFormOn:aDevice
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5930
    ].
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5931
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5932
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5933
    form isNil ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5934
        'Image [warning]: display bitmap creation failed' errorPrintCR.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5935
        ^ nil
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5936
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5937
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5938
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5939
    form
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5940
        copyBitsFrom:self bits
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5941
        bitsPerPixel:usedDeviceBitsPerPixel
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5942
        depth:usedDeviceDepth
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5943
        padding:8
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5944
        width:width height:height
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5945
        x:0 y:0
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5946
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5947
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5948
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5949
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  5950
    "Modified: / 27-05-2007 / 13:44:26 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5951
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5952
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5953
!Image methodsFor:'copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5954
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5955
postCopy
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5956
    "redefined to also copy the pixels and the colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5957
     and clear out any device handles in the copy."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5958
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5959
    bytes := bytes copy.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  5960
    (colorMap isNil or:[colorMap isKindOf:Colormap]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5961
	colorMap := MappedPalette withColors:colorMap.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  5962
    ] ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5963
	colorMap := colorMap copy.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  5964
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5965
    device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil.
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5966
    mask := mask copy.
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  5967
    maskedPixelsAre0 := false.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  5968
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  5969
    "Modified: / 22.8.1998 / 11:27:09 / cg"
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5970
!
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5971
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5972
skipInstvarIndexInDeepCopy:index
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5973
    "a helper for deepCopy; only indices for which this method returns
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5974
     false are copied in a deep copy."
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5975
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5976
    index == 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5977
	^ true "/ skip device
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5978
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5979
    index == 13 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5980
	^ true "/ skip deviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5981
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5982
    index == 14 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5983
	^ true "/ skip monoDeviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5984
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5985
    index == 15 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5986
	^ true "/ skip fullColorDeviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5987
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5988
    ^ false
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  5989
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5990
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5991
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  5992
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5993
!Image methodsFor:'displaying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5994
1737
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5995
asImage
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5996
    "ST-80 compatibility
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5997
    "
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5998
    ^ self
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  5999
!
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6000
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6001
displayFilledOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6002
    "display the receiver as an opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6003
     This allows Images to be wrapped by a FillingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6004
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6005
    aGC displayOpaqueForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6006
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6007
    "Created: 29.5.1996 / 10:34:18 / cg"
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6008
    "Modified: 29.5.1996 / 10:52:36 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6009
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6010
3865
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6011
displayOn:aGC x:x y:y
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6012
    "draw the receiver in the graphicsContext, aGC.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6013
     Smalltalk-80 compatibility"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6014
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6015
    aGC displayForm:self x:x y:y.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6016
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6017
    "Modified: 23.4.1996 / 11:12:31 / cg"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6018
    "Created: 12.5.1996 / 20:14:31 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6019
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6020
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6021
displayOn:aGC x:x y:y opaque:opaque
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6022
    "draw the receiver in the graphicsContext, aGC.
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6023
     Smalltalk-80 compatibility"
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6024
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6025
    opaque ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6026
	self displayOpaqueOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6027
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6028
	self displayOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6029
    ].
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6030
!
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6031
3379
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6032
displayOpaqueOn:aGC at:aPoint
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6033
    "draw the receiver in the graphicsContext, aGC.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6034
     Smalltalk-80 compatibility"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6035
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6036
    self displayOpaqueOn:aGC x:aPoint x y:aPoint y.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6037
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6038
    "Modified: 12.5.1996 / 20:16:38 / cg"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6039
!
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6040
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6041
displayOpaqueOn:aGC x:x y:y
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6042
    "draw the receiver in the graphicsContext, aGC.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6043
     Smalltalk-80 compatibility"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6044
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6045
    aGC displayOpaqueForm:self x:x y:y.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6046
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6047
    "Modified: 23.4.1996 / 11:12:31 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6048
    "Created: 22.10.1996 / 16:35:49 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6049
!
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6050
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6051
displayStrokedOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6052
    "display the receiver as an non opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6053
     This allows Images to be wrapped by a StrokingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6054
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6055
    aGC displayForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6056
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6057
    "Created: 29.5.1996 / 10:34:18 / cg"
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6058
    "Modified: 29.5.1996 / 10:52:30 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6059
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6060
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6061
!Image methodsFor:'dither helpers'!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6062
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6063
burkesDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6064
    "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
  6065
     Works for any source depths / photometric"
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
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6068
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6069
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6070
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6071
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6072
     errorArray1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6073
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6074
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6075
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6076
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6077
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6078
     grey|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6079
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6080
    self depth > 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6081
	^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6082
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6083
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6084
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6085
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6086
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6087
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6088
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6089
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6090
    errorArray := Array new:(w+4).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6091
    errorArray1 := Array new:(w+4) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6092
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6093
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6094
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6095
    "/ 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
  6096
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6097
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6098
    greyValues := self greyMapForRange:(255*1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6099
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6100
    0 to:(h-1) do:[:y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6101
	nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6102
	byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6103
	bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6104
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6105
	t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6106
	errorArray := errorArray1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6107
	errorArray1 := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6108
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6109
	errorArray1 atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6110
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6111
	self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6112
	    |eP "{Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6113
	     eD
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6114
	     eI "{Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6115
	     xE "{Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6116
	     xN "{Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6117
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6118
	    "/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6119
	    grey := greyValues at:(pixel + 1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6120
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6121
	    "/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6122
	    xE := x + 2 + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6123
	    grey := (grey + (errorArray at:xE)).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6124
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6125
	    byte := byte bitShift:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6126
	    grey > (127*1024) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6127
		byte := byte bitOr:1.      "/ white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6128
		e := grey - (255*1024)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6129
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6130
		e := grey                  "/ black
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6131
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6132
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6133
	    e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6134
		"/ distribute the error:
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6135
		"/                  XX  8  4
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6136
		"/             2  4  8  4  2
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6137
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6138
		eD := e.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6139
		eI := e // 32.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6140
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6141
		eP := eI * 8. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6142
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6143
		xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6144
		errorArray at:xN put:(errorArray at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6145
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6146
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6147
		errorArray1 at:xE put:(errorArray1 at:xE) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6148
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6149
		eP := eI * 4. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6150
		xN := xE + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6151
		errorArray at:xN put:(errorArray at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6152
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6153
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6154
		xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6155
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6156
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6157
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6158
		xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6159
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6160
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6161
		eP := eI * 2. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6162
		xN := xE - 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6163
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6164
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6165
		"/ eD := eD.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6166
		xN := xE + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6167
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6168
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6169
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6170
	    bitCnt := bitCnt - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6171
	    bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6172
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6173
		dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6174
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6175
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6176
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6177
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6178
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6179
	bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6180
	    byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6181
	    monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6182
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6183
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6184
	dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6185
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6186
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6187
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6188
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6189
    "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
  6190
    "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
  6191
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6192
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6193
floydSteinbergDitheredDepth8BitsColors:colors
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6194
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6195
     which must be a depth-8 image.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6196
     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
  6197
     (which need not be a colorCubes colors)."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6198
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6199
    ^ self floydSteinbergDitheredDepth8BitsColors:colors map:nil
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6200
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6201
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6202
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6203
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6204
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6205
     which must be a depth-24 image.
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6206
     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
  6207
     (which need not be a colorCubes colors)."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6208
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6209
    |pseudoBits
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6210
     ditherRGBBytes ditherColors
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6211
     w       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6212
     h       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6213
     index   "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6214
     ditherIds failed lastColor qScramble
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6215
     clrLookup lookupPos
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6216
     error clr|
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6217
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6218
    self depth ~~ 24 ifTrue:[^ nil].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6219
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6220
    "/ collect valid ditherColors ...
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6221
    aMapOrNil isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6222
	ditherColors := colors select:[:clr | clr notNil].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6223
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6224
	ditherColors := colors
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6225
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6226
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6227
    "/ ... and sort by manhatten distance from black
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6228
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6229
    qScramble := #(
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6230
		"/  2rX00X00X00X00
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6231
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6232
		    2r000000000000    "/ 0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6233
		    2r000000000100    "/ 1
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6234
		    2r000000100000    "/ 2
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6235
		    2r000000100100    "/ 3
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6236
		    2r000100000000    "/ 4
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6237
		    2r000100000100    "/ 5
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6238
		    2r000100100000    "/ 6
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6239
		    2r000100100100    "/ 7
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6240
		    2r100000000000    "/ 8
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6241
		    2r100000000100    "/ 9
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6242
		    2r100000100000    "/ a
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6243
		    2r100000100100    "/ b
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6244
		    2r100100000000    "/ c
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6245
		    2r100100000100    "/ d
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6246
		    2r100100100000    "/ e
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6247
		    2r100100100100    "/ f
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6248
		  ).
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6249
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6250
    ditherColors := ditherColors sort:[:a :b |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6251
				|cr "{Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6252
				 cg "{Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6253
				 cb "{Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6254
				 i1 "{Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6255
				 i2 "{Class: SmallInteger }"|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6256
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6257
				cr := a redByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6258
				cg := a greenByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6259
				cb := a blueByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6260
				i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6261
				i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6262
				i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6263
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6264
				cr := b redByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6265
				cg := b greenByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6266
				cb := b blueByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6267
				i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6268
				i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6269
				i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6270
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6271
				i1 < i2
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6272
		    ].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6273
    aMapOrNil isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6274
	ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6275
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6276
	ditherIds := aMapOrNil asByteArray
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6277
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6278
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6279
    "/ build an index table, for fast lookup from manhatten-r-g-b distance
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6280
    "/ to the position in the colorList
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6281
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6282
    clrLookup := ByteArray new:(4096).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6283
    index := 0.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6284
    ditherColors keysAndValuesDo:[:clrPosition :clr |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6285
	|r g b i|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6286
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6287
	r := clr redByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6288
	g := clr greenByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6289
	b := clr blueByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6290
	i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6291
	i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6292
	i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6293
	lookupPos := i.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6294
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6295
	[index < lookupPos] whileTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6296
	    clrLookup at:(index+1) put:(clrPosition-1-1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6297
	    index := index + 1
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6298
	]
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6299
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6300
    clrLookup from:index+1 to:4096 put:(ditherColors size - 1).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6301
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6302
"/    [index <= (4095)] whileTrue:[
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6303
"/        clrLookup at:(index+1) put:(ditherColors size - 1).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6304
"/        index := index + 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6305
"/    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6306
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6307
    "/ collect ditherColor components
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6308
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6309
    lastColor := ditherColors size.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6310
    ditherIds := ByteArray uninitializedNew:lastColor.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6311
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6312
    index := 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6313
    1 to:lastColor do:[:pix |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6314
	clr := ditherColors at:pix.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6315
	ditherRGBBytes at:index put:(clr redByte).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6316
	ditherRGBBytes at:index+1 put:(clr greenByte).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6317
	ditherRGBBytes at:index+2 put:(clr blueByte).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6318
	aMapOrNil isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6319
	    ditherIds at:pix put:clr colorId.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6320
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6321
	    ditherIds at:pix put:(aMapOrNil at:pix).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6322
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6323
	index := index + 3.
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6324
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6325
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6326
    pseudoBits := ByteArray uninitializedNew:(width * height).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6327
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6328
    w := width + 2.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6329
    error := ByteArray uninitializedNew:w*(3*2).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6330
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6331
    w := width.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6332
    h := height.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6333
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6334
    failed := true.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6335
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6336
%{
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6337
    int __x, __y;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6338
    int __eR, __eG, __eB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6339
    unsigned char *srcP, *dstP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6340
    unsigned char *idP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6341
    unsigned char *dp;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6342
    unsigned char *__clrLookup;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6343
    short *errP, *eP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6344
    int __fR, __fG, __fB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6345
    int iR, iG, iB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6346
    int idx;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6347
    int __w = __intVal(w);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6348
    int __h = __intVal(h);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6349
    int __nColors = __intVal(lastColor);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6350
    int __wR = -1, __wG, __wB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6351
    static int __qScramble[16] = {
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6352
		    0x000 /* 2r000000000000    0 */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6353
		    0x004 /* 2r000000000100    1 */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6354
		    0x020 /* 2r000000100000    2 */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6355
		    0x024 /* 2r000000100100    3 */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6356
		    0x100 /* 2r000100000000    4 */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6357
		    0x104 /* 2r000100000100    5 */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6358
		    0x120 /* 2r000100100000    6 */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6359
		    0x124 /* 2r000100100100    7 */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6360
		    0x800 /* 2r100000000000    8 */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6361
		    0x804 /* 2r100000000100    9 */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6362
		    0x820 /* 2r100000100000    a */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6363
		    0x824 /* 2r100000100100    b */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6364
		    0x900 /* 2r100100000000    c */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6365
		    0x904 /* 2r100100000100    d */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6366
		    0x920 /* 2r100100100000    e */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6367
		    0x924 /* 2r100100100100    f */,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6368
		  };
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6369
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6370
    if (__isByteArray(__INST(bytes))
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6371
     && __isByteArray(pseudoBits)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6372
     && __isByteArray(ditherRGBBytes)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6373
     && __isByteArray(ditherIds)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6374
     && __isByteArray(clrLookup)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6375
     && __isByteArray(error)) {
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6376
	failed = false;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6377
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6378
	srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6379
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6380
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6381
	__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6382
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6383
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6384
	/*
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6385
	 * clear error accumulator
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6386
	 */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6387
	eP = errP;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6388
	bzero(eP, (__w+2) * 2 * 3);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6389
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6390
	for (__y=__h; __y>0; __y--) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6391
	    __eR = __eG = __eB = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6392
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6393
	    eP = &(errP[3]);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6394
	    __eR = eP[0];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6395
	    __eG = eP[1];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6396
	    __eB = eP[2];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6397
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6398
	    for (__x=__w; __x>0; __x--) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6399
		int __want;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6400
		int pix;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6401
		int __wantR, __wantG, __wantB;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6402
		int idx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6403
		int tR, tG, tB;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6404
		int nR, nG, nB;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6405
		int dR, dG, dB;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6406
		int minDelta, bestIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6407
		int cnt;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6408
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6409
		__wantR = *srcP++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6410
		__wantG = *srcP++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6411
		__wantB = *srcP++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6412
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6413
		/*
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6414
		 * wR, wG and wB is the wanted r/g/b value;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6415
		 */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6416
		__wantR = __wantR + __eR;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6417
		__wantG = __wantG + __eG;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6418
		__wantB = __wantB + __eB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6419
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6420
#define RED_SCALE 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6421
#define GREEN_SCALE 59
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6422
#define BLUE_SCALE 11
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6423
#define GOOD_DELTA 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6424
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6425
#define xRED_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6426
#define xGREEN_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6427
#define xBLUE_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6428
#define xGOOD_DELTA 3
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6429
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6430
#define FAST_LOOKUP
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6431
/* #define ONE_SHOT */
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6432
#define NPROBE 8
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6433
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6434
#ifndef FAST_LOOKUP
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6435
		if ((__wantR == __wR)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6436
		 && (__wantG == __wG)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6437
		 && (__wantB == __wB)) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6438
		    /*
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6439
		     * same color again - reuse last bestMatch
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6440
		     */
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6441
		} else
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6442
#endif
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6443
		{
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6444
		    __wR = __wantR;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6445
		    __wG = __wantG;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6446
		    __wB = __wantB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6447
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6448
#ifdef FAST_LOOKUP
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6449
		    if(__wR > 255) __wR = 255;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6450
		    else if (__wR < 0) __wR = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6451
		    if(__wG > 255) __wG = 255;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6452
		    else if (__wG < 0) __wG = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6453
		    if(__wB > 255) __wB = 255;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6454
		    else if (__wB < 0) __wB = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6455
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6456
		    {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6457
			int lookupIndex;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6458
			int idx, idx0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6459
			int d, delta;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6460
			unsigned char *dp0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6461
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6462
			dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6463
			lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6464
			lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6465
			lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6466
			idx = bestIdx =__clrLookup[lookupIndex];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6467
			dp += (idx+idx+idx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6468
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6469
			/* try color at lookupIndex */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6470
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6471
			d = dp[0];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6472
			delta = (__wR - d) * RED_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6473
			if (delta < 0) delta = -delta;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6474
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6475
			d = dp[1];
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6476
			if (__wG > d)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6477
			    delta += (__wG - d) * GREEN_SCALE;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6478
			else
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6479
			    delta += (d - __wG) * GREEN_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6480
			d = dp[2];
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6481
			if (__wB > d)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6482
			    delta += (__wB - d) * BLUE_SCALE;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6483
			else
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6484
			    delta += (d - __wB) * BLUE_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6485
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6486
			if (delta <= GOOD_DELTA) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6487
			    goto foundBest;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6488
			}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6489
			minDelta = delta;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6490
# ifndef ONE_SHOT
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6491
			idx0 = idx; dp0 = dp;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6492
			cnt = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6493
			while ((++cnt <= NPROBE) && (idx > 0)) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6494
			    /* try previous color(s) */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6495
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6496
			    idx--; dp -= 3;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6497
			    d = dp[0];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6498
			    delta = (__wR - d) * RED_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6499
			    if (delta < 0) delta = -delta;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6500
			    d = dp[1];
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6501
			    if (__wG > d)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6502
				delta += (__wG - d) * GREEN_SCALE;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6503
			    else
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6504
				delta += (d - __wG) * GREEN_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6505
			    d = dp[2];
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6506
			    if (__wB > d)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6507
				delta += (__wB - d) * BLUE_SCALE;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6508
			    else
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6509
				delta += (d - __wB) * BLUE_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6510
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6511
			    if (delta < minDelta) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6512
				bestIdx = idx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6513
				if (delta <= GOOD_DELTA) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6514
				    goto foundBest;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6515
				}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6516
				minDelta = delta;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6517
			    }
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6518
			}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6519
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6520
			idx = idx0; dp = dp0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6521
			cnt = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6522
			while ((++cnt <= NPROBE) && (++idx < __nColors)) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6523
			    /* try next color */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6524
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6525
			    dp += 3;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6526
			    d = dp[0];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6527
			    delta = (__wR - d) * RED_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6528
			    if (delta < 0) delta = -delta;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6529
			    d = dp[1];
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6530
			    if (__wG > d)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6531
				delta += (__wG - d) * GREEN_SCALE;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6532
			    else
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6533
				delta += (d - __wG) * GREEN_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6534
			    d = dp[2];
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6535
			    if (__wB > d)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6536
				delta += (__wB - d) * BLUE_SCALE;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6537
			    else
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6538
				delta += (d - __wB) * BLUE_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6539
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6540
			    if (delta < minDelta) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6541
				bestIdx = idx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6542
				if (delta <= GOOD_DELTA) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6543
				    goto foundBest;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6544
				}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6545
				minDelta = delta;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6546
			    }
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6547
			}
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6548
# endif
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6549
		    }
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6550
	foundBest: ;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6551
#else
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6552
/*
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6553
		    if(__wR > 255) __wR = 255;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6554
		    else if (__wR < 0) __wR = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6555
		    if(__wG > 255) __wG = 255;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6556
		    else if (__wG < 0) __wG = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6557
		    if(__wB > 255) __wB = 255;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6558
		    else if (__wB < 0) __wB = 0;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6559
*/
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6560
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6561
		    /* find the best matching color */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6562
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6563
		    minDelta = 99999;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6564
		    bestIdx = -1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6565
		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6566
		    for (idx = 0; idx<__nColors; idx++) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6567
			int d, delta;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6568
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6569
			d = dp[0];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6570
			delta = (__wR - d) * RED_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6571
			if (delta < 0) delta = -delta;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6572
			if (delta < minDelta) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6573
			    d = dp[1];
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6574
			    if (__wG > d)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6575
				delta += (__wG - d) * GREEN_SCALE;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6576
			    else
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6577
				delta += (d - __wG) * GREEN_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6578
			    if (delta < minDelta) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6579
				d = dp[2];
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6580
				if (__wB > d)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6581
				    delta += (__wB - d) * BLUE_SCALE;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6582
				else
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6583
				    delta += (d - __wB) * BLUE_SCALE;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6584
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6585
				if (delta < minDelta) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6586
				    bestIdx = idx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6587
				    if (delta <= GOOD_DELTA) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6588
					break;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6589
				    }
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6590
				    minDelta = delta;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6591
				}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6592
			    }
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6593
			}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6594
			dp += 3;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6595
		    }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6596
#endif
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6597
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6598
		dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6599
		dp += bestIdx * 3;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6600
		dR = dp[0];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6601
		dG = dp[1];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6602
		dB = dp[2];
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6603
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6604
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  6605
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6606
		__wantR, __wantG, __wantB,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6607
		__wR, __wG, __wB,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6608
		dR, dG, dB);
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6609
*/
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6610
		/*
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6611
		 * store the corresponding dither colors colorId
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6612
		 */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6613
		*dstP++ = idP[bestIdx];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6614
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6615
		/*
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6616
		 * the new error & distribute the error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6617
		 */
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6618
		__eR = __wantR - dR;
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6619
		if (__eR) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6620
		    tR = __eR >> 4;  /* 16th of error */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6621
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6622
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6623
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6624
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6625
		    __eR = nR;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6626
		} else {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6627
		    __eR = eP[3];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6628
		    eP[0] = eP[-3] = eP[3] = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6629
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6630
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6631
		__eG = __wantG - dG;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6632
		if (__eG) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6633
		    tG = __eG >> 4;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6634
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6635
		    eP[1] = tG*5;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6636
		    eP[-2] = tG*3;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6637
		    eP[4] = __eG - (tG*15);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6638
		    __eG = nG;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6639
		} else {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6640
		    __eG = eP[4];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6641
		    eP[1] = eP[-2] = eP[4] = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6642
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6643
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6644
		__eB = __wantB - dB;
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6645
		if (__eB) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6646
		    tB = __eB >> 4;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6647
		    nB = eP[5] + (tB * 7);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6648
		    eP[2] = tB*5;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6649
		    eP[-1] = tB*3;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6650
		    eP[5] = __eB - (tB*15);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6651
		    __eB = nB;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6652
		} else {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6653
		    __eB = eP[5];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6654
		    eP[2] = eP[-1] = eP[5] = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6655
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6656
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6657
		eP += 3;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6658
	    }
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6659
	}
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6660
    }
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6661
%}.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6662
    failed ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6663
	self primitiveFailed.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6664
	^ nil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6665
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6666
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6667
    ^ pseudoBits
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6668
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6669
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6670
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6671
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6672
     which must be a depth-8 image.
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6673
     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
  6674
     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
  6675
     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
  6676
     colors assigned to aDevice, such as the preallocated colors of the
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6677
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6678
     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
  6679
     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
  6680
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6681
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6682
    |pseudoBits
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6683
     rgbBytes
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6684
     w       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6685
     h       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6686
     index   "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6687
     fixR    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6688
     fixG    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6689
     fixB    "{Class: SmallInteger }"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6690
     fixGfixB
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6691
     fixIds failed map lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6692
     rgbIDX  "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6693
     idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6694
     error clr|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6695
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6696
    self depth ~~ 8 ifTrue:[^ nil].
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6697
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6698
    fixR := nRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6699
    fixR == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6700
    fixG := nGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6701
    fixG == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6702
    fixB := nBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6703
    fixB == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6704
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6705
    "/ simple check
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6706
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6707
	self error:'invalid color array passed'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6708
	^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6709
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6710
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6711
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6712
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6713
    "/ collect color components as integer values (for integer arithmetic)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6714
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6715
    rgbBytes := ByteArray uninitializedNew:256 * 3.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6716
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6717
    index := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6718
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6719
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6720
	lastColor := colorMap size - 1
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6721
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6722
	lastColor := 255.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6723
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6724
    0 to:lastColor do:[:pix |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6725
	clr := self colorFromValue:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6726
	rgbBytes at:index put:(clr redByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6727
	rgbBytes at:index+1 put:(clr greenByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6728
	rgbBytes at:index+2 put:(clr blueByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6729
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6730
	index := index + 3.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6731
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6732
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6733
    pseudoBits := ByteArray uninitializedNew:(width * height).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6734
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6735
    w := width + 2.
1636
c30f6644666e dont use bcopy in #floydSteinbergDitheredDepth8BitsColors
Claus Gittinger <cg@exept.de>
parents: 1630
diff changeset
  6736
    error := ByteArray new:w*(3*2).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6737
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6738
    w := width.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6739
    h := height.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6740
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6741
    idxAndErrRBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6742
    idxAndErrGBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6743
    idxAndErrBBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6744
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6745
    fixGfixB := fixG * fixB.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6746
    index := 1.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6747
    0 to:255 do:[:i |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6748
	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
  6749
	idxAndErrRBytes at:index put:(rgbIDX * fixGfixB).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6750
	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
  6751
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6752
	rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6753
	idxAndErrGBytes at:index put:(rgbIDX * fixB).
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6754
	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
  6755
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6756
	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
  6757
	idxAndErrBBytes at:index put:(rgbIDX ).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6758
	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
  6759
	index := index + 2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6760
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6761
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6762
    failed := true.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6763
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6764
%{
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6765
    int __x, __y;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6766
    int __eR, __eG, __eB;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6767
    unsigned char *srcP, *dstP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6768
    unsigned char *rgbP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6769
    unsigned char *idP;
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6770
    unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes;
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6771
    short *errP, *eP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6772
    int idx;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6773
    int __w = __intVal(w);
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6774
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6775
    if (__isByteArray(__INST(bytes))
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6776
     && __isByteArray(pseudoBits)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6777
     && __isByteArray(rgbBytes)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6778
     && __isByteArray(fixIds)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6779
     && __isByteArray(error)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6780
     && __bothSmallInteger(fixR, fixG)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6781
     && __isSmallInteger(fixB)) {
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6782
	failed = false;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6783
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6784
	srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6785
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6786
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6787
	idP = __ByteArrayInstPtr(fixIds)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6788
	__idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6789
	__idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6790
	__idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6791
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
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
	eP = errP;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6794
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6795
	for (__y=__intVal(h); __y>0; __y--) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6796
	    __eR = __eG = __eB = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6797
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6798
	    eP = &(errP[3]);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6799
	    __eR = eP[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6800
	    __eG = eP[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6801
	    __eB = eP[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6802
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6803
	    for (__x=__w; __x>0; __x--) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6804
		int __want;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6805
		int pix;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6806
		int idx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6807
		int tR, tG, tB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6808
		int nR, nG, nB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6809
		int iRGB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6810
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6811
		pix = *srcP++;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6812
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6813
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6814
		 * 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
  6815
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6816
		pix = pix+pix+pix;  /* pix * 3 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6817
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6818
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6819
		 * 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
  6820
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6821
		__want = rgbP[pix]   + __eR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6822
		if (__want > 255) __want = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6823
		else if (__want < 0) __want = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6824
		__want += __want;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6825
		idx = __idxAndErrRBytes[__want];
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6826
		__eR = __idxAndErrRBytes[__want+1];
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6827
		__eR -= 128;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6828
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6829
		__want = rgbP[pix+1] + __eG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6830
		if (__want > 255) __want = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6831
		else if (__want < 0) __want = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6832
		__want += __want;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6833
		idx += __idxAndErrGBytes[__want];
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6834
		__eG = __idxAndErrGBytes[__want+1];
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6835
		__eG -= 128;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6836
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6837
		__want = rgbP[pix+2] + __eB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6838
		if (__want > 255) __want = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6839
		else if (__want < 0) __want = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6840
		__want += __want;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6841
		idx += __idxAndErrBBytes[__want];
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6842
		__eB = __idxAndErrBBytes[__want+1];
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6843
		__eB -= 128;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6844
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6845
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6846
		 * store the corresponding dither colors colorId
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6847
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6848
		*dstP++ = idP[idx];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6849
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6850
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6851
		 * distribute the error
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6852
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6853
		if (__eR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6854
		    tR = __eR >> 4;  /* 16th of error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6855
		    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
  6856
		    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
  6857
		    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
  6858
		    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
  6859
		    __eR = nR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6860
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6861
		    __eR = eP[3];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6862
		    eP[0] = eP[-3] = eP[3] = 0;
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
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6865
		if (__eG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6866
		    tG = __eG >> 4;  /* 16th of error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6867
		    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
  6868
		    eP[1] = tG*5;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6869
		    eP[-2] = tG*3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6870
		    eP[4] = __eG - (tG*15);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6871
		    __eG = nG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6872
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6873
		    __eG = eP[4];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6874
		    eP[1] = eP[-2] = eP[4] = 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
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6877
		if (__eB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6878
		    tB = __eB >> 4;  /* 16th of error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6879
		    nB = eP[5] + (tB * 7);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6880
		    eP[2] = tB*5;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6881
		    eP[-1] = tB*3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6882
		    eP[5] = __eB - (tB*15);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6883
		    __eB = nB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6884
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6885
		    __eB = eP[5];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6886
		    eP[2] = eP[-1] = eP[5] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6887
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6888
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6889
		eP += 3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6890
	    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6891
	}
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6892
    }
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6893
%}.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6894
    failed ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6895
	self primitiveFailed.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6896
	^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6897
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6898
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6899
    ^ pseudoBits
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6900
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6901
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6902
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6903
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6904
floydSteinbergDitheredGrayBitsDepth:depth
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6905
    "return the bits for dithering a gray image from the image.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6906
     Works for any source depths / photometric,
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6907
     but possibly slow since each pixel is processed individually.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6908
     Redefined by some subclasses for more performance (D8Image/D24Image)"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6909
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6910
    |dstIndex        "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6911
     nextDst         "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6912
     bytesPerOutRow  "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6913
     outBits greyValues greyErrors greyPixels greyLevels
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6914
     errorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6915
     nextErrorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6916
     t
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6917
     w               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6918
     h               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6919
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6920
     byte            "{Class: SmallInteger }"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6921
     grey
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6922
     eR eRB eB eLB |
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6923
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6924
    depth > 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6925
	self error:'unimplemented conversion'.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6926
	^ nil
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6927
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6928
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6929
    w := width.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6930
    h := height.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6931
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6932
    bytesPerOutRow := ((w * depth) + 7) // 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6933
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6934
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6935
    greyLevels := (1 bitShift:depth) - 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6936
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6937
    errorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6938
    nextErrorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6939
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6940
    nextErrorArray atAllPut:0.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6941
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6942
    dstIndex := 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6943
    bitCnt := 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6944
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  6945
    self depth <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6946
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6947
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6948
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6949
	greyValues := self greyMapForRange:(greyLevels).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6950
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6951
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6952
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6953
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6954
						   v truncated]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6955
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6956
	greyPixels := ByteArray withAll:greyPixels.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6957
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6958
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6959
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6960
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6961
						   ((v - v truncated) * 1024) truncated
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6962
					       ]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6963
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6964
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6965
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6966
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6967
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6968
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6969
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6970
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6971
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6972
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6973
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6974
	    self valuesAtY:y from:0 to:(w-1) do:[:x :value |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6975
		|e     "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6976
		 pixel "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6977
		 error "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6978
		 e16   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6979
		 xE    "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6980
		 xN    "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6981
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6982
		pixel := greyPixels at:(value + 1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6983
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6984
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6985
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6986
		error := (greyErrors at:(value + 1)) + (errorArray at:xE).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6987
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6988
		byte := byte bitShift:depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6989
		error > 512 "0.5" ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6990
		    pixel := pixel + 1.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6991
		    e := error - 1024 "1.0"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6992
		] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6993
		    e := error
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6994
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6995
		byte := byte bitOr:pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6996
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6997
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6998
		    e16 := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6999
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7000
		    eR  := e16 * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7001
		    eRB := e16 * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7002
		    eB  := e16 * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7003
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7004
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7005
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7006
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7007
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7008
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7009
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7010
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7011
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7012
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7013
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7014
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7015
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7016
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7017
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7018
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7019
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7020
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7021
		bitCnt := bitCnt - depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7022
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7023
		    outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7024
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7025
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7026
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7027
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7028
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7029
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7030
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7031
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7032
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7033
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7034
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7035
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7036
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7037
	].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7038
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7039
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7040
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7041
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7042
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7043
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7044
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7045
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7046
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7047
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7048
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7049
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7050
		|e     "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7051
		 pixel "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7052
		 error "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7053
		 e16   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7054
		 xE    "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7055
		 xN    "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7056
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7057
		grey := (clr brightness * greyLevels).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7058
		pixel := grey truncated.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7059
		error := ((grey - pixel) * 1024) truncated.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7060
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7061
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7062
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7063
		error := error + (errorArray at:xE).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7064
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7065
		byte := byte bitShift:depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7066
		error > 512 "0.5" ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7067
		    pixel := pixel + 1.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7068
		    e := error - 1024 "1.0"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7069
		] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7070
		    e := error
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7071
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7072
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7073
		byte := byte bitOr:pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7074
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7075
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7076
		    e16 := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7077
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7078
		    eR  := e16 * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7079
		    eRB := e16 * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7080
		    eB  := e16 * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7081
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7082
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7083
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7084
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7085
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7086
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7087
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7088
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7089
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7090
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7091
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7092
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7093
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7094
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7095
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7096
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7097
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7098
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7099
		bitCnt := bitCnt - depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7100
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7101
		    outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7102
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7103
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7104
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7105
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7106
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7107
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7108
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7109
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7110
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7111
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7112
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7113
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7114
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7115
	].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7116
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7117
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7118
    ^ outBits
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7119
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7120
    "Created: 10.6.1996 / 13:28:22 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7121
    "Modified: 11.6.1996 / 00:13:38 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7122
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7123
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7124
floydSteinbergDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7125
    "return the bitmap for a dithered monochrome bitmap from the image.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7126
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7127
     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
  7128
     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
  7129
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7130
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7131
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7132
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7133
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7134
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7135
     nextErrorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7136
     e eD t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7137
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7138
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7139
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7140
     byte            "{Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7141
     grey
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7142
     eR eRB eB eLB |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7143
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7144
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7145
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7146
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7147
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7148
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7149
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7150
    errorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7151
    nextErrorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7152
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7153
    nextErrorArray atAllPut:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7154
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7155
    dstIndex := 1.
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7156
    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7157
    byte := 0.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7158
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7159
    self depth <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7160
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7161
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7162
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7163
	greyValues := self greyMapForRange:(255 * 1024).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7164
	greyValues := greyValues collect:[:v | v rounded].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7165
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7166
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7167
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7168
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7169
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7170
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7171
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7172
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7173
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7174
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7175
	    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
  7176
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7177
		int __grey, __e;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7178
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7179
		OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7180
		OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7181
		int __x = __intVal(x);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7182
		int __eR, __eB, __eRB, __eLB, __eI;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7183
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7184
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7185
		__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7186
		__grey += __intVal(__errorArray[__x+1]);
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7187
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7188
		__byte <<= 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7189
		if (__grey > 127*1024) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7190
		    __e = __grey - (255*1024);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7191
		    __byte |= 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7192
		} else {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7193
		    __e = __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7194
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7195
		if (__e) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7196
		    __eI = __e >> 4;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7197
		    __eR  = __eI * 7;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7198
		    __eRB = __eI * 1;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7199
		    __eB  = __eI * 5;
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7200
		    __eLB = __e - __eR - __eRB - __eB;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7201
		    __errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7202
		    __nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7203
		    __nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7204
		    __nextErrorArray[__x  ] = __MKSMALLINT(__intVal(__nextErrorArray[__x  ]) + __eLB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7205
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7206
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7207
		__bitCnt--;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7208
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7209
		    int __dstIndex = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7210
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7211
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7212
		    dstIndex = __MKSMALLINT(__dstIndex + 1);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7213
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7214
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7215
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7216
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7217
		bitCnt = __MKSMALLINT(__bitCnt);
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7218
%}.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7219
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7220
"/                |eI "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7221
"/                 xE "{ Class: SmallInteger }"
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  7222
"/                 xN "{ Class: SmallInteger }" |
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  7223
"/
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7224
"/                "/ get the colors grey value [0 .. 1]
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7225
"/                grey := greyValues at:(pixel + 1).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7226
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7227
"/                "/ adjust error
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7228
"/                xE := x + 2.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7229
"/                grey := (grey + (errorArray at:xE)).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7230
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7231
"/                byte := byte bitShift:1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7232
"/                grey > (127*1024) ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7233
"/                    byte := byte bitOr:1.      "/ white
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7234
"/                    e := grey - (255*1024)
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7235
"/                ] ifFalse:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7236
"/                    e := grey                  "/ black
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7237
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7238
"/                e ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7239
"/                    eD := e.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7240
"/                    eI := e // 16.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7241
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7242
"/                    eR  := eI * 7.              "/ 7/16 to right
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7243
"/                    eRB := eI * 1.              "/ 1/16 to right below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7244
"/                    eB  := eI * 5.              "/ 5/16 to below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7245
"/                    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7246
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7247
"/                    xN := xE + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7248
"/                    eR ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7249
"/                        errorArray     at:xN put:(errorArray at:xN) + eR.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7250
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7251
"/                    eRB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7252
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7253
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7254
"/                    eB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7255
"/                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7256
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7257
"/                    eLB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7258
"/                        xN := xE - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7259
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7260
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7261
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7262
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7263
"/                bitCnt := bitCnt - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7264
"/                bitCnt == 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7265
"/                    monoBits at:dstIndex put:byte.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7266
"/                    dstIndex := dstIndex + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7267
"/                    byte := 0.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7268
"/                    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7269
"/                ].
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7270
		  0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7271
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7272
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7273
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7274
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7275
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7276
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7277
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7278
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7279
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7280
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7281
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7282
	'Image [info]: slow floydSteinberg dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7283
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7284
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7285
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7286
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7287
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7288
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7289
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7290
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7291
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7292
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7293
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7294
		|eI "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7295
		 xE "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7296
		 xN "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7297
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7298
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7299
		grey := (clr brightness * 255).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7300
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7301
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7302
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7303
		grey := (grey + (errorArray at:xE)) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7304
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7305
		byte := byte bitShift:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7306
		grey > 127 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7307
		    byte := byte bitOr:1.      "/ white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7308
		    e := grey - 255
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7309
		] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7310
		    e := grey                  "/ black
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7311
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7312
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7313
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7314
		    eD := e.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7315
		    eI := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7316
		    eR  := eI * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7317
		    eRB := eI * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7318
		    eB  := eI * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7319
		    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7320
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7321
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7322
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7323
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7324
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7325
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7326
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7327
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7328
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7329
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7330
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7331
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7332
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7333
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7334
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7335
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7336
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7337
		bitCnt := bitCnt - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7338
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7339
		    monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7340
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7341
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7342
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7343
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7344
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7345
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7346
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7347
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7348
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7349
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7350
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7351
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7352
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7353
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7354
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7355
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7356
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7357
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7358
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7359
    "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
  7360
    "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
  7361
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7362
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7363
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7364
    "return a nearest paint bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7365
     which must be a depth-8 image.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7366
     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
  7367
     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
  7368
     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
  7369
     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
  7370
     Color class."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7371
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7372
    |pseudoBits
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7373
     fixR    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7374
     fixG    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7375
     fixB    "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7376
     fixGfixB
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7377
     r       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7378
     g       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7379
     b       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7380
     idx     "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7381
     idMap lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7382
     clr|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7383
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7384
    self depth ~~ 8 ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7385
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7386
    photometric == #palette ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7387
	lastColor := colorMap size - 1
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7388
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7389
	lastColor := 255.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7390
    ].
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7391
    idMap := ByteArray uninitializedNew:256.
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7392
3915
dd2dae91c068 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3914
diff changeset
  7393
    (nRed isNil or:[nGreen isNil or:[nBlue isNil]]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7394
	0 to:lastColor do:[:pix |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7395
	    |clr repClr|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7396
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7397
	    clr := self colorFromValue:pix.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7398
	    repClr := clr nearestIn:fixColors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7399
	    idMap at:(pix+1) put:(fixColors identityIndexOf:repClr)-1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7400
	].
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  7401
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7402
	fixR := nRed.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7403
	fixR == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7404
	fixG := nGreen.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7405
	fixG == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7406
	fixB := nBlue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7407
	fixB == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7408
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7409
	"/ simple check
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7410
	(fixR * fixG * fixB) ~~ fixColors size ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7411
	    self error:'invalid color array passed'.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7412
	    ^ nil
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7413
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7414
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7415
	"/
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7416
	"/ collect colorIds
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7417
	"/
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7418
	fixGfixB := fixG * fixB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7419
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7420
	0 to:lastColor do:[:pix |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7421
	    clr := self colorFromValue:pix.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7422
	    r := clr redByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7423
	    g := clr greenByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7424
	    b := clr blueByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7425
	    idx := ((r * (fixR-1) + 128) // 255) * fixGfixB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7426
	    idx := idx + (((g * (fixG-1) + 128) // 255) * fixB).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7427
	    idx := idx + ((b * (fixB-1) + 128) // 255).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7428
	    idMap at:(pix+1) put:(fixColors at:(idx+1)) colorId.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7429
	].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7430
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7431
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7432
    pseudoBits := ByteArray uninitializedNew:(width * height).
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7433
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7434
    "/ translate
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7435
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  7436
    self bits
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7437
	expandPixels:8         "xlate only"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7438
	width:width height:height
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7439
	into:pseudoBits
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7440
	mapping:idMap.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7441
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7442
    ^ pseudoBits
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7443
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7444
    "Modified: 18.6.1996 / 09:18:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7445
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7446
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7447
nfloydSteinbergDitheredDepth8BitsColors:colors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7448
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7449
     which must be a depth-8 image.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7450
     This method expects an array of colors to be used for dithering
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7451
     (which need not be a colorCubes colors)."
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7452
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7453
    |pseudoBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7454
     rgbBytes
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7455
     ditherRGBBytes ditherColors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7456
     w       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7457
     h       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7458
     index   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7459
     numR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7460
     numG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7461
     numB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7462
     bitsR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7463
     bitsG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7464
     bitsB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7465
     maxBits  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7466
     maskR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7467
     maskG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7468
     maskB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7469
     shR      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7470
     shG      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7471
     shB      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7472
     ditherIds failed map lastColor colorsByDistance qScramble
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7473
     clrLookup lookupPos cube nCube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7474
     dR  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7475
     dG  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7476
     dB  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7477
     iR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7478
     iRG   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7479
     iRGB  "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7480
     clr
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7481
     rI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7482
     gI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7483
     bI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7484
     maxIDX  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7485
     subCubeColorCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7486
     error
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7487
     dl "{Class: SmallInteger }"|
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7488
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7489
    self depth ~~ 8 ifTrue:[^ nil].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7490
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7491
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7492
    "/ collect color components as integer values (for integer arithmetic)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7493
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7494
    rgbBytes := ByteArray uninitializedNew:256 * 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7495
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7496
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7497
	lastColor := colorMap size - 1
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7498
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7499
	lastColor := 255.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7500
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7501
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7502
    0 to:lastColor do:[:pix |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7503
	clr := self colorFromValue:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7504
	rgbBytes at:index put:(clr redByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7505
	rgbBytes at:index+1 put:(clr greenByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7506
	rgbBytes at:index+2 put:(clr blueByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7507
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7508
	index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7509
    ].
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
    "/ collect valid ditherColors ...
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7512
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7513
    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
  7514
    ditherColors := ditherColors select:[:clr | clr colorId notNil].
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7515
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7516
    "/ collect ditherColor components
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7517
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7518
    lastColor := ditherColors size.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7519
    ditherIds := ByteArray uninitializedNew:lastColor.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7520
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7521
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7522
    1 to:lastColor do:[:pix |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7523
	clr := ditherColors at:pix.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7524
	ditherRGBBytes at:index put:(clr redByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7525
	ditherRGBBytes at:index+1 put:(clr greenByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7526
	ditherRGBBytes at:index+2 put:(clr blueByte).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7527
	ditherIds at:pix put:clr colorId.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7528
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7529
	index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7530
    ].
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
    "/ place the ditherColor positions into a color cube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7533
    bitsR := 5.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7534
    bitsG := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7535
    bitsB := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7536
    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
"/    bitsR := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7539
"/    bitsG := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7540
"/    bitsB := 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7541
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7542
    numR := 1 bitShift:bitsR.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7543
    numG := 1 bitShift:bitsG.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7544
    numB := 1 bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7545
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7546
    maskR := (numR-1) bitShift:(bitsG + bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7547
    maskG := (numG-1) bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7548
    maskB := numB-1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7549
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7550
    shR := -16+bitsR+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7551
    shG := -16+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7552
    shB := -16+bitsB.
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
    maxIDX := numR*numG*numB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7555
    cube := Array new:maxIDX.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7556
    1 to:lastColor do:[:clrIdx |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7557
	clr := ditherColors at:clrIdx.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7558
	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
  7559
	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
  7560
	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
  7561
	index := rI + gI + bI + 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7562
	subCubeColorCollection := cube at:index.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7563
	subCubeColorCollection isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7564
	    subCubeColorCollection := OrderedCollection new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7565
	    cube at:index put:subCubeColorCollection.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7566
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7567
	subCubeColorCollection add:(clrIdx - 1).
903
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
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7570
    shR := 1 bitShift:(bitsG+bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7571
    shG := 1 bitShift:(bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7572
    shB := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7573
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7574
    1 to:maxIDX do:[:i |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7575
	subCubeColorCollection := cube at:i.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7576
	subCubeColorCollection notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7577
	    cube at:i put:(subCubeColorCollection asByteArray)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7578
	]
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7579
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7580
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7581
"/    nCube := cube copy.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7582
"/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7583
"/    cube keysAndValuesDo:[:i :indices |
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7584
"/        indices notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7585
"/            nCube at:i put:(indices asByteArray)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7586
"/        ] ifFalse:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7587
"/            "/ find nearest color
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7588
"/
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7589
"/            dl := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7590
"/            [dl < maxBits] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7591
"/                dR := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7592
"/                [dR <= dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7593
"/                    iR := i + (dR * shR).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7594
"/                    (iR > 0 and:[iR < maxIDX]) ifTrue:[
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7595
"/                        dG := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7596
"/                        [dG < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7597
"/                            iRG := iR + (dG * shG).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7598
"/                            (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7599
"/                                dB := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7600
"/                                [dB < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7601
"/                                    iRGB := iRG + dB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7602
"/                                    (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7603
"/                                        (cube at:iRGB) notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7604
"/                                            nCube at:i put:(cube at:iRGB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7605
"/                                            dB := dG := dR := dl := 999.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7606
"/                                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7607
"/                                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7608
"/                                    dB := dB + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7609
"/                                ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7610
"/                            ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7611
"/                            dG := dG + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7612
"/                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7613
"/                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7614
"/                    dR := dR + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7615
"/                ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7616
"/                dl := dl + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7617
"/            ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7618
"/        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7619
"/    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7620
"/self halt.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7621
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7622
    "/ now, cube contains collections of colors which are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7623
    "/ positioned in a subCube; quickly accessed by a lookup
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7624
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7625
    pseudoBits := ByteArray uninitializedNew:(width * height).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7626
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7627
    w := width.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7628
    h := height.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7629
    error := ByteArray new:(w+2)*3*2.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7630
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7631
%{
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7632
#define BITSR   5
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7633
#define BITSG   6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7634
#define BITSB   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7635
#define MAXBITS 6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7636
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7637
#define xBITSR   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7638
#define xBITSG   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7639
#define xBITSB   3
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7640
#define xMAXBITS 4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7641
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7642
#define NR      32 /* (1<<BITSR) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7643
#define NG      64 /* (1<<BITSG) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7644
#define NB      16 /* (1<<BITSB) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7645
#define MAXRGB  64 /* (1<<MAXBITS) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7646
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7647
#define SHR     (BITSG+BITSB)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7648
#define SHG     BITSB
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7649
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7650
#define REMEMBER_SEARCH
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7651
#define xNO_FLOYD_STEINBERG
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7652
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7653
    int __x, __y;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7654
    int __eR, __eG, __eB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7655
    unsigned char *srcP, *dstP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7656
    unsigned char *rgbP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7657
    unsigned char *idP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7658
    short *errP, *eP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7659
    int __fR, __fG, __fB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7660
    int idx;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7661
    int __w = __intVal(w);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7662
    int __h = __intVal(h);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7663
    int __nColors = __intVal(lastColor);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7664
    int __wR = -1, __wG, __wB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7665
    OBJ *__cube;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7666
    int cubeIndex, cubeIndex2;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7667
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7668
    if (__isByteArray(__INST(bytes))
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7669
     && __isByteArray(pseudoBits)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7670
     && __isByteArray(rgbBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7671
     && __isByteArray(ditherRGBBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7672
     && __isByteArray(ditherIds)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7673
     && __isByteArray(error)) {
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7674
	failed = false;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7675
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7676
	srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7677
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7678
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7679
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7680
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7681
	__cube = __ArrayInstPtr(cube)->a_element;
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
	eP = errP;
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
	for (__y=__h; __y>0; __y--) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7686
	    eP = &(errP[3]);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7687
	    __eR = eP[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7688
	    __eG = eP[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7689
	    __eB = eP[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7690
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7691
	    for (__x=__w; __x>0; __x--) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7692
		int __want;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7693
		int pix;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7694
		int __wantR, __wantG, __wantB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7695
		int idx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7696
		int tR, tG, tB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7697
		int nR, nG, nB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7698
		int __dR, __dG, __dB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7699
		int minDelta, bestIdx;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7700
		int __iR, __iG, __iB;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7701
		int cR, cG, cB;
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7702
		int delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7703
		OBJ subCubeColors;
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
		pix = *srcP++;
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
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7708
		 * 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
  7709
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7710
		idx = pix+pix+pix;  /* pix * 3 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7711
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7712
		__wR = __wantR = rgbP[idx] + __eR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7713
		__wG = __wantG = rgbP[idx+1] + __eG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7714
		__wB = __wantB = rgbP[idx+2] + __eB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7715
		if(__wR > 255) __wR = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7716
		else if (__wR < 0) __wR = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7717
		if(__wG > 255) __wG = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7718
		else if (__wG < 0) __wG = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7719
		if(__wB > 255) __wB = 255;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7720
		else if (__wB < 0) __wB = 0;
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
		__iR = __wR >> (8-BITSR);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7723
		__iG = __wG >> (8-BITSG);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7724
		__iB = __wB >> (8-BITSB);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7725
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7726
		cubeIndex = (__iR<<SHR) + (__iG<<SHG) + __iB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7727
		subCubeColors = __cube[cubeIndex];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7728
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7729
		if (subCubeColors == nil) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7730
		    /* 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
  7731
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7732
		    delta = 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7733
		    while (delta < MAXRGB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7734
			/* check plane above */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7735
			cR = __iR + delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7736
			if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7737
			    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
  7738
				if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7739
				    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
  7740
					if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7741
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7742
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7743
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7744
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7745
					    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7746
					}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7747
				    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7748
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7749
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7750
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7751
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7752
			/* check plane below */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7753
			cR = __iR - delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7754
			if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7755
			    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
  7756
				if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7757
				    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
  7758
					if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7759
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7760
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7761
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7762
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7763
					    }
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
				    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7766
				}
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
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7769
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7770
			/* check plane to the right */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7771
			cG = __iG + delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7772
			if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7773
			    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
  7774
				if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7775
				    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
  7776
					if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7777
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7778
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7779
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7780
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7781
					    }
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
				}
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
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7787
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7788
			/* check plane to the left */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7789
			cG = __iG - delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7790
			if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7791
			    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
  7792
				if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7793
				    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
  7794
					if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7795
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7796
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7797
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7798
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7799
					    }
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
				    }
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
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7804
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7805
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7806
			/* check plane at back */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7807
			cB = __iB + delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7808
			if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7809
			    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
  7810
				if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7811
				    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
  7812
					if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7813
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7814
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7815
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7816
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7817
					    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7818
					}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7819
				    }
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
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7823
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7824
			/* check plane at front */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7825
			cB = __iB - delta;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7826
			if ((unsigned)cB < NB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7827
			    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
  7828
				if ((unsigned)cR < NR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7829
				    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
  7830
					if ((unsigned)cG < NG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7831
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7832
					    subCubeColors = __cube[cubeIndex2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7833
					    if (__isNonNilObject(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7834
						goto found;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7835
					    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7836
					}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7837
				    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7838
				}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7839
			    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7840
			}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7841
			delta = delta + 1;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7842
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7843
		    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7844
		    /* 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
  7845
		    subCubeColors = nil;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7846
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7847
    found:
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7848
		    __iR = cR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7849
		    __iG = cG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7850
		    __iB = cB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7851
		    bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7852
#ifdef REMEMBER_SEARCH
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7853
		    __cube[cubeIndex] = __MKSMALLINT(bestIdx);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7854
#endif
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7855
		} else {
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7856
#ifdef REMEMBER_SEARCH
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7857
		    if (__isSmallInteger(subCubeColors)) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7858
			bestIdx = __intVal(subCubeColors);
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7859
		    } else
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7860
#endif
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7861
		    {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7862
			bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7863
		    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7864
		}
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7865
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7866
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7867
		 * 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
  7868
		 * colors in subCubeColors.
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
		 * 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
  7871
		 * 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
  7872
		 * first color found there.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7873
		 * (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
  7874
		 * 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
  7875
		 * it will be diffused anyway ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7876
		 */
903
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
#ifndef NO_FLOYD_STEINBERG
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7879
		{
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7880
		    unsigned char *dp;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7881
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7882
		    /*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7883
		     * fetch that colors r/g/b components
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7884
		     */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7885
		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7886
		    dp += bestIdx * 3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7887
		    __dR = dp[0];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7888
		    __dG = dp[1];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7889
		    __dB = dp[2];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7890
		}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7891
#endif
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7892
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7893
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  7894
console_fprintf(stderr, "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
  7895
		__wantR, __wantG, __wantB,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7896
		__wR, __wG, __wB,
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7897
		__dR, __dG, __dB);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7898
*/
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7899
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7900
		 * store the corresponding dither colors colorId
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7901
		 */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7902
		*dstP++ = idP[bestIdx];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7904
#ifndef NO_FLOYD_STEINBERG
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7905
		/*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7906
		 * the new error & distribute the error
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7907
		 */
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7908
		__eR = __wantR - __dR;
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7909
		if (__eR) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7910
		    tR = __eR >> 4;  /* 16th of error */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7911
		    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
  7912
		    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
  7913
		    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
  7914
		    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
  7915
		    __eR = nR;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7916
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7917
		    __eR = eP[3];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7918
		    eP[0] = eP[-3] = eP[3] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7919
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7920
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7921
		__eG = __wantG - __dG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7922
		if (__eG) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7923
		    tG = __eG >> 4;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7924
		    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
  7925
		    eP[1] = tG*5;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7926
		    eP[-2] = tG*3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7927
		    eP[4] = __eG - (tG*15);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7928
		    __eG = nG;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7929
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7930
		    __eG = eP[4];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7931
		    eP[1] = eP[-2] = eP[4] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7932
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7933
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7934
		__eB = __wantB - __dB;
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7935
		if (__eB) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7936
		    tB = __eB >> 4;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7937
		    nB = eP[5] + (tB * 7);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7938
		    eP[2] = tB*5;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7939
		    eP[-1] = tB*3;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7940
		    eP[5] = __eB - (tB*15);
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7941
		    __eB = nB;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7942
		} else {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7943
		    __eB = eP[5];
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7944
		    eP[2] = eP[-1] = eP[5] = 0;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7945
		}
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7946
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7947
		eP += 3;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7948
#endif
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7949
	    }
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
	    /*
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7952
	     * allow for an interrupt after every row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7953
	     * but care to refetch C variables
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7954
	     */
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7955
	    if (InterruptPending) {
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7956
		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
  7957
		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
  7958
		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
  7959
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7960
		__interrupt__();
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7961
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7962
		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
  7963
		dstP = __ByteArrayInstPtr(pseudoBits)->ba_element + d_dstP;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7964
		rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7965
		idP = __ByteArrayInstPtr(ditherIds)->ba_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7966
		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
  7967
		__cube = __ArrayInstPtr(cube)->a_element;
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7968
	    }
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7969
	}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7970
    }
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7971
%}.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7972
    failed ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7973
	self primitiveFailed.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7974
	^ nil
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7975
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7976
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7977
    ^ pseudoBits
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7978
!
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7979
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7980
orderedDitheredGrayBitsDepth:depth
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7981
    "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
  7982
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  7983
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7984
	orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7985
	ditherWidth:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  7986
	depth:depth.
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7987
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7988
    "Created: 24.6.1997 / 22:20:12 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7989
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7990
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7991
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7992
    "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
  7993
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7994
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7995
     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
  7996
     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
  7997
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7998
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7999
     greyLevels greyValues greyPixels greyErrors
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8000
     dstIndex        "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8001
     nextDst
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8002
     bytesPerOutRow  "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8003
     pixelsPerByte   "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8004
     outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8005
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8006
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8007
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8008
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8009
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8010
    depth > 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8011
	'IMAGE: unimplemented orderedDither conversion' errorPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8012
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8013
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8014
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8015
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8016
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8017
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8018
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8019
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8020
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8021
    greyLevels := 1 bitShift:depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8022
    pixelsPerByte := 8 / depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8023
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8024
    bytesPerOutRow := (w * depth + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8025
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8026
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8027
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8028
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8029
    self bitsPerPixel <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8030
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8031
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8032
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8033
	greyValues := self greyMapForRange:(greyLevels-1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8034
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8035
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8036
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8037
						   v truncated]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8038
	greyPixels := ByteArray withAll:greyPixels.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8039
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8040
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8041
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8042
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8043
						   ((v - v truncated) * nDither) rounded
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8044
					       ]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8045
	greyErrors := ByteArray withAll:greyErrors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8046
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8047
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8048
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8049
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8050
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8051
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8052
	    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
  8053
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8054
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8055
		int __byte = __intVal(byte);
4745
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8056
		/* Note: __value is reserved in Visual C++ 8 (2005) */
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8057
		int __val = __intVal(value);
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8058
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8059
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8060
		int __pixel, __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8061
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8062
		unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8063
		unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8064
4745
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8065
		__pixel = __greyPixels[__val];
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8066
		__grey = __greyErrors[__val];
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8067
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8068
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8069
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8070
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8071
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8072
		if (__grey > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8073
		    __pixel++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8074
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8075
		__byte = (__byte << __intVal(depth)) | __pixel;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8076
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8077
		__bitCnt = __bitCnt - __intVal(depth);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8078
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8079
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8080
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8081
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8082
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8083
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8084
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8085
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8086
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8087
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8088
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8089
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8090
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8091
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8092
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8093
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8094
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8095
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8096
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8097
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8098
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8099
	'Image [info]: slow ordered dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8100
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8101
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8102
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8103
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8104
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8105
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8106
	    "/ this is the representaion independent (but slow)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8107
	    "/ inner loop - it extracts colors from the receiver
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8108
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8109
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8110
		|dstClr grey dT pixel|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8111
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8112
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8113
		grey := clr brightness.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8114
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8115
		"/ remap into [0 .. greyLevels-1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8116
		grey := grey * (greyLevels-1).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8117
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8118
		"/ get threshold pixel [0 .. greyLevels-1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8119
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8120
		pixel := grey truncated.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8121
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8122
		"/ compute the error [0..1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8123
		grey := grey - pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8124
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8125
		"/ map into dither space [0 .. nDither]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8126
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8127
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8128
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8129
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8130
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8131
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8132
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8133
		int __pixel;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8134
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8135
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8136
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8137
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8138
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8139
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8140
		__pixel = __intVal(pixel);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8141
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8142
		if (__intVal(grey) > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8143
		    __pixel++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8144
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8145
		__byte = (__byte << __intVal(depth)) | __pixel;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8146
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8147
		__bitCnt = __bitCnt - __intVal(depth);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8148
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8149
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8150
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8151
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8152
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8153
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8154
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8155
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8156
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8157
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8158
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8159
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8160
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8161
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8162
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8163
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8164
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8165
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8166
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8167
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8168
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8169
    ^ outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8170
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8171
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8172
orderedDitheredMonochromeBits
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8173
    "return the bitmap for a dithered monochrome bitmap from the image;
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8174
     using a default ditherMatrix."
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8175
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8176
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8177
	orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8178
	ditherWidth:8
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8179
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8180
    "Created: 11.6.1996 / 16:48:57 / cg"
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8181
!
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8182
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8183
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8184
    "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
  8185
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8186
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8187
     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
  8188
     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
  8189
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8190
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8191
     greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8192
     dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8193
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8194
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8195
     monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8196
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8197
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8198
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8199
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8200
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8201
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8202
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8203
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8204
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8205
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8206
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8207
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8208
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8209
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8210
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8211
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8212
    self bitsPerPixel <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8213
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8214
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8215
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8216
	greyValues := self greyByteMapForRange:nDither.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8217
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8218
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8219
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8220
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8221
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8222
	    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
  8223
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8224
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8225
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8226
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8227
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8228
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8229
		int __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8230
		unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8231
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8232
		__grey = __greyValues[__intVal(value)];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8233
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8234
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8235
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8236
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8237
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8238
		__byte = __byte << 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8239
		if (__grey > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8240
		    __byte = __byte | 1;            /* white */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8241
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8242
		__bitCnt = __bitCnt - 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8243
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8244
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8245
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8246
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8247
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8248
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8249
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8250
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8251
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8252
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8253
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8254
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8255
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8256
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8257
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8258
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8259
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8260
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8261
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8262
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8263
	'Image [info]: slow ordered dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8264
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8265
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8266
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8267
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8268
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8269
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8270
		|dstClr grey dT|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8271
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8272
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8273
		grey := clr brightness.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8274
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8275
		"/ map into dither space [0 .. nDither]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8276
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8277
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8278
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8279
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8280
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8281
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8282
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8283
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8284
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8285
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8286
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8287
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8288
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8289
		__byte = __byte << 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8290
		if (__intVal(grey) > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8291
		    __byte = __byte | 1;            /* white */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8292
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8293
		__bitCnt = __bitCnt - 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8294
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8295
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8296
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8297
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8298
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8299
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8300
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8301
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8302
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8303
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8304
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8305
		0
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8306
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8307
"/                dT := ditherMatrix at:(x \\ dW) + (y \\ dH * dW) + 1.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8308
"/
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8309
"/                byte := byte bitShift:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8310
"/                grey < dT ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8311
"/                    byte := byte bitOr:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8312
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8313
"/                bitCnt := bitCnt - 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8314
"/                bitCnt == 0 ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8315
"/                    monoBits at:dstIndex put:byte.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8316
"/                    dstIndex := dstIndex + 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8317
"/                    byte := 0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8318
"/                    bitCnt := 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8319
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8320
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8321
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8322
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8323
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8324
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8325
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8326
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8327
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8328
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8329
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8330
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8331
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8332
stevensonArceDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8333
    "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
  8334
     Works for any source depths / photometric"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8335
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  8336
    |dstIndex        "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8337
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8338
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8339
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8340
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8341
     errorArray1 errorArray2 errorArray3
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8342
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8343
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8344
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8345
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8346
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  8347
     grey
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  8348
     xE              "{Class: SmallInteger }" |
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8349
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8350
    self depth > 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8351
	^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8352
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8353
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8354
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8355
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8356
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8357
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8358
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8359
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8360
    errorArray := Array new:(w+6).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8361
    errorArray1 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8362
    errorArray2 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8363
    errorArray3 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8364
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8365
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8366
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8367
    "/ 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
  8368
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8369
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8370
    greyValues := self greyMapForRange:(255 * 1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8371
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8372
    0 to:(h-1) do:[:y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8373
	nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8374
	byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8375
	bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8376
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8377
	t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8378
	errorArray := errorArray1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8379
	errorArray1 := errorArray2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8380
	errorArray2 := errorArray3.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8381
	errorArray3 := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8382
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8383
	errorArray3 atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8384
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8385
	self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8386
	    |eP eD|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8387
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8388
	    "/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8389
	    grey := greyValues at:(pixel + 1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8390
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8391
	    "/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8392
	    xE := x + 3 + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8393
	    grey := (grey + (errorArray at:xE)).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8394
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8395
	    byte := byte bitShift:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8396
	    grey > (127 * 1024) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8397
		byte := byte bitOr:1.      "/ white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8398
		e := grey - (255 * 1024)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8399
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8400
		e := grey                  "/ black
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8401
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8402
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8403
	    e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8404
		"/ distribute the error:
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8405
		"/                  XX    32
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8406
		"/         12    26    30    16
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8407
		"/            12    26    12
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8408
		"/          5    12    12     5
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8409
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8410
		eD := e.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8411
		e := e // 200.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8412
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8413
		eP := e * 32. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8414
		errorArray at:xE+2 put:(errorArray at:xE+2) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8415
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8416
		eP := e * 30. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8417
		errorArray1 at:xE+1 put:(errorArray1 at:xE+1) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8418
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8419
		eP := e * 16. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8420
		errorArray1 at:xE+3 put:(errorArray1 at:xE+3) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8421
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8422
		eP := e * 26. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8423
		errorArray1 at:xE-1 put:(errorArray1 at:xE-1) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8424
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8425
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8426
		errorArray2 at:xE put:(errorArray2 at:xE) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8427
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8428
		eP := e * 12. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8429
		errorArray1 at:xE-3 put:(errorArray1 at:xE-3) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8430
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8431
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8432
		errorArray2 at:xE-2 put:(errorArray2 at:xE-2) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8433
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8434
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8435
		errorArray2 at:xE+2 put:(errorArray2 at:xE+2) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8436
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8437
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8438
		errorArray3 at:xE-1 put:(errorArray3 at:xE-1) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8439
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8440
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8441
		errorArray3 at:xE+1 put:(errorArray3 at:xE+1) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8442
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8443
		eP := e * 5. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8444
		errorArray3 at:xE-3 put:(errorArray3 at:xE-3) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8445
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8446
		eP := eD.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8447
		errorArray3 at:xE+3 put:(errorArray3 at:xE+3) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8448
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8449
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8450
	    bitCnt := bitCnt - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8451
	    bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8452
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8453
		dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8454
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8455
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8456
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8457
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8458
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8459
	bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8460
	    byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8461
	    monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8462
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8463
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8464
	dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8465
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8466
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8467
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8468
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8469
    "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
  8470
    "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
  8471
! !
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8472
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8473
!Image methodsFor:'drawing'!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8474
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8475
drawRectangle: aRectangle withColor:aColor
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8476
    "draw a rectangle with some pixel value.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8477
     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
  8478
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8479
    |xI "{ Class: SmallInteger }"
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8480
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8481
     wI "{ Class: SmallInteger }"
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8482
     hI "{ Class: SmallInteger }"|
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8483
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8484
    xI := aRectangle left.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8485
    yI := aRectangle top.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8486
    wI := aRectangle width.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8487
    hI := aRectangle height.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8488
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8489
    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
  8490
	self atImageAndMask: xRun@yI put:aColor.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8491
	self atImageAndMask: xRun@(yI+hI-1) put:aColor
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8492
    ].
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8493
    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
  8494
	self atImageAndMask: xI@yRun put:aColor.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8495
	self atImageAndMask: xI+wI-1@yRun put:aColor
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8496
    ].
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8497
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8498
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8499
!
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8500
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8501
fillRectangle: aRectangle withColor:aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8502
    "draw a rectangle with some pixel value.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8503
    By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8504
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8505
    |xI "{ Class: SmallInteger }"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8506
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8507
     wI "{ Class: SmallInteger }"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8508
     hI "{ Class: SmallInteger }"|
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8509
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8510
    xI := aRectangle left.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8511
    yI := aRectangle top.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8512
    wI := aRectangle width.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8513
    hI := aRectangle height.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8514
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8515
    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
  8516
	xI to:xI+wI-1 do:[:xRun |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8517
	    self atImageAndMask:xRun@yRun put:aColor
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8518
	]
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8519
    ]
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8520
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8521
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8522
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8523
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8524
fillRectangleX:x y:y width:w height:h with:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8525
    "fill a rectangular area with a aColor"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8526
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8527
    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
  8528
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8529
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8530
fillRectangleX:x y:y width:w height:h withValue:aPixelValue
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8531
    "fill a rectangular area with some pixel value.
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8532
     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
  8533
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8534
    |xI "{ Class: SmallInteger }"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8535
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8536
     wI "{ Class: SmallInteger }"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8537
     hI "{ Class: SmallInteger }"|
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8538
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8539
    xI := x.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8540
    yI := y.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8541
    wI := w.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8542
    hI := h.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8543
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8544
    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
  8545
	xI to:xI+wI-1 do:[:xRun |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8546
	    self pixelAtX:xRun y:yRun put:aPixelValue
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8547
	]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8548
    ]
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8549
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  8550
    "Created: 22.4.1997 / 14:02:14 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8551
    "Modified: 24.4.1997 / 17:24:58 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8552
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8553
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8554
floodFillAt: aPoint withColor: aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8555
    "fill a area with aColor like a flood up to surrounded pixels having different colors.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8556
     By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8557
4420
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  8558
    |surroundingPixelsOfDo detectedPixel processPixelToFill
3861
e9cbd4ec6020 flood fill with mask fixed
Claus Gittinger <cg@exept.de>
parents: 3860
diff changeset
  8559
     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
3760
dd2ae9dd870d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3759
diff changeset
  8560
     toDo idx pixel w h|
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8561
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8562
    w := self width.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8563
    h := self height.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8564
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8565
    surroundingPixelsOfDo :=
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8566
	[:pX :pY :fn |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8567
	    |nX nY|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8568
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8569
	    nX := pX + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8570
	    nY := pY + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8571
	    (nY < h) ifTrue: [fn value:pX value:nY].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8572
	    (pY > 0) ifTrue: [fn value:pX value:(pY - 1)].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8573
	    (nX < w) ifTrue: [fn value:nX value:pY].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8574
	    (pX > 0) ifTrue: [fn value:(pX - 1) value:pY].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8575
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8576
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8577
    enumerateDetectedPixelsAndDo :=
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8578
	[:detectedPixels :action |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8579
	    |idx|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8580
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8581
	    idx := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8582
	    0 to:h-1 do:[:y |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8583
		0 to:w-1 do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8584
		    (detectedPixels at:idx) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8585
			action value:x value:y
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8586
		    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8587
		    idx := idx + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8588
		].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8589
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8590
	].
4420
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  8591
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  8592
    processPixelToFill := [:spX :spY |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8593
	    |sp idx|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8594
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8595
	    ((self pixelAtX:spX y:spY) == detectedPixel and: [mask isNil or:[(mask pixelAtX:spX y:spY) == 1]])
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8596
	    ifTrue: [
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8597
		idx := 1 + spX + (spY * w).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8598
		(allDetectedPixelCoordinates at:idx) ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8599
		    allDetectedPixelCoordinates at:idx put:true.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8600
		    toDo add:spX @ spY.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8601
		].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8602
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8603
	].
3861
e9cbd4ec6020 flood fill with mask fixed
Claus Gittinger <cg@exept.de>
parents: 3860
diff changeset
  8604
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8605
    (mask notNil and: [(mask pixelAt:aPoint) == 0]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8606
	allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8607
	enumerateDetectedPixelsAndDo
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8608
		value:allDetectedPixelCoordinates
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8609
		value:[:x :y | self atImageAndMask:(x@y) put: aColor].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8610
	^ allDetectedPixelCoordinates
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8611
    ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8612
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8613
    detectedPixel := self pixelAt: aPoint.
4420
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  8614
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8615
    allDetectedPixelCoordinates := BooleanArray new:(w * h).
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8616
    toDo := OrderedCollection new:1000.
3760
dd2ae9dd870d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3759
diff changeset
  8617
    allDetectedPixelCoordinates at:(1 + aPoint x + (aPoint y * w)) put:true.
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8618
    toDo add:aPoint.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8619
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8620
    [toDo notEmpty] whileTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8621
	|p|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8622
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8623
	p := toDo removeFirst.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8624
	surroundingPixelsOfDo value:p x value:p y value:processPixelToFill.
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8625
    ].
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8626
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  8627
    idx := 1.
4420
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  8628
    aColor redByte notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8629
	pixel := self valueFromColor:aColor.
4420
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  8630
    ].
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  8631
3805
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  8632
    pixel isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8633
	enumerateDetectedPixelsAndDo
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8634
		value:allDetectedPixelCoordinates
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8635
		value:[:x :y | mask pixelAtX:x y:y put:0].
3805
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  8636
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8637
	enumerateDetectedPixelsAndDo
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8638
		value:allDetectedPixelCoordinates
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8639
		value:[:x :y | self pixelAtX:x y:y put:pixel].
3805
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  8640
    ].
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  8641
    ^ allDetectedPixelCoordinates
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8642
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  8643
    "Modified: / 29.7.1998 / 03:09:16 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8644
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8645
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8646
rectangle: aRectangle withColor:aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8647
    "draw a rectangle with some pixel value.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8648
    By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8649
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8650
    self obsoleteMethodWarning.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8651
    self drawRectangle: aRectangle withColor:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8652
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  8653
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8654
! !
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8655
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8656
!Image methodsFor:'enumerating'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8657
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8658
atY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8659
    "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
  8660
     The block is passed the color at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8661
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8662
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8663
     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
  8664
     and also the color allocation)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8665
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  8666
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  8667
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8668
    self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8669
    self colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8670
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8671
    "Modified: 7.6.1996 / 19:13:30 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8672
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8673
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8674
colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8675
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8676
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8677
     The code here provides a generic and slow implementation, and
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8678
     should be redefined in concrete subclasses, to avoid some processing
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8679
     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
  8680
     and also the color allocation)."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8681
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8682
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8683
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8684
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8685
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8686
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8687
    xStart to:xEnd do:[:xRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8688
	aBlock value:xRun value:(self colorAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8689
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8690
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  8691
    "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
  8692
    "Modified: / 30.9.1998 / 22:14:16 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8693
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8694
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8695
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8696
    "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
  8697
     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
  8698
     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
  8699
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8700
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8701
     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
  8702
     and especially, the color allocations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8703
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  8704
    |yS "{Class: SmallInteger }"
942
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  8705
     yE "{Class: SmallInteger }"
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  8706
     yR|
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  8707
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  8708
    yS := yStart.
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  8709
    yE := yEnd.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  8710
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8711
    yS to:yE do:[:yRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8712
	yR := yRun.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8713
	self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8714
	    aBlock value:xRun value:yR value:color
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8715
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8716
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8717
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  8718
    "Modified: 11.7.1996 / 19:50:47 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8719
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8720
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8721
valueAtY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8722
    "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
  8723
     Obsolete - remains for backward compatibility."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8724
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  8725
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  8726
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8727
    self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8728
    self valuesAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8729
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8730
    "Modified: 7.6.1996 / 19:11:06 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8731
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8732
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8733
valuesAtY:y from:x1 to:x2 do:aBlock
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8734
    "WARNING: for now, this enumerates pixel values
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8735
     (backward compatibility with ST/X)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8736
     In the future, this will enumerate colors
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8737
     Use #pixelAtT:from:to:do: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8738
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8739
     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
  8740
     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
  8741
     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
  8742
     (see also Image>>atY:from:to:do:).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8743
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8744
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8745
     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
  8746
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8747
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8748
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8749
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8750
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8751
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8752
    xStart to:xEnd do:[:xRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8753
	aBlock value:xRun value:(self pixelAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8754
    ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  8755
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8756
    "Created: 7.6.1996 / 19:09:51 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  8757
    "Modified: 24.4.1997 / 16:55:38 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8758
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8759
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8760
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8761
    "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
  8762
     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
  8763
     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
  8764
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8765
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8766
     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
  8767
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8768
    |xS "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8769
     xE "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8770
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8771
    xS := xStart.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8772
    xE := xEnd.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8773
    yStart to:yEnd do:[:yRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8774
	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
  8775
	    aBlock value:xRun value:yRun value:pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8776
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8777
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8778
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  8779
    "Modified: 7.6.1996 / 19:09:29 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8780
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  8781
3613
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8782
!Image methodsFor:'finalization'!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8783
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8784
finalizationLobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8785
    "answer the registry used for finalization.
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8786
     Images have their own Registry"
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8787
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8788
    ^ Lobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8789
!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8790
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8791
finalize
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8792
    "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
  8793
! !
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  8794
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  8795
!Image methodsFor:'image manipulations'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  8796
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8797
applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8798
    "helper for withPixelFunctionAppliedToValues:
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  8799
     enumerate pixelValues and evaluate the block for each.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8800
     Could be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8801
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8802
    |w   "{Class: SmallInteger }"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8803
     h   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8804
     x0  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8805
     y0  "{Class: SmallInteger }"
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8806
     y   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8807
     newPixel newPixelRow pixelRow|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8808
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8809
    x0 := aRectangle left.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8810
    y0 := aRectangle top.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8811
    w := aRectangle width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8812
    h := aRectangle height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8813
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8814
    newPixelRow := Array new:w.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8815
    pixelRow := self pixelArraySpecies new:width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8816
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8817
    (x0 = 0 and:[w = self width]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8818
	"/ slightly faster
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8819
	y := y0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8820
	h timesRepeat:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8821
	    self rowAt:y into:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8822
	    1 to:w do:[:runCol |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8823
		newPixel := pixelFunctionBlock
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8824
				value:self
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8825
				value:(pixelRow at:runCol)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8826
				value:(runCol-1)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8827
				value:y.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8828
		newPixelRow at:runCol put:newPixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8829
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8830
	    newImage rowAt:y putAll:newPixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8831
	    y := y + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8832
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8833
	^ self.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8834
    ].
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8835
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8836
    y := y0.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8837
    h timesRepeat:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8838
	self rowAt:y into:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8839
	1 to:w do:[:runCol |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8840
	    newPixel := pixelFunctionBlock
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8841
			    value:self
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8842
			    value:(pixelRow at:runCol+x0)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8843
			    value:(runCol+x0-1)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8844
			    value:y.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8845
	    newPixelRow at:runCol put:newPixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8846
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8847
	pixelRow replaceFrom:x0+1 to:x0+1+w-1 with:newPixelRow startingAt:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8848
	newImage rowAt:y putAll:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8849
	y := y + 1.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8850
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8851
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8852
    "Modified: 24.4.1997 / 16:18:31 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8853
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  8854
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8855
applyPixelValuesTo:pixelFunctionBlock into:newImage
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8856
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8857
     enumerate pixelValues and evaluate the block for each."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8858
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8859
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8860
	applyPixelValuesTo:pixelFunctionBlock
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8861
	in:(0@0 corner:width@height)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8862
	into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8863
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  8864
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8865
blendWith:aColor
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8866
    "return a new image which is blended with some color.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8867
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8868
     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
  8869
     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
  8870
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8871
     ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8872
	copyWithColorMapProcessing:[:clr | clr blendWith:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8873
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8874
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8875
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8876
     ((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
  8877
     ((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
  8878
     ((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
  8879
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8880
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8881
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8882
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8883
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8884
colorMapProcessing:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8885
    "a helper for all kinds of colormap manipulations.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8886
     The argument, aBlock is called for every colormap entry,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8887
     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
  8888
     This will fail for non-palette images.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8889
     See examples in Image>>copyWithColorMapProcessing:"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8890
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8891
    |nColors "{ Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8892
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8893
    colorMap isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8894
	self colorsFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8895
	    self colorAtX:x y:y put:(aBlock value:clr)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8896
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8897
	^ self
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8898
    ].
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
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8901
    1 to:nColors do:[:index |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8902
	|clr|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8903
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8904
	clr := colorMap at:index.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8905
	clr notNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8906
	    colorMap at:index put:(aBlock value:clr)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8907
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8908
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8909
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  8910
    "Modified: 23.4.1996 / 11:13:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8911
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8912
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8913
copyWithColorMapProcessing:aBlock
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8914
    "a helper to create & return new images based on the receiver with
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8915
     some colorMap processing. The receiver is copied, and the copied images
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8916
     colormap is modified by replacing entries with the result of the processing block,
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8917
     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
  8918
     a color.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8919
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale)"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8920
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8921
    |newImage|
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8922
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  8923
    self colorMap isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8924
	^ self withPixelFunctionApplied:[:orig :clr :x :y | aBlock  value:clr]
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  8925
"/        self error:'no colormap in image'.
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  8926
"/        ^ nil
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8927
    ].
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8928
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8929
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8930
     the code below manipulates the colormap.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8931
     For non-palette images, special code is required
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8932
    "
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  8933
    newImage := self copy.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8934
    newImage colorMapProcessing:aBlock.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8935
    ^ newImage
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8936
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8937
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8938
     leave red component only:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8939
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8940
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8941
	copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8942
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8943
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8944
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8945
     make it reddish:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8946
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8947
     (Image fromFile:'bitmaps/gifImages/claus.gif')
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8948
	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
  8949
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8950
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8951
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8952
     invert:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8953
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8954
     (Image fromFile:'bitmaps/gifImages/claus.gif')
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8955
	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
  8956
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8957
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8958
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8959
     lighter:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8960
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8961
     (Image fromFile:'bitmaps/gifImages/claus.gif')
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8962
	copyWithColorMapProcessing:[:clr | |r g b|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8963
						r := clr red.  g := clr green.  b := clr blue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8964
						Color red:(r + (100-r//2))
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8965
						      green:(g + (100-g//2))
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8966
						      blue:(b + (100-b//2))]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8967
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  8968
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8969
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8970
     darker:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8971
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8972
     (Image fromFile:'bitmaps/gifImages/claus.gif')
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8973
	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
  8974
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8975
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8976
    "Modified: 24.4.1997 / 18:28:05 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8977
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  8978
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8979
createMask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8980
    |maskArray bytesPerMaskRow|
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8981
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8982
    bytesPerMaskRow := (width+7) // 8.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8983
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8984
    maskArray := ByteArray new:(bytesPerMaskRow * height) withAll:2r11111111.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8985
    mask := ImageMask width:width height:height fromArray:maskArray.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8986
    ^ mask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8987
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  8988
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8989
darkened
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8990
    "return a new image which is slightly darker than the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  8991
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8992
     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
  8993
     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
  8994
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8995
     ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8996
	copyWithColorMapProcessing:[:clr | clr darkened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8997
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  8998
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  8999
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9000
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9001
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9002
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9003
    "Modified: 24.4.1997 / 18:28:31 / cg"
283
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
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9006
easyRotateBitsInto:destinationImage angle:degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9007
    "helper for rotation - does the actual pixel shuffling.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9008
     by degrees clockwise. Here, only 90, 180 and 270 degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9009
     are implemented. Hard angles are done in #hardRotate:.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9010
     The code here is depth-independent (but not too fast);
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9011
     can be redefined in subclasses for more performance"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9012
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9013
    |w  "{Class: SmallInteger }"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9014
     h  "{Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9015
     c2 r2 pixelArray|
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9016
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9017
    w := width - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9018
    h := height - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9019
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9020
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9021
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9022
    degrees = 90 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9023
	0 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9024
	    self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9025
	    c2 := h-row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9026
	    0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9027
		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
  9028
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9029
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9030
	^ self.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9031
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9032
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9033
    degrees = 180 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9034
	0 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9035
	    self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9036
	    r2 := h - row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9037
	    0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9038
		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
  9039
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9040
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9041
	^ self
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9042
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9043
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9044
    "/ degrees = 270
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9045
    0 to:h do:[:row |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9046
	self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9047
	0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9048
	    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
  9049
	]
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9050
    ]
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9051
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9052
    "Created: 23.4.1997 / 14:36:45 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9053
    "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
  9054
!
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9055
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9056
flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9057
    "destructively inplace horizontal flip"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9058
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9059
    |h  "{Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9060
     pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9061
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9062
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9063
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9064
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9065
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9066
    0 to:h do:[:row |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9067
	self rowAt:row into:pixelArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9068
	pixelArray reverse.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9069
	self rowAt:row putAll:pixelArray.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9070
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9071
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9072
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9073
	mask flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9074
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9075
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9076
    "/ flush device info
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9077
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9078
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9079
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9080
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipHorizontal inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9081
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9082
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9083
    "Modified: 24.4.1997 / 18:29:13 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9084
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9085
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9086
flipVertical
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9087
    "inplace vertical flip"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9088
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9089
    |h           "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9090
     bytesPerRow "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9091
     buffer
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9092
     indexLow    "{Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9093
     indexHi     "{Class: SmallInteger }"
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9094
     bytes|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9095
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9096
    bytes := self bits.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9097
    bytesPerRow := self bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9098
    buffer := ByteArray new:bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9099
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9100
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9101
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9102
    indexLow := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9103
    indexHi := bytesPerRow * h + 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9104
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9105
    0 to:(h // 2) do:[:row |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9106
	buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9107
	bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9108
	bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9109
	indexLow := indexLow + bytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9110
	indexHi := indexHi - bytesPerRow.
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9111
    ].
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9112
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9113
	mask flipVertical
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9114
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9115
    "flush device info"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9116
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9117
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9118
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9119
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipVertical inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9120
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9121
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9122
    "Modified: 24.4.1997 / 18:29:36 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9123
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9124
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9125
hardAntiAliasedMagnifiedBy:scalePoint
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9126
    "return a new image magnified and antiAliased by scalePoint, aPoint.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9127
     This converts into a depth24Image before doing the antiAlias-magnify.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9128
     It is definitely slower than the non antiAliasing/integral magnification methods."
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9129
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9130
    ^ (Depth24Image fromImage:self)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9131
	hardAntiAliasedMagnifiedBy:scalePoint
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9132
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9133
    "Modified: 2.6.1997 / 13:19:57 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9134
    "Created: 2.6.1997 / 15:53:34 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9135
!
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9136
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9137
hardMagnifiedBy:scalePoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9138
    "return a new image magnified by scalePoint, aPoint.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9139
     This is the general magnification method, handling non-integral values.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9140
     It is slower than the integral magnification method."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9141
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9142
    |mX
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9143
     mY
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9144
     newWidth  "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9145
     newHeight "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9146
     w         "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9147
     h         "{ Class: SmallInteger }"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9148
     newImage newBits bitsPerPixel newBytesPerRow newMask
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9149
     value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9150
     srcRow pixelArray|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9151
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9152
    mX := scalePoint x.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9153
    mY := scalePoint y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9154
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9155
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9156
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9157
    newWidth := (width * mX) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9158
    newHeight := (height * mY) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9159
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9160
    bitsPerPixel := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9161
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9162
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9163
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9164
    mask notNil ifTrue:[
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9165
        newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9166
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9167
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9168
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9169
    newImage
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9170
        width:newWidth
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9171
        height:newHeight
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9172
        photometric:photometric
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9173
        samplesPerPixel:samplesPerPixel
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9174
        bitsPerSample:bitsPerSample
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9175
        colorMap:colorMap copy
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9176
        bits:newBits
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9177
        mask:newMask.
905
228d503775d9 everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  9178
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9179
    "walk over destination image fetching pixels from source image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9180
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9181
    w := newWidth - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9182
    h := newHeight - 1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9183
    pixelArray := newImage pixelArraySpecies new:newWidth.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9184
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9185
    0 to:h do:[:row |
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9186
        srcRow := (row // mY).
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9187
        0 to:w do:[:col |
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9188
            value := self pixelAtX:(col // mX) y:srcRow.
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9189
            pixelArray at:(col+1) put:value.
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9190
        ].
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9191
        newImage rowAt:row putAll:pixelArray.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9192
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9193
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9194
    ^ newImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9195
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9196
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9197
     |i|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9198
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9199
     Time millisecondsToRun:[
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9200
         i := i hardMagnifiedBy:0.5@0.5
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9201
     ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9202
     i
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9203
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9204
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9205
    "Modified: 24.4.1997 / 18:30:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9206
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9207
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9208
hardRotated:degrees
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9209
    "return a new image from the old one, by rotating the image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9210
     degrees clockwise.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9211
     Warning: the returned image will be larger than the original image."
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9212
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9213
    |p r a aN p1 p2 p3 p4 maxX minX maxY minY
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9214
     newImage
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9215
     newWidth  "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9216
     newHeight "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9217
     newBytesPerRow newBits
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9218
     blackPixel halfW halfH radians m t bad
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9219
     bytesPerRow myDepth maskBits
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9220
     pX pY srcX srcY pix nX nY
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9221
     sinRot cosRot sinPY cosPY|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9222
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9223
    radians := degrees degreesToRadians.
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9224
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9225
    "/ placing the image at the origin,
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9226
    "/ compute the diagonal and angle.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9227
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9228
    p := (width - 1 / 2) @ (height - 1 / 2).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9229
    r := p r.
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9230
    a := p theta.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9231
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9232
    "/ add the rotation
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9233
    "/ (sight - subtract, we defined things clockwise ...
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9234
    "/  ... in contrast to point which thinks counter-clockwise)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9235
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9236
    aN := a - radians.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9237
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9238
    "/ compute new corner points
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9239
    p1 := Point r:r theta:aN.         "/ rotated topRight
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9240
    p2 := Point r:r theta:aN-a-a.     "/ rotated bottomRight
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9241
    p3 := p1 * -1.                    "/ rotated bottomLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9242
    p4 := p2 * -1.                    "/ rotated topLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9243
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9244
    "/ compute the boundary of the new image
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9245
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9246
    maxX := minX := p1 x.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9247
    (t := p2 x) > maxX ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9248
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9249
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9250
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9251
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9252
    (t := p3 x) > maxX ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9253
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9254
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9255
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9256
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9257
    (t := p4 x) > maxX ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9258
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9259
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9260
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9261
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9262
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9263
    maxY := minY := p1 y.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9264
    (t := p2 y) > maxY ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9265
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9266
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9267
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9268
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9269
    (t := p3 y) > maxY ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9270
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9271
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9272
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9273
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9274
    (t := p4 y) > maxY ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9275
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9276
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9277
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9278
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9279
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9280
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9281
    newWidth := (maxX - minX) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9282
    newHeight := (maxY - minY) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9283
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9284
    newImage := self species new.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9285
    newImage width:newWidth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9286
    newImage height:newHeight.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9287
    newBytesPerRow := newImage bytesPerRow.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  9288
    newImage createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  9289
    newBits := newImage bits.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9290
    newImage photometric:photometric.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9291
    newImage samplesPerPixel:samplesPerPixel.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9292
    newImage bitsPerSample:bitsPerSample.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9293
    newImage colorMap:colorMap copy.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9294
    newImage maskedPixelsAre0:maskedPixelsAre0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9295
    mask notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9296
	newImage mask:(mask rotated:degrees)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9297
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9298
	self isMask ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9299
	    self depth ~~ 1 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9300
		m := ImageMask width:width height:height.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9301
		m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9302
		maskBits atAllPut:16rFF.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9303
		newImage mask:(m rotated:degrees)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9304
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9305
	]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9306
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9307
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9308
    maskedPixelsAre0 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9309
	blackPixel := 0.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9310
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9311
	blackPixel := self valueFromColor:Color black.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9312
	blackPixel isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9313
	    blackPixel := self valueFromColor:Color white.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9314
	    blackPixel isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9315
		blackPixel := 0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9316
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9317
	]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9318
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9319
    self isMask ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9320
	blackPixel := 0.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9321
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9322
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9323
    myDepth := self depth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9324
    newBits atAllPut:0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9325
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9326
    "/ now, walk over destination pixels,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9327
    "/ fetching from source.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9328
    "/ (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
  9329
    "/  in the destination image ...)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9330
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9331
    halfW := (width - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9332
    halfH := (height - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9333
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9334
    bytesPerRow := self bytesPerRow.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9335
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9336
%{
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9337
    int __newHeight = __intVal(newHeight);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9338
    int __newWidth = __intVal(newWidth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9339
    int __height = __intVal(__INST(height));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9340
    int __width = __intVal(__INST(width));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9341
    double __minX, __minY, __radians;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9342
    double __halfW, __halfH;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9343
    int __dstX, __dstY;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9344
    int __depth = __intVal(myDepth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9345
    unsigned char *__srcBytes, *__dstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9346
    unsigned char *__dstPtr, *__dstRowPtr, *__dstEndPtr;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9347
    int __nSrcBytes, __nDstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9348
    int __srcBytesPerRow = __intVal(bytesPerRow);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9349
    int __dstBytesPerRow = __intVal(newBytesPerRow);
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9350
    int __dstMask, __blackPixel;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9351
    double __sin, __cos;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9352
    double sin(), cos();
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9353
#   define Float_PI 3.14159
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9354
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9355
    bad = true;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9356
    if (1
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9357
     && __isFloat(minX)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9358
     && __isFloat(minY)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9359
     && __isFloat(radians)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9360
     && __isFloat(halfW)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9361
     && __isFloat(halfH)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9362
     && __isByteArray(newBits)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9363
     && __isByteArray(__INST(bytes))) {
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9364
	__srcBytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9365
	__dstBytes = __ByteArrayInstPtr(newBits)->ba_element;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9366
	__nSrcBytes = __byteArraySize(__INST(bytes));
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9367
	__nDstBytes = __byteArraySize(newBits);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9368
	__blackPixel = __intVal(blackPixel);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9369
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9370
	__radians = __floatVal(radians);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9371
	__radians = -__radians; /* sigh: clock-wise */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9372
	__sin = sin(__radians);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9373
	__cos = cos(__radians);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9374
	__minX = __floatVal(minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9375
	__minY = __floatVal(minY);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9376
	__halfW = __floatVal(halfW);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9377
	__halfH = __floatVal(halfH);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9378
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9379
	__dstRowPtr = __dstBytes;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9380
	__dstEndPtr = __dstBytes + __nDstBytes;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9381
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9382
#       define EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9383
#       define FAST_ADVANCE 5
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9384
#       define FAST_ADVANCE2
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9385
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9386
	switch (__depth) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9387
	    case 8:
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9388
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9389
		    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9390
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9391
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9392
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9393
		    __pY = (double)(__dstY + __minY);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9394
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9395
		    __sinPY = __sin * __pY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9396
		    __cosPY = __cos * __pY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9397
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9398
		    __dstPtr = __dstRowPtr;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9399
		    __dstRowPtr += __dstBytesPerRow;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9400
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9401
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9402
			double __pX, __nX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9403
			unsigned __pix;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9404
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9405
			/* translate X in destination (center to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9406
			__pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9407
			/* rotate X */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9408
			__nX = (__cos * __pX) - __sinPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9409
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9410
			/* translate X in source (origin to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9411
			__nX = __nX + __halfW + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9412
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9413
			/* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9414
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9415
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9416
			    if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9417
				break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9418
			    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9419
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9420
#ifdef FAST_ADVANCE
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9421
			    if (__blackPixel == 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9422
				do {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9423
				    /* try advance by FAST_ADVANCE pixels ... */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9424
				    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9425
				    if (__dstX >= __newWidth) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9426
					break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9427
				    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9428
				    __pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9429
				    __nX = (__cos * __pX) - __sinPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9430
				    __nX = __nX + __halfW + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9431
				} while (__nX < 0);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9432
				__dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9433
			    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9434
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9435
			    __pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9436
			} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9437
			    int __srcX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9438
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9439
			    __srcX = (int)__nX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9440
			    /* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9441
			    if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9442
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9443
				if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9444
				    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9445
				}
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9446
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9447
#ifdef FAST_ADVANCE2
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9448
				if (__blackPixel == 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9449
				    do {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9450
					/* try advance by FAST_ADVANCE pixels ... */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9451
					__dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9452
					if (__dstX >= __newWidth) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9453
					    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9454
					}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9455
					__pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9456
					__nX = (__cos * __pX) - __sinPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9457
					__nX = __nX + __halfW + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9458
					__srcX = (int)__nX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9459
				    } while (__srcX >= __width);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9460
				    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9461
				}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9462
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9463
				__pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9464
			    } else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9465
				double __nY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9466
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9467
				/* rotate Y */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9468
				__nY = (__sin * __pX) + __cosPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9469
				/* translate Y in source (origin to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9470
				__nY = __nY + __halfH + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9471
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9472
				/* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9473
				if (__nY < 0) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9474
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9475
				    if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9476
					break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9477
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9478
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9479
#ifdef FAST_ADVANCE2
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9480
				    if (__blackPixel == 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9481
					do {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9482
					    /* try advance by FAST_ADVANCE pixels ... */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9483
					    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9484
					    if (__dstX >= __newWidth) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9485
						break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9486
					    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9487
					    __pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9488
					    __nY = (__sin * __pX) + __cosPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9489
					    __nY = __nY + __halfH + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9490
					} while (__nY < 0);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9491
					__dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9492
				    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9493
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9494
				    __pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9495
				} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9496
				    int __srcY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9497
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9498
				    __srcY = (int)__nY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9499
				    /* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9500
				    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9501
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9502
					if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9503
					    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9504
					}
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9505
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9506
#ifdef FAST_ADVANCE
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9507
					if (__blackPixel == 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9508
					    do {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9509
						/* try advance by FAST_ADVANCE pixels ... */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9510
						__dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9511
						if (__dstX >= __newWidth) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9512
						    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9513
						}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9514
						__pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9515
						__nY = (__sin * __pX) + __cosPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9516
						__nY = __nY + __halfH + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9517
						__srcY = (int)__nY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9518
					    } while (__srcY >= __height);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9519
					    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9520
					}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9521
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9522
					__pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9523
				    } else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9524
					/* fetch source pixel */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9525
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9526
					int idx;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9527
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9528
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9529
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9530
					idx = __srcY * __srcBytesPerRow + __srcX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9531
					if ((unsigned)idx < __nSrcBytes) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9532
					    __pix = __srcBytes[idx];
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9533
					} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9534
					    __pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9535
					}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9536
				    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9537
				}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9538
			    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9539
			}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9540
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9541
			if (__pix != 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9542
			    *__dstPtr = __pix;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9543
			}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9544
			__dstPtr++;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9545
		    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9546
		}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9547
		break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9548
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9549
	    case 1:
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9550
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9551
		    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9552
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9553
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9554
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9555
		    __pY = (double)(__dstY + __minY);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9556
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9557
		    __sinPY = __sin * __pY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9558
		    __cosPY = __cos * __pY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9559
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9560
		    __dstPtr = __dstRowPtr;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9561
		    __dstMask = 0x80;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9562
		    __dstRowPtr += __dstBytesPerRow;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9563
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9564
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9565
			double __pX, __nX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9566
			int __pix;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9567
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9568
			/* translate X in destination (center to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9569
			__pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9570
			/* rotate X */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9571
			__nX = (__cos * __pX) - __sinPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9572
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9573
			/* translate X in source (origin to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9574
			__nX = __nX + __halfW + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9575
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9576
			/* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9577
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9578
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9579
			    if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9580
				break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9581
			    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9582
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9583
#ifdef FAST_ADVANCE
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9584
			    if (__blackPixel == 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9585
				do {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9586
				    /* try advance by 8 pixels ... */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9587
				    __dstX += 8; __dstPtr ++;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9588
				    if (__dstX >= __newWidth) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9589
					break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9590
				    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9591
				    __pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9592
				    __nX = (__cos * __pX) - __sinPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9593
				    __nX = __nX + __halfW + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9594
				} while (__nX < 0);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9595
				__dstX -= 8; __dstPtr--;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9596
			    }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9597
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9598
			    __pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9599
			} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9600
			    int __srcX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9601
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9602
			    __srcX = (int)__nX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9603
			    /* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9604
			    if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9605
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9606
				if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9607
				    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9608
				}
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9609
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9610
#ifdef FAST_ADVANCE2
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9611
				if (__blackPixel == 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9612
				    do {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9613
					/* try advance by 8 pixels ... */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9614
					__dstX += 8; __dstPtr++;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9615
					if (__dstX >= __newWidth) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9616
					    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9617
					}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9618
					__pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9619
					__nX = (__cos * __pX) - __sinPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9620
					__nX = __nX + __halfW + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9621
					__srcX = (int)__nX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9622
				    } while (__srcX >= __width);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9623
				    __dstX -= 8; __dstPtr--;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9624
				}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9625
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9626
				__pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9627
			    } else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9628
				double __nY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9629
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9630
				/* rotate Y */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9631
				__nY = (__sin * __pX) + __cosPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9632
				/* translate Y in source (origin to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9633
				__nY = __nY + __halfH + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9634
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9635
				/* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9636
				if (__nY < 0) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9637
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9638
				    if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9639
					break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9640
				    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9641
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9642
#ifdef FAST_ADVANCE2
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9643
				    if (__blackPixel == 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9644
					do {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9645
					    /* try advance by 8 pixels ... */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9646
					    __dstX += 8; __dstPtr++;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9647
					    if (__dstX >= __newWidth) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9648
						break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9649
					    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9650
					    __pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9651
					    __nY = (__sin * __pX) + __cosPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9652
					    __nY = __nY + __halfH + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9653
					} while (__nY < 0);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9654
					__dstX -= 8; __dstPtr--;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9655
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9656
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9657
				    __pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9658
				} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9659
				    int __srcY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9660
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9661
				    __srcY = (int)__nY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9662
				    /* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9663
				    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9664
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9665
					if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9666
					    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9667
					}
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9668
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9669
#ifdef FAST_ADVANCE
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9670
					if (__blackPixel == 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9671
					    do {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9672
						/* try advance by 8 pixels ... */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9673
						__dstX += 8; __dstPtr++;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9674
						if (__dstX >= __newWidth) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9675
						    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9676
						}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9677
						__pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9678
						__nY = (__sin * __pX) + __cosPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9679
						__nY = __nY + __halfH + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9680
						__srcY = (int)__nY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9681
					    } while (__srcY >= __height);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9682
					    __dstX -= 8; __dstPtr--;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9683
					}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9684
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9685
					__pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9686
				    } else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9687
					/* fetch source pixel */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9688
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9689
					int idx, pV;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9690
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9691
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9692
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9693
					idx = __srcY * __srcBytesPerRow + (__srcX >> 3);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9694
					if ((unsigned)idx < __nSrcBytes) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9695
					    pV = __srcBytes[idx];
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9696
					    __pix = (pV & (0x80 >> (__srcX & 7))) ? 1 : 0;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9697
					} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9698
					    __pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9699
					}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9700
				    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9701
				}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9702
			    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9703
			}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9704
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9705
			/* store pixel */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9706
			if (__pix != 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9707
			    *__dstPtr |= __dstMask;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9708
			}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9709
			__dstMask >>= 1;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9710
			if (__dstMask == 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9711
			    __dstMask = 0x80;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9712
			    __dstPtr++;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9713
			}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9714
		    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9715
		}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9716
		break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9718
	    case 24:
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9719
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9720
		    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9721
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9722
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9723
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9724
		    __pY = (double)(__dstY + __minY);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9725
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9726
		    __sinPY = __sin * __pY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9727
		    __cosPY = __cos * __pY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9728
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9729
		    __dstPtr = __dstRowPtr;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9730
		    __dstRowPtr += __dstBytesPerRow;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9731
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9732
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9733
			double __pX, __nX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9734
			unsigned __pix;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9735
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9736
			/* translate X in destination (center to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9737
			__pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9738
			/* rotate X */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9739
			__nX = (__cos * __pX) - __sinPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9740
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9741
			/* translate X in source (origin to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9742
			__nX = __nX + __halfW + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9743
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9744
			/* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9745
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9746
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9747
			    if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9748
				break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9749
			    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
  9750
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9751
			    __pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9752
			} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9753
			    int __srcX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9754
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9755
			    __srcX = (int)__nX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9756
			    /* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9757
			    if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9758
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9759
				if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9760
				    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9761
				}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9762
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9763
				__pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9764
			    } else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9765
				double __nY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9766
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9767
				/* rotate Y */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9768
				__nY = (__sin * __pX) + __cosPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9769
				/* translate Y in source (origin to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9770
				__nY = __nY + __halfH + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9771
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9772
				/* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9773
				if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9774
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9775
				    if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9776
					break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9777
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9778
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9779
				    __pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9780
				} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9781
				    int __srcY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9782
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9783
				    __srcY = (int)__nY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9784
				    /* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9785
				    if (__srcY >= __height) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9786
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9787
					if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9788
					    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9789
					}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9790
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9791
					__pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9792
				    } else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9793
					/* fetch source pixel */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9794
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9795
					int idx;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9796
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9797
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9798
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9799
					idx = __srcY * __srcBytesPerRow + __srcX + __srcX + __srcX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9800
					if ((unsigned)idx < __nSrcBytes) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9801
					    __pix = __srcBytes[idx];
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9802
					    __pix = (__pix<<8) | __srcBytes[idx+1];
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9803
					    __pix = (__pix<<8) | __srcBytes[idx+2];
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9804
					} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9805
					    __pix = __blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9806
					}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9807
				    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9808
				}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9809
			    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9810
			}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9811
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9812
			/* store pixel */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9813
			if (__pix != 0) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9814
			    __dstPtr[0] = (__pix >> 16 & 0xFF);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9815
			    __dstPtr[1] = (__pix >> 8) & 0xFF;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9816
			    __dstPtr[2] = __pix & 0xFF;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9817
			}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9818
			__dstPtr += 3;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9819
		    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9820
		}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9821
		break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9822
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9823
	    default:
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9824
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9825
		    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9826
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9827
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9828
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9829
		    __pY = (double)(__dstY + __minY);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9830
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9831
		    __sinPY = __sin * __pY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9832
		    __cosPY = __cos * __pY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9833
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9834
		    __dstPtr = __dstRowPtr;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9835
		    __dstMask = 0x80;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9836
		    __dstRowPtr += __dstBytesPerRow;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9837
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9838
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9839
			double __pX, __nX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9840
			OBJ __pix;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9841
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9842
			/* translate X in destination (center to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9843
			__pX = (double)(__dstX + __minX);
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9844
			/* rotate X */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9845
			__nX = (__cos * __pX) - __sinPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9846
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9847
			/* translate X in source (origin to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9848
			__nX = __nX + __halfW + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9849
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9850
			/* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9851
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9852
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9853
			    if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9854
				break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9855
			    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9856
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9857
			    __pix = blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9858
			} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9859
			    int __srcX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9860
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9861
			    __srcX = (int)__nX;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9862
			    /* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9863
			    if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9864
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9865
				if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9866
				    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9867
				}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9868
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9869
				__pix = blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9870
			    } else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9871
				double __nY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9872
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9873
				/* rotate Y */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9874
				__nY = (__sin * __pX) + __cosPY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9875
				/* translate Y in source (origin to 0/0) */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9876
				__nY = __nY + __halfH + 0.5;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9877
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9878
				/* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9879
				if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9880
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9881
				    if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9882
					break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9883
				    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9884
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9885
				    __pix = blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9886
				} else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9887
				    int __srcY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9888
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9889
				    __srcY = (int)__nY;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9890
				    /* inside ? */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9891
				    if (__srcY >= __height) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9892
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9893
					if (didFetchInRow) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9894
					    break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9895
					}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9896
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9897
					__pix = blackPixel;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9898
				    } else {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9899
					/* fetch source pixel */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9900
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9901
					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
  9902
#ifdef EARLY_OUT
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9903
					didFetchInRow = 1;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9904
#endif
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9905
					__pix = (*valAt.ilc_func)(self,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9906
							      @symbol(pixelAtX:y:),
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9907
							      nil, &valAt,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9908
							      __MKSMALLINT(__srcX),
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9909
							      __MKSMALLINT(__srcY));
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9910
				    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9911
				}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9912
			    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9913
			}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9914
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9915
			/* store pixel */
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9916
			{
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9917
			    static struct inlineCache atPutVal = _ILC3;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9918
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9919
			    if (__pix != __MKSMALLINT(0)) {
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9920
				(*atPutVal.ilc_func)(newImage,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9921
						      @symbol(pixelAtX:y:put:),
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9922
						      nil, &atPutVal,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9923
						      __MKSMALLINT(__dstX),
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9924
						      __MKSMALLINT(__dstY),
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9925
						      __pix
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9926
						     );
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9927
			    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9928
			}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9929
		    }
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9930
		}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9931
		break;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9932
	}
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9933
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9934
	bad = false;
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9935
    }
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9936
%}.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9937
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9938
    bad ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9939
	"/ should not happen
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9940
	self primitiveFailed
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9941
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9942
"/        sinRot := radians negated sin.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9943
"/        cosRot := radians negated cos.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9944
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9945
"/        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
  9946
"/            pY := (dstY + minY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9947
"/            sinPY := (sinRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9948
"/            cosPY := (cosRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9949
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9950
"/            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
  9951
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9952
"/                "/ translate center to origin
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9953
"/                pX := (dstX + minX).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9954
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9955
"/                nX := (cosRot * pX) - sinPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9956
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9957
"/                "/ translate in source
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9958
"/                srcX := nX + halfW.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9959
"/                srcX := srcX rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9960
"/                "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9961
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9962
"/                (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
  9963
"/                    nY := (sinRot * pX) + cosPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9964
"/                    srcY := nY + halfH.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9965
"/                    srcY := srcY rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9966
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9967
"/                    "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9968
"/                    (srcY >= 0 and:[srcY < height]) ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9969
"/                        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
  9970
"/                    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9971
"/                        pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9972
"/                    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9973
"/                ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9974
"/                    pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9975
"/                ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9976
"/                pix ~~ blackPixel ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9977
"/                    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
  9978
"/                ]
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9979
"/            ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
  9980
"/        ].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9981
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9982
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9983
    ^ newImage
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9984
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9985
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9986
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9987
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9988
     i := Smalltalk imageFromFileNamed:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' inPackage:'stx:goodies'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9989
     i inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9990
     (i rotated:45) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9991
     (i rotated:90) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9992
     (i rotated:91) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9993
     (i rotated:95) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9994
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9995
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9996
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9997
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9998
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
  9999
     i := Depth24Image fromImage:i.
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10000
     (i rotated:200) inspect
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10001
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10002
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10003
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10004
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10005
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10006
     Transcript showCR:(
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10007
	Time millisecondsToRun:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10008
	   i rotated:45.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10009
	]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10010
     ).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10011
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10012
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10013
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10014
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10015
     i := Smalltalk imageFromFileNamed:'bitmaps/xpmBitmaps/misc_icons/BOOK.xpm' inPackage:'stx:goodies'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10016
     v := View new extent:(i width max:100)@(i height max:100).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10017
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10018
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10019
     [true] whileTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10020
	rI := i rotated:rot.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10021
	rI := rI onDevice:v device.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10022
	v clear.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10023
	v displayForm:rI x:v width//2-(rI width//2) y:v height//2-(rI height // 2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10024
	rot := rot + 5.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10025
	rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10026
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10027
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10028
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10029
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10030
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10031
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10032
     v := View new extent:400@400.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10033
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10034
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10035
     [true] whileTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10036
	rI := i rotated:rot.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10037
	rI := rI onDevice:v device.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10038
	v clear.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10039
	v displayForm:rI x:v width//2-(rI width//2) y:v height//2-(rI height // 2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10040
	rot := rot + 5.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10041
	rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10042
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10043
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10044
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10045
    "Modified: 22.4.1997 / 17:36:37 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10046
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10047
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 10048
lightened
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10049
    "return a new image which is slightly brighter than the receiver.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10050
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10051
     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
 10052
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 10053
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10054
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10055
	copyWithColorMapProcessing:[:clr | clr lightened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10056
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10057
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10058
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10059
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10060
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10061
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10062
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10063
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10064
    "Modified: 24.4.1997 / 18:31:23 / cg"
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 10065
!
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 10066
134
claus
parents: 132
diff changeset
 10067
magnifiedBy:scale
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10068
    "return a new image magnified by scalePoint, aPoint.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 10069
     If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:'
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 10070
     while simple (integral) magnifications are handled here."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10071
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10072
    |scalePoint mX mY
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10073
     magX      "{ Class: SmallInteger }"   "new version of stc can find this out itself..."
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10074
     magY      "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10075
     srcOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10076
     dstOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10077
     w         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10078
     h         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10079
     first
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10080
     newWidth newHeight newImage newBits newMask
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10081
     bitsPerPixel newBytesPerRow oldBytesPerRow
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10082
     bytes|
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10083
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10084
    scalePoint := scale asPoint.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 10085
    mX := scalePoint x.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 10086
    mY := scalePoint y.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10087
    ((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10088
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
48194c26a46c Initial revision
claus
parents:
diff changeset
 10089
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10090
    ((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10091
	^ self hardMagnifiedBy:scalePoint
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10092
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10093
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10094
    bytes := self bits.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 10095
    bitsPerPixel := self depth.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10096
    oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 10097
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10098
    w := width.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10099
    h := height.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10100
    magX := mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10101
    magY := mY.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10102
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 10103
    newWidth := w * magX.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 10104
    newHeight := h * magY.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10105
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 10106
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
48194c26a46c Initial revision
claus
parents:
diff changeset
 10107
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10108
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10109
	newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10110
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10111
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10112
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10113
    newImage
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10114
	width:newWidth
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10115
	height:newHeight
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10116
	photometric:photometric
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10117
	samplesPerPixel:samplesPerPixel
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10118
	bitsPerSample:bitsPerSample
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10119
	colorMap:colorMap copy
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10120
	bits:newBits
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10121
	mask:newMask.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10122
48194c26a46c Initial revision
claus
parents:
diff changeset
 10123
    mX = 1 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10124
	"expand rows only"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10125
	srcOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10126
	dstOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10127
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10128
	1 to:h do:[:row |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10129
	    1 to:magY do:[:i |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10130
		newBits replaceFrom:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10131
			to:(dstOffset + oldBytesPerRow - 1)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10132
			with:bytes
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10133
			startingAt:srcOffset.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10134
		dstOffset := dstOffset + newBytesPerRow
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10135
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10136
	    srcOffset := srcOffset + oldBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10137
	].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10138
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10139
	"expand cols"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10140
	(mX > 1) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10141
	    dstOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10142
	    srcOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10143
	    1 to:h do:[:row |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10144
		self magnifyRowFrom:bytes
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10145
		     offset:srcOffset
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10146
		     into:newBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10147
		     offset:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10148
		     factor:mX.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10149
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10150
		first := dstOffset.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10151
		dstOffset := dstOffset + newBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10152
		" and copy for row expansion "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10153
		2 to:magY do:[:i |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10154
		    newBits replaceFrom:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10155
			    to:(dstOffset + newBytesPerRow - 1)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10156
			    with:newBits
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10157
			    startingAt:first.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10158
		    dstOffset := dstOffset + newBytesPerRow
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10159
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10160
		srcOffset := srcOffset + oldBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10161
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10162
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10163
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
 10164
    ^ newImage
48194c26a46c Initial revision
claus
parents:
diff changeset
 10165
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10166
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10167
     ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') magnifiedBy:1@2)
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10168
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10169
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10170
    "Modified: 24.4.1997 / 18:32:04 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 10171
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 10172
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10173
magnifiedPreservingRatioTo:anExtent
154
claus
parents: 153
diff changeset
 10174
    "return a new image magnified to fit into anExtent,
claus
parents: 153
diff changeset
 10175
     preserving the receivers width/height ratio.
claus
parents: 153
diff changeset
 10176
     (i.e. not distorting the image).
claus
parents: 153
diff changeset
 10177
     See also #magnifiedTo: and #magnifiedBy:"
claus
parents: 153
diff changeset
 10178
claus
parents: 153
diff changeset
 10179
    |rX rY|
claus
parents: 153
diff changeset
 10180
claus
parents: 153
diff changeset
 10181
    rX := anExtent x / self width.
claus
parents: 153
diff changeset
 10182
    rY := anExtent y / self height.
claus
parents: 153
diff changeset
 10183
    ^ self magnifiedBy:(rX min:rY)
claus
parents: 153
diff changeset
 10184
claus
parents: 153
diff changeset
 10185
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10186
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
154
claus
parents: 153
diff changeset
 10187
claus
parents: 153
diff changeset
 10188
    in contrast to:
claus
parents: 153
diff changeset
 10189
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10190
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 10191
    "
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 10192
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 10193
    "Modified: 22.4.1997 / 12:33:46 / cg"
154
claus
parents: 153
diff changeset
 10194
!
claus
parents: 153
diff changeset
 10195
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10196
magnifiedTo:anExtent
154
claus
parents: 153
diff changeset
 10197
    "return a new image magnified to have the size specified by extent.
claus
parents: 153
diff changeset
 10198
     This may distort the image if the arguments ratio is not the images ratio.
claus
parents: 153
diff changeset
 10199
     See also #magnifiedPreservingRatioTo: and #magnifiedBy:"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10200
134
claus
parents: 132
diff changeset
 10201
    ^ self magnifiedBy:(anExtent / self extent)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10202
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10203
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 10204
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
154
claus
parents: 153
diff changeset
 10205
claus
parents: 153
diff changeset
 10206
    in contrast to:
claus
parents: 153
diff changeset
 10207
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 10208
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10209
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10210
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10211
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10212
mixed:amount with:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10213
    "return a new image which is blended with some color;
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10214
     amount determines how much of the blending color is applied (0..)
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10215
     where 0 means: blending color pure.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10216
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10217
     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
 10218
     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
 10219
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10220
     ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10221
	copyWithColorMapProcessing:[:clr | clr mixed:amount with:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10222
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10223
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10224
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10225
     ((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
 10226
     ((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
 10227
     ((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
 10228
     ((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
 10229
     ((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
 10230
     ((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
 10231
     ((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
 10232
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10233
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10234
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10235
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10236
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10237
negative
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10238
    "return a new image which is a negative of the receiver.
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10239
     The receiver must be a palette image (currently)."
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10240
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10241
    |newImage|
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10242
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10243
    colorMap isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10244
	photometric == #blackIs0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10245
	    newImage := self copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10246
	    newImage photometric:#whiteIs0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10247
	    ^ newImage
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10248
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10249
	photometric == #whiteIs0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10250
	    newImage := self copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10251
	    newImage photometric:#blackIs0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10252
	    ^ newImage
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10253
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10254
	^ nil
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10255
    ].
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10256
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10257
     ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10258
	copyWithColorMapProcessing:[:clr |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10259
		|newColor|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10260
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10261
		newColor := Color
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10262
				redByte:(255 - clr redByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10263
				greenByte:(255 - clr greenByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10264
				blueByte:(255 - clr blueByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10265
	]
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10266
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10267
    "
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10268
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10269
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') negative inspect
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10270
    "
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10271
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10272
    "Created: 20.6.1997 / 13:13:41 / cg"
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10273
    "Modified: 20.6.1997 / 13:17:50 / cg"
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10274
!
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10275
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10276
rotated:degrees
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10277
    "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
 10278
     degrees clockwise.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10279
     Notice, that the resulting image has a different extent.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10280
     If rotation is heavily used, the workHorse methods
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10281
     (#easyRotateBitsInto:angle: and #hardRotateBitsInto:angle) may
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10282
     be redefined in concrete image subclasses."
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10283
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10284
    |nW nH newImage d|
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10285
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10286
    d := degrees.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10287
    [d < 0] whileTrue:[d := d + 360].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10288
    d >= 360 ifTrue:[d := d \\ 360].
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10289
    d := d truncated.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10290
    d = 0 ifTrue:[^ self].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10291
    ((d ~= 90) and:[(d ~= 270) and:[d ~= 180]]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10292
	^ self hardRotated:d
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10293
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10294
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10295
    d = 180 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10296
	nW := width.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10297
	nH := height.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10298
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10299
	nW := height.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10300
	nH := width.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10301
    ].
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10302
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10303
    newImage := self species new.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10304
    newImage width:nW.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10305
    newImage height:nH.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10306
    newImage createPixelStore.
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10307
    newImage photometric:photometric.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10308
    newImage samplesPerPixel:samplesPerPixel.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10309
    newImage bitsPerSample:bitsPerSample.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10310
    newImage colorMap:colorMap copy.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10311
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10312
	newImage mask:(mask rotated:degrees)
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10313
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10314
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10315
    self easyRotateBitsInto:newImage angle:d.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10316
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10317
    ^ newImage
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10318
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10319
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10320
     |i|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10321
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10322
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10323
     i inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10324
     (i rotated:45) inspect.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10325
     (i rotated:90) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10326
     (i rotated:180) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10327
     (i rotated:270) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10328
    "
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10329
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10330
     |i|
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10331
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10332
     i := Image fromFile:'goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10333
     i inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10334
     (i rotated:90) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10335
     (i rotated:180) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10336
     (i rotated:270) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10337
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10338
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10339
    "Modified: 24.4.1997 / 18:33:42 / cg"
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10340
!
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10341
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10342
withColorResolutionReducedBy:numBits
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10343
    "return a new image with the same picture as the receiver, but reduced colorResolution;
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10344
     that is, the lower numBits are cleared in the r/g/b color components.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10345
     If anything fails, return nil."
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10346
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10347
    |xMax yMax r g b nR nG nB clr pix map revMap n_clr n_pix mask anyChange
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10348
     newColors newColorArray newImage extMask extBits newPixelValue|
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10349
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10350
    numBits > 7 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10351
	^ nil
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10352
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10353
    mask := (16rFF bitShift:numBits) bitAnd:16rFF.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10354
    extMask := (1 bitShift:numBits).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10355
    extBits := extMask - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10356
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10357
    anyChange := false.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10358
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10359
    newColors := Set new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10360
    newColorArray := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10361
    map := Array new:256.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10362
    revMap := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10363
4317
a24172a52a76 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
 10364
    newImage := self class width:width height:height depth:self depth.
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10365
    newImage photometric:photometric.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10366
    newImage colorMap:(self colorMap copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10367
    newImage bits:(self bits copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10368
    newImage mask:(self mask copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10369
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10370
    xMax := width - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10371
    yMax := height - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10372
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10373
    newPixelValue :=
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10374
	[:image :pixelValue |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10375
	    |r g b nR nG nB|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10376
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10377
	    r := image redBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10378
	    g := image greenBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10379
	    b := image blueBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10380
	    nR := r bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10381
	    nG := g bitAnd:mask. (nG bitAnd:extMask)~~0 ifTrue:[nG := nG bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10382
	    nB := b bitAnd:mask. (nB bitAnd:extMask)~~0 ifTrue:[nB := nB bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10383
	    image valueFromRedBits:nR greenBits:nG blueBits:nB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10384
	].
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10385
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10386
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10387
    photometric == #palette ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10388
	"/ direct manipulation of the pixels
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10389
	0 to:yMax do:[:y |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10390
	    0 to:xMax do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10391
		pix := self pixelAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10392
		n_pix := newPixelValue value:self value:pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10393
		n_pix ~= pix ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10394
		    newImage pixelAtX:x y:y put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10395
		    anyChange := true.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10396
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10397
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10398
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10399
	anyChange ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10400
	    ^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10401
	].
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10402
    ] ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10403
	"/ manipulate the colormap
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10404
	0 to:yMax do:[:y |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10405
	    0 to:xMax do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10406
		pix := self pixelAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10407
		(n_pix := map at:pix+1) isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10408
		    clr := self colorAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10409
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10410
		    r := clr redByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10411
		    g := clr greenByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10412
		    b := clr blueByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10413
		    nR := r bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10414
		    nG := g bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10415
		    nB := b bitAnd:mask. (nR bitAnd:extMask)~~0 ifTrue:[nR := nR bitOr:extBits].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10416
		    n_clr := Color redByte:nR greenByte:nG blueByte:nB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10417
		    (newColors includes:n_clr) ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10418
			newColors add:n_clr.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10419
			newColorArray add:n_clr.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10420
			revMap add:pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10421
			map at:pix+1 put:(n_pix := revMap size - 1).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10422
		    ] ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10423
			"/ mhmh - multiple pixels mapped to the same color
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10424
			n_pix := (newColorArray indexOf:n_clr) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10425
			map at:pix+1 put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10426
		    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10427
		].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10428
		newImage pixelAtX:x y:y put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10429
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10430
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10431
	revMap size == self colorMap size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10432
	    revMap = (0 to:revMap size-1) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10433
		^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10434
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10435
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10436
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10437
	newImage colorMap:(MappedPalette withColors:newColorArray).
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10438
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10439
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10440
    ^ newImage
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10441
!
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 10442
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10443
withPixelFunctionApplied:pixelFunctionBlock
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10444
    "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
 10445
     on the pixel colors.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10446
     Notice: this method is very slow - either apply pixel values
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10447
     (#withPixelFunctionAppliedToPixels:) or redefine this method in
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10448
     a concrete subclass.
3860
571f1cd259f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3855
diff changeset
 10449
     (read `Beyond photography, by Gerard J. Holzmann;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10450
	   ISBM 0-13-074410-7)
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10451
     See blurred / oilPointed as examples ...)"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10452
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10453
    |w  "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10454
     h  "{Class: SmallInteger }"
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 10455
     newImage "newBits newBytesPerRow"|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10456
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10457
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10458
    newImage depth:self depth.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10459
    newImage width:width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10460
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10461
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10462
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10463
    newImage createPixelStore. "/ bits:newBits.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10464
    newImage photometric:photometric.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10465
    newImage samplesPerPixel:samplesPerPixel.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10466
    newImage bitsPerSample:bitsPerSample.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10467
    newImage colorMap:colorMap copy.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10468
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10469
    w := width - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10470
    h := height - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10471
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10472
    0 to:h do:[:y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10473
	0 to:w do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10474
	    newImage colorAtX:x y:y put:(pixelFunctionBlock
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10475
						value:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10476
						value:(self colorAtX:x y:y)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10477
						value:x
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10478
						value:y)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10479
	]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10480
    ].
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10481
    ^ newImage
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10482
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10483
    "black out everything except for some rectangle:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10484
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10485
     |i black|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10486
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10487
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10488
     i inspect.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10489
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10490
     black := Color black.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10491
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10492
			((x between:100 and:200)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10493
			and:[y between:100 and:200]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10494
			    oldColor
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10495
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10496
			    black.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10497
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10498
		     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10499
    "
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10500
    "brighten a frame:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10501
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10502
     |i black w h|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10503
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10504
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10505
     i inspect.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10506
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10507
     w := i width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10508
     h := i height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10509
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10510
			((x between:0 and:10)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10511
			or:[(y between:0 and:10)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10512
			or:[(x between:w-10 and:w)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10513
			or:[y between:h-10 and:h]]]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10514
			    oldColor lightened nearestIn:i colorMap
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10515
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10516
			    oldColor.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10517
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10518
		     ]) inspect.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10519
    "
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10520
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10521
    "Modified: 24.4.1997 / 18:36:59 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10522
!
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10523
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10524
withPixelFunctionAppliedToPixels:pixelFunctionBlock
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10525
    "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
 10526
     on the pixel values.
4296
240f73781089 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4226
diff changeset
 10527
     (read `Beyond photography, by Gerard J. Holzmann;
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10528
	   ISBM 0-13-074410-7)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10529
     See blurred / oilPointed as examples ...)"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10530
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10531
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10532
	withPixelFunctionAppliedToPixels:pixelFunctionBlock
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10533
	in:(0@0 corner:width@height)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10534
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10535
    "oil painting effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10536
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10537
     |i w h|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10538
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10539
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10540
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10541
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10542
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10543
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10544
			|b p max xMin xMax yMin yMax|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10545
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10546
			b := Bag identityNew:10.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10547
			xMin := x-3 max:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10548
			xMax := x+3 min:w.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10549
			yMin := y-3 max:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10550
			yMax := y+3 min:h.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10551
			xMin to:xMax do:[:tx|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10552
			  yMin to:yMax do:[:ty|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10553
			    b add:(oldImage pixelAtX:tx y:ty)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10554
			  ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10555
			].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10556
			max := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10557
			b contents keysAndValuesDo:[:pixel :n |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10558
			    n > max ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10559
				p := pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10560
				max := n
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10561
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10562
			].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10563
			p
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10564
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10565
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10566
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10567
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10568
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10569
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10570
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10571
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10572
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10573
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10574
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10575
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10576
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10577
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10578
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10579
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10580
			|p r a nR nP nX nY|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10581
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10582
			p := (x-w2)@(y-h2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10583
			r := p r.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10584
			a := p theta.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10585
			nR := r * r / R.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10586
			nP := Point r:nR theta:a.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10587
			nX := ((nP x+w2) rounded max:0) min:w.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10588
			nY := ((nP y+h2) rounded max:0) min:h.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10589
			(nX > w or:[nX < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10590
			    white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10591
			] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10592
			    (nY > h or:[nY < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10593
				white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10594
			    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10595
				oldImage pixelAtX:nX y:nY
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10596
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10597
			]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10598
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10599
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10600
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10601
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10602
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10603
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10604
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10605
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10606
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10607
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10608
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10609
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10610
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10611
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10612
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10613
			|p r a nR nP nX nY|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10614
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10615
			p := (x-w2)@(y-h2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10616
			r := p r.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10617
			a := p theta.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10618
			nR := r * r / R.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10619
			nP := Point r:nR theta:a.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10620
			nX := (nP x+w2) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10621
			nY := (nP y+h2) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10622
			(nX > w or:[nX < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10623
			    white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10624
			] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10625
			    (nY > h or:[nY < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10626
				white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10627
			    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10628
				oldImage pixelAtX:nX y:nY
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10629
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10630
			]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10631
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10632
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10633
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10634
    "Created: 24.4.1997 / 18:37:17 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10635
    "Modified: 24.4.1997 / 18:40:02 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10636
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10637
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10638
withPixelFunctionAppliedToPixels:pixelFunctionBlock in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10639
    "return a new image from the old one, by applying a pixel processor
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10640
     on the pixel values.
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 10641
     (read `Beyond photography, by Gerard J. Holzmann;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10642
	   ISBM 0-13-074410-7)
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10643
     See blurred / oilPointed as examples ...)"
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10644
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 10645
    |newImage "newBits newBytesPerRow"|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10646
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10647
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10648
    newImage depth:self depth.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10649
    newImage width:width.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10650
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10651
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10652
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10653
    newImage createPixelStore. "/ bits:newBits
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10654
    newImage photometric:photometric.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10655
    newImage samplesPerPixel:samplesPerPixel.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10656
    newImage bitsPerSample:bitsPerSample.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10657
    newImage colorMap:colorMap copy.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10658
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10659
    self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10660
    ^ newImage
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10661
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10662
    "oil painting effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10663
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10664
     |i w h|
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10665
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10666
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10667
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10668
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10669
     h := i height - 1.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10670
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10671
			|b p max xMin xMax yMin yMax|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10672
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10673
			b := Bag identityNew:10.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10674
			xMin := x-3 max:0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10675
			xMax := x+3 min:w.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10676
			yMin := y-3 max:0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10677
			yMax := y+3 min:h.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10678
			xMin to:xMax do:[:tx|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10679
			  yMin to:yMax do:[:ty|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10680
			    b add:(oldImage pixelAtX:tx y:ty)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10681
			  ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10682
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10683
			max := 0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10684
			b contents keysAndValuesDo:[:pixel :n |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10685
			    n > max ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10686
				p := pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10687
				max := n
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10688
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10689
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10690
			p
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10691
		     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10692
    "
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10693
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10694
    "fisheye effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10695
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10696
     |i w h w2 h2 R white|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10697
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10698
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10699
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10700
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10701
     h := i height - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10702
     w2 := w // 2.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10703
     h2 := h // 2.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10704
     R := w2.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10705
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10706
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10707
			|p r a nR nP nX nY|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10708
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10709
			p := (x-w2)@(y-h2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10710
			r := p r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10711
			a := p theta.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10712
			nR := r * r / R.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10713
			nP := Point r:nR theta:a.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10714
			nX := ((nP x+w2) rounded max:0) min:w.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10715
			nY := ((nP y+h2) rounded max:0) min:h.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10716
			(nX > w or:[nX < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10717
			    white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10718
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10719
			    (nY > h or:[nY < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10720
				white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10721
			    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10722
				oldImage pixelAtX:nX y:nY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10723
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10724
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10725
		     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 10726
    "
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10727
    "fisheye effect:
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10728
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10729
     |i w h w2 h2 R white|
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10730
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10731
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10732
     i inspect.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10733
     w := i width - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10734
     h := i height - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10735
     w2 := w // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10736
     h2 := h // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10737
     R := w2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 10738
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10739
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10740
			|p r a nR nP nX nY|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10741
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10742
			p := (x-w2)@(y-h2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10743
			r := p r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10744
			a := p theta.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10745
			nR := r * r / R.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10746
			nP := Point r:nR theta:a.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10747
			nX := (nP x+w2) rounded.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10748
			nY := (nP y+h2) rounded.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10749
			(nX > w or:[nX < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10750
			    white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10751
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10752
			    (nY > h or:[nY < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10753
				white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10754
			    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10755
				oldImage pixelAtX:nX y:nY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10756
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10757
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10758
		     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10759
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10760
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10761
    "Created: 24.4.1997 / 18:37:17 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10762
    "Modified: 24.4.1997 / 18:40:02 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10763
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10764
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 10765
!Image methodsFor:'initialization'!
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 10766
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10767
createPixelStore
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10768
    |bytesPerRow|
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10769
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10770
    bytesPerRow := self bytesPerRow.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10771
    self bits:(ByteArray uninitializedNew:(bytesPerRow * self height)).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10772
!
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10773
3871
a7867fb8d880 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
 10774
initialize
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 10775
    self photometric:(self class defaultPhotometric)
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 10776
! !
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 10777
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10778
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10779
!Image methodsFor:'instance release'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10780
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10781
close
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10782
    "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
 10783
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10784
    deviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10785
	deviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10786
	deviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10787
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10788
    monoDeviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10789
	monoDeviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10790
	monoDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10791
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10792
    fullColorDeviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10793
	fullColorDeviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10794
	fullColorDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10795
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10796
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10797
    device := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10798
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10799
	mask close.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10800
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10801
    Lobby unregister:self.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10802
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10803
    "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
 10804
    "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
 10805
!
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10806
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10807
release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10808
    "release device resources"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10809
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10810
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10811
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10812
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10813
    fullColorDeviceForm := nil.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 10814
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10815
	mask release.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 10816
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 10817
    Lobby unregister:self.
1746
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 10818
    super release.
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 10819
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 10820
    "Modified: 11.6.1997 / 13:20:04 / cg"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10821
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10822
4226
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10823
releaseFromDevice
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10824
    "release device resources"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10825
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10826
    device := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10827
    deviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10828
    monoDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10829
    fullColorDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10830
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10831
    "Modified: 16.1.1997 / 19:33:01 / cg"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10832
!
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 10833
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10834
restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10835
    "flush device specifics after a snapin or binary restore"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10836
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10837
    self release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10838
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10839
2227
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10840
!Image methodsFor:'misc'!
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10841
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10842
edit
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10843
    "open an image editor on the receiver"
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10844
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10845
    ImageEditor openOnImage:self.
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10846
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10847
    "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
 10848
! !
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 10849
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10850
!Image methodsFor:'obsolete'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10851
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10852
applyPixelValuesTo:pixelFunctionBlock into:newImage in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10853
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10854
     enumerate pixelValues and evaluate the block for each.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10855
     To be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10856
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10857
    ^ self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10858
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10859
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10860
magnifyBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10861
    "obsolete: has been renamed to magnifiedBy: for ST-80 compatibility
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10862
     and name consistency ..."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10863
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10864
    self obsoleteMethodWarning.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10865
    ^ self magnifiedBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10866
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10867
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10868
!Image methodsFor:'pixel copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10869
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10870
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
 10871
    "replace a rectangular area by pixels from another image.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10872
     The sources colors must be present in the destinations
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10873
     colorMap - otherwise, an error will be reported.
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10874
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10875
     WARNING:
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10876
       This implementation is a very slow fallback general algorithm
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10877
       (the loop over the source pixels is very slow).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10878
       If this method is used heavily, you may want to redefine it in
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10879
       concrete subclasses for the common case of of copying from an Image
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10880
       with the same depth & palette.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10881
       If you do heavy image processing, specialized versions are even req'd
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10882
       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
 10883
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10884
    |dX dY|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10885
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10886
    dX := srcX-dstX.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10887
    dY := srcY-dstY.
1248
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
 10888
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10889
    ((photometric == anImage photometric)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10890
     and:[self bitsPerPixel == anImage bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10891
     and:[colorMap = anImage colorMap]]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10892
	"/ can loop over values
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10893
	anImage valuesFromX:srcX  y:srcY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10894
			toX:srcX+w-1 y:srcY+h-1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10895
			 do:[:x :y :pixelValue |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10896
	    self pixelAtX:x-dX y:y-dY put:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10897
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10898
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10899
	"/ must loop over colors - horribly slow
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10900
	anImage colorsFromX:srcX  y:srcY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10901
			toX:srcX+w-1 y:srcY+h-1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10902
			 do:[:x :y :clr |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10903
	    self colorAtX:x-dX y:y-dY put:clr.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10904
	]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10905
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10906
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10907
    (mask isNil and:[anImage mask notNil]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10908
	"/ I have no mask; copied image has
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10909
	self createMask.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10910
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10911
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10912
    mask notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10913
	anImage mask notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10914
	    "/ both have a mask
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10915
	    mask copyFrom:anImage mask x:srcX y:srcY toX:dstX y:dstY width:w height:h
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10916
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10917
	    "/ I have a mask - copied image has not
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10918
	    mask fillRectangleX:dstX y:dstY width:w height:h withValue:1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10919
	]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10920
"/    ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10921
"/        anImage mask notNil ifTrue:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10922
"/            "/ I have no mask; copied image has (already handled)
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10923
"/        ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10924
"/            "/ none has a mask - nothing to do.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10925
"/        ]
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10926
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10927
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10928
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10929
     |i1 i8 i4|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10930
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10931
     i8 := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10932
     i8 inspect.
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 10933
     i1 := Image fromFile:'libtool/bitmaps/SBrowser.xbm'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10934
     i1 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10935
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10936
     i4 := Depth4Image fromImage:i8.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10937
     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
 10938
     i4 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10939
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10940
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10941
    "Created: 20.9.1995 / 10:14:01 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10942
    "Modified: 20.9.1995 / 10:25:31 / claus"
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 10943
    "Modified: 21.6.1997 / 13:15:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10944
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10945
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10946
subImageIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10947
    "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
 10948
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10949
    ^ self class fromSubImage:self in:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10950
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10951
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10952
     |i|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10953
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 10954
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10955
     i inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10956
     (i subImageIn:(300@160 corner:340@200)) inspect
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10957
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10958
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10959
    "Created: 20.9.1995 / 01:24:20 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10960
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10961
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10962
!Image methodsFor:'printing & storing'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10963
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10964
storeOn:aStream
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10965
    "append a printed representation of the receiver to aStream,
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10966
     from which a copy of it can be reconstructed."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10967
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 10968
    |colors usedValues colorMapArray|
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 10969
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10970
    aStream nextPutAll:'(' , self class name , ' new)'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10971
    aStream nextPutAll:' width: '. width storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10972
    aStream nextPutAll:'; height: '. height storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10973
    aStream nextPutAll:'; photometric:('. photometric storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10974
    aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10975
    aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10976
    aStream nextPutAll:'); bits:(ByteArray fromPackedString:'. self bits asPackedString storeOn:aStream. aStream nextPutAll:') '.
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 10977
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 10978
    colorMap notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10979
	self depth <= 8 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10980
	    "/ cut off unused colors ...
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10981
	    usedValues := self usedValues.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10982
	    colors := colorMap copyFrom:1 to:((usedValues max+1) min:colorMap size).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10983
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10984
	    colorMapArray := OrderedCollection new.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10985
	    colors do:[:clr| colorMapArray add:(clr redByte); add:(clr greenByte); add:(clr blueByte)].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10986
	    aStream nextPutAll:'; colorMapFromArray:'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10987
	    colorMapArray asByteArray storeOn:aStream.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10988
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10989
	    aStream nextPutAll:'; colorMap:('.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10990
	    colorMap storeOn:aStream.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10991
	    aStream nextPutAll:')'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10992
	]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10993
    ].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 10994
    mask notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10995
	aStream nextPutAll:'; mask:('.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10996
	mask storeOn:aStream.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10997
	aStream nextPutAll:')'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10998
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10999
    aStream nextPutAll:'; yourself'
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
 11000
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
 11001
    "Modified: / 22.8.1998 / 12:55:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11002
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 11003
48194c26a46c Initial revision
claus
parents:
diff changeset
 11004
!Image methodsFor:'private'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 11005
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11006
bestSupportedImageFormatFor:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11007
    "scan through the image formats as supported by aDevice,
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11008
     and return the best to use when the receiver is to be represented
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11009
     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
 11010
     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
 11011
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 11012
    |bestDeviceDepth
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 11013
     bestDeviceBitsPerPixel "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11014
     "maxDepth"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11015
     bestInfo maxInfo
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 11016
     myDepth                "{ Class: SmallInteger }"
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 11017
     maxBitsPerPixel        "{ Class: SmallInteger }"|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11018
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11019
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11020
    maxBitsPerPixel := 0.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11021
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11022
    aDevice supportedImageFormats do:[:entry |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11023
	|deviceImageDepth        "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11024
	 deviceImageBitsPerPixel "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11025
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11026
	deviceImageDepth := entry at:#depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11027
	deviceImageBitsPerPixel := entry at:#bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11028
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11029
	"/ 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
 11030
	"/ devices depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11031
	"/ (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
 11032
	"/ but I dont know (yet) how to pass the correct color info
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11033
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11034
	((deviceImageDepth == 1) or:[deviceImageDepth == aDevice depth]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11035
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11036
	    deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11037
		maxInfo := entry.
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 11038
    "/            maxBitsPerPixel := deviceImageBitsPerPixel.
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 11039
    "/            maxDepth := deviceImageDepth.
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11040
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11041
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11042
	    deviceImageDepth >= myDepth ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11043
		deviceImageDepth == myDepth ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11044
		    "/ take the better one ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11045
		    (bestDeviceDepth isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11046
		     or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11047
			and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11048
			bestInfo := entry.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11049
			bestDeviceDepth := deviceImageDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11050
			bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11051
		    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11052
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11053
		    "/ take the next-larger depth
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11054
		    (bestDeviceDepth isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11055
		     or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11056
			bestInfo := entry.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11057
			bestDeviceDepth := deviceImageDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11058
			bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11059
		    ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11060
		]
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11061
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11062
	].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11063
    ].
851
c9511f8945ce fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents: 841
diff changeset
 11064
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11065
    bestDeviceDepth isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11066
	maxBitsPerPixel == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11067
	    "/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11068
	    "/ oops - nothing appropriate
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11069
	    "/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11070
	    maxInfo notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11071
		^ maxInfo
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11072
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11073
	    bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11074
	    bestInfo := IdentityDictionary new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11075
	    bestInfo at:#depth put:bestDeviceDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11076
	    bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11077
	    bestInfo at:#padding put:32.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11078
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11079
	    bestInfo := maxInfo.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11080
	]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11081
    ].
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 11082
    ^ bestInfo
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 11083
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 11084
    "Modified: / 7.2.1998 / 11:23:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11085
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11086
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11087
colormapFromImage:anImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11088
    "setup the receivers colormap from another image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11089
     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
 11090
     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
 11091
     for fromImage:/fromSubImake:"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11092
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 11093
    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
 11094
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 11095
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 11096
colormapFromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 11097
    "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
 11098
     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
 11099
     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
 11100
     for fromImage:/fromSubImake:"
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 11101
2447
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 11102
    |usedColors|
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 11103
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11104
    samplesPerPixel == 3 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11105
	photometric := #rgb
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11106
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11107
	photometricOrNil isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11108
	    photometric := anImage photometric.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11109
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11110
	    photometric := photometricOrNil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11111
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11112
	photometric == #palette ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11113
	    self setColorMap:(anImage colorMap copy).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11114
	    "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11115
	     must generate/compress the colormap, if source image has higher depth
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11116
	     than myself.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11117
	    "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11118
	    (colorMap isNil
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11119
	    or:[anImage bitsPerPixel > self bitsPerPixel]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11120
		"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11121
		 get used colors are extracted into our colorMap
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11122
		 (the at-put below will set the pixelValue according the
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11123
		 new colorIndex
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11124
		"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11125
		self setColorMap:(anImage usedColors asArray).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11126
		colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11127
		    'Image [warning]: possibly too many colors in image' errorPrintCR
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11128
		]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11129
	    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11130
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11131
	    usedColors := anImage usedColors asArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11132
	    usedColors size > (1 bitShift:self bitsPerPixel) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11133
		'Image [warning]: possibly too many colors in image' errorPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11134
		usedColors := usedColors copyTo:(1 bitShift:self bitsPerPixel).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11135
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11136
	    self setColorMap:usedColors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11137
	    photometric := #palette
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11138
	]
283
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
    "Created: 20.9.1995 / 00:58:42 / claus"
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 11142
    "Modified: 10.1.1997 / 17:52:21 / cg"
283
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
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11145
greyByteMapForRange:range
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11146
    "return a collection to map from pixelValues to greyLevels
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11147
     in the range 0..range.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11148
     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
 11149
     The values are rounded towards the nearest pixel."
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11150
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 11151
    |d clr val greyMap r
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 11152
     n "{ Class: SmallInteger }"|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 11153
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 11154
    r := range.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 11155
    r == 256 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11156
	r := 255
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11157
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11158
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11159
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11160
	n := colorMap size.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11161
	greyMap := ByteArray new:n.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11162
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11163
	1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11164
	    (clr := colorMap at:i) isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11165
		"/ an unused color
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11166
		val := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11167
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11168
		val := (r * clr brightness) rounded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11169
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11170
	    greyMap at:i put:val
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11171
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11172
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11173
	d := self bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11174
	n := 1 bitShift:d.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11175
	n >= 4096 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11176
	    self error:'size not supported - too large'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11177
	    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11178
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11179
	greyMap := ByteArray new:n.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11180
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11181
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11182
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11183
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11184
		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
 11185
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11186
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11187
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11188
		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
 11189
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11190
	    photometric == #blackIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11191
		"/ we are done
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11192
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11193
		photometric == #whiteIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11194
		    greyMap reverse
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11195
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11196
		    self error:'invalid format'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11197
		    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11198
		]
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
	].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11201
    ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 11202
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11203
    ^ greyMap
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11204
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11205
    "
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 11206
     Depth8Image new greyByteMapForRange:256
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 11207
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 11208
     Depth8Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 11209
     Depth4Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 11210
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 11211
     Depth4Image new greyByteMapForRange:1
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
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11214
    "Created: 8.6.1996 / 08:34:14 / cg"
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 11215
    "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
 11216
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11217
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11218
greyMapForRange:range
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11219
    "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
 11220
     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
 11221
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 11222
    |d r clr val
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11223
     n "{Class: SmallInteger }"
1927
d1bbdf03e5a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1919
diff changeset
 11224
     n2 "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11225
     greyArray|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11226
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11227
    d := self bitsPerPixel.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11228
    n := 1 bitShift:d.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11229
    n >= 4096 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11230
	self error:'size not supported - too large'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11231
	^ nil
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11232
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11233
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11234
    greyArray := Array new:n.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11235
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11236
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11237
	n2 := colorMap size.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11238
	1 to:n2 do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11239
	    (clr := colorMap at:i) isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11240
		"/ an unused color
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11241
		val := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11242
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11243
		val := range * clr brightness
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11244
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11245
	    greyArray at:i put:val
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11246
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11247
	n2 < n ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11248
	    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
 11249
	]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11250
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11251
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11252
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11253
		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
 11254
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11255
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11256
	    r := range asFloat.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11257
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11258
		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
 11259
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11260
	    photometric == #blackIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11261
		"/ we are done
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11262
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11263
		photometric == #whiteIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11264
		    greyArray reverse
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11265
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11266
		    self error:'invalid format'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11267
		    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11268
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11269
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11270
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11271
    ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11272
    ^ greyArray
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11273
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11274
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11275
     Depth8Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11276
     Depth4Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11277
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11278
     Depth16Image new greyMapForRange:1
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11279
     Depth4Image new greyMapForRange:1
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11280
     Depth2Image new greyMapForRange:1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11281
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 11282
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 11283
    "Modified: 1.3.1997 / 15:48:49 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11284
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 11285
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11286
magnifyRowFrom:srcBytes offset:srcStart
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11287
	  into:dstBytes offset:dstStart factor:mX
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11288
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11289
    "magnify a single pixel row - can only magnify by integer factors,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11290
     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
 11291
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11292
    ^ self subclassResponsibility
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11293
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11294
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11295
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11296
    "given the bits of a grey/color bitmap, 8-bit padded and
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11297
     pixels interpreted as greyValues, 0 is black,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11298
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11299
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11300
    |f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11301
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11302
    f := Form width:width height:height depth:depth onDevice:aDevice.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11303
    f isNil ifTrue:[^ nil].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11304
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11305
    f bits:bits.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11306
    f initGC.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11307
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11308
    (aDevice blackpixel ~~ 0) ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11309
        "/ have to invert bits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11310
        f function:#copyInverted
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11311
    ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11312
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11313
        drawBits:bits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11314
        depth:depth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11315
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11316
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11317
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11318
        into:(f id)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11319
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11320
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11321
        with:(f gcId).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11322
    ^ f
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11323
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11324
    "Created: 10.6.1996 / 20:10:31 / cg"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11325
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11326
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11327
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11328
    "given the bits of a monochrome bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11329
     0-bits as black, create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11330
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 11331
"/    monoBits invert.
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
 11332
    ^ (Form width:width height:height fromArray:monoBits onDevice:aDevice)
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
 11333
        colorMap:(Array with:Color black with:Color white).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11334
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11335
    "Created: 10.6.1996 / 20:18:09 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 11336
    "Modified: 17.4.1997 / 01:07:38 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11337
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11338
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11339
makeDevicePixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11340
    "given the bits of a grey/color bitmap, 8-bit padded and
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11341
     pixels interpreted as in the devices colormap,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11342
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11343
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11344
    |f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11345
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11346
    f := Form width:width height:height depth:depth onDevice:aDevice.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11347
    f isNil ifTrue:[^ nil].
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11348
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11349
    f bits:bits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11350
    f initGC.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11351
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11352
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11353
        drawBits:bits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11354
        depth:depth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11355
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11356
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11357
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11358
        into:(f id)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11359
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11360
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 11361
        with:(f gcId).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11362
    ^ f
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11363
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 11364
    "Created: 10.6.1996 / 17:56:08 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 11365
    "Modified: 10.6.1996 / 20:11:27 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11366
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11367
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11368
!Image methodsFor:'queries'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11369
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11370
alphaBitsOf:pixel
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11371
    "if the receiver is an rgb-image:
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11372
     return the alpha component of a pixelValue as integer 0..maxAlphaValue.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11373
     MaxAlphaValue is of course the largest integer representable by the number
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11374
     of alpha bits i.e. (1 bitShift:bitsAlpha)-1.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11375
     This has to be redefined by subclasses."
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11376
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11377
    |redBits greenBits blueBits alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11378
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11379
    samplesPerPixel >= 4 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11380
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11381
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11382
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11383
	alphaBits := bitsPerSample at:4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11384
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11385
	^ (pixel bitShift:(redBits + greenBits + blueBits) negated)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11386
	   bitAnd:(1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11387
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11388
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11389
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11390
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11391
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11392
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11393
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11394
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11395
alphaMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11396
    "return the mask used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11397
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11398
    |alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11399
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11400
    samplesPerPixel >= 4 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11401
	alphaBits := bitsPerSample at:4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11402
	^ (1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11403
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11404
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11405
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11406
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11407
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11408
alphaShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11409
    "return the shift amount used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11410
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11411
    |redBits greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11412
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11413
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11414
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11415
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11416
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11417
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11418
	^ (greenBits + blueBits + redBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11419
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11420
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11421
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11422
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11423
3813
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 11424
ascentOn:aGC
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 11425
    "I will not draw myself above the baseline"
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 11426
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 11427
    ^ 0
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 11428
!
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 11429
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11430
averageColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11431
    "return the average color of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11432
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11433
     (i.e. to compute shadow & light colors for viewBackgrounds).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11434
     Notice, that for the above purpose, it is usually ok to process
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11435
     a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11436
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11437
    ^ self averageColorIn:(0@0 corner:(width-1)@(height-1))
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11438
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11439
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11440
averageColorIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11441
    "return the images average color in an area.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11442
     The implementation below is slow - so you may want to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11443
     create tuned versions for DepthXImage if you plan to do
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11444
     heavy image processing ...
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11445
     (also, creating tuned versions of the enumeration messages helps a lot)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11446
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11447
    |x0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11448
     y0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11449
     x1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11450
     y1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11451
     sumRed sumGreen sumBlue n|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11452
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11453
    sumRed := sumGreen := sumBlue := 0.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11454
    y0 := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11455
    y1 := aRectangle bottom.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11456
    x0 := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11457
    x1 := aRectangle right.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11458
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11459
    n := (x1 - x0 + 1) * (y1 - y0 + 1).
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 11460
    mask isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11461
	self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11462
	    sumRed := sumRed + colorAtXY red.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11463
	    sumGreen := sumGreen + colorAtXY green.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11464
	    sumBlue := sumBlue + colorAtXY blue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11465
	].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 11466
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11467
	"/ masked pixels are not counted.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11468
	self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11469
	    (mask pixelAtX:x y:y) == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11470
		n := n - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11471
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11472
		sumRed := sumRed + colorAtXY red.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11473
		sumGreen := sumGreen + colorAtXY green.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11474
		sumBlue := sumBlue + colorAtXY blue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11475
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11476
	].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 11477
    ].
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 11478
    n == 0 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11479
	"/ all masked
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11480
	^ Color black
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 11481
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11482
    ^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11483
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11484
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11485
bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11486
    "return the number of bits per pixel"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11487
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11488
    ^ (bitsPerSample inject:0 into:[:sum :i | sum + i])
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11489
!
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
bitsPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11492
    "return the number of bits in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11493
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
 11494
    ^ width * (self bitsPerPixel).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11495
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11496
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11497
blackComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11498
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11499
     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
 11500
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11501
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11502
	"/ 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
 11503
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11504
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11505
	    ^ 100.0 / 255 * (pixel bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11506
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11507
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11508
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11509
    self subclassResponsibility
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
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11512
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11513
blueBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11514
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11515
     return the blue bits of a pixelValue as integer 0..maxBlueValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11516
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11517
     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
 11518
     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
 11519
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11520
    |blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11521
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11522
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11523
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11524
	^ 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
 11525
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11526
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11527
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11528
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11529
    "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
 11530
    "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
 11531
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11532
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11533
blueComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11534
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11535
     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
 11536
     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
 11537
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11538
    |blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11539
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11540
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11541
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11542
	"/ 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
 11543
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11544
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11545
	blueBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11546
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11547
	s := (1 bitShift:blueBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11548
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11549
	^ 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
 11550
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11551
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11552
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11553
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11554
    "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
 11555
    "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
 11556
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11557
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11558
blueMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11559
    "return the mask used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11560
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11561
    |blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11562
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11563
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11564
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11565
	^ (1 bitShift:blueBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11566
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11567
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11568
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11569
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11570
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11571
blueShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11572
    "return the shift amount used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11573
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11574
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11575
	^ 0
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11576
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11577
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11578
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11579
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11580
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11581
bounds
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11582
    "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
 11583
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11584
    ^ 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
 11585
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11586
    "Created: 13.5.1996 / 10:27:06 / cg"
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11587
!
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11588
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11589
brightness
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11590
    "return the (average) brightness of the image.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11591
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11592
     (i.e. to compute shadow & light colors for viewBackgrounds).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11593
     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
 11594
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11595
    ^ (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
 11596
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11597
    "Modified: 8.6.1996 / 08:46:46 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11598
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11599
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11600
bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11601
    "return the number of bytes in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11602
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11603
    |bitsPerRow bytesPerRow|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11604
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11605
    bitsPerRow := width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11606
    bytesPerRow := bitsPerRow // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11607
    ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11608
	bytesPerRow := bytesPerRow + 1
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11609
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11610
    ^ bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11611
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11612
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11613
bytesPerRowPaddedTo:padding
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11614
    "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
 11615
     if scanlines are to be padded to padding-bits."
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11616
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
 11617
    ^ self class
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11618
	bytesPerRowForWidth:width depth:(self bitsPerPixel) padding:padding
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11619
!
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 11620
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11621
center
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11622
    "for compatibility with GC protocol - return the centerPoint"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11623
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11624
    ^ (width // 2) @ (height // 2)
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11625
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11626
    "Created: 22.10.1997 / 23:52:40 / cg"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11627
!
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 11628
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11629
colorFromValue:pixelValue
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11630
    "given a pixel value, return the corresponding color.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 11631
     Pixel values start with 0.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 11632
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 11633
     - this method is typically redefined in subclasses."
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11634
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11635
    |p maxPixel clr r g b c m y k a|
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11636
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11637
    p := photometric.
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11638
    p isNil ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11639
        colorMap notNil ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11640
            p := #palette
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11641
        ] ifFalse:[
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11642
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11643
            p := #blackIs0
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11644
        ]
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11645
    ].
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11646
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11647
    p == #blackIs0 ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11648
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11649
        ^ Color gray:(pixelValue * (100 / maxPixel)).
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11650
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11651
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11652
    p == #whiteIs0 ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11653
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11654
        ^ 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
 11655
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11656
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11657
    p == #palette ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11658
        pixelValue >= colorMap size ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11659
            ^ Color black
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11660
        ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11661
        clr := colorMap at:(pixelValue + 1).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11662
        clr isNil ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11663
            ^ Color black.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11664
        ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11665
        ^ clr.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11666
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11667
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 11668
    p == #rgb ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11669
        r := self redBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11670
        g := self greenBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11671
        b := self blueBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11672
        "/ must scale to byte value...
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11673
        r := r bitShift:(8 - (bitsPerSample at:1)).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11674
        g := g bitShift:(8 - (bitsPerSample at:2)).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11675
        b := b bitShift:(8 - (bitsPerSample at:3)).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11676
        ^ Color redByte:r greenByte:g blueByte:b
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11677
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11678
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11679
    p == #rgba ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11680
        r := self redBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11681
        g := self greenBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11682
        b := self blueBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11683
        a := self alphaBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11684
        "/ must scale to byte value...
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11685
        r := r bitShift:(8 - (bitsPerSample at:1)).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11686
        g := g bitShift:(8 - (bitsPerSample at:2)).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11687
        b := b bitShift:(8 - (bitsPerSample at:3)).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11688
        a := a bitShift:(8 - (bitsPerSample at:4)).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11689
        ^ Color redByte:r greenByte:g blueByte:b alphaByte:a
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11690
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11691
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11692
    p == #cmyk ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11693
        c := self cyanComponentOfCMYK:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11694
        m := self magentaComponentOfCMYK:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11695
        y := self yellowComponentOfCMYK:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11696
        k := self blackComponentOfCMYK:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11697
        ^ 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
 11698
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11699
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11700
    p == #cmy ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11701
        c := self cyanComponentOfCMY:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11702
        m := self magentaComponentOfCMY:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11703
        y := self yellowComponentOfCMY:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11704
        ^ Color cyan:c magenta:m yellow:y.
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11705
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11706
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11707
    self error:'invalid (unsupported) photometric'
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11708
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11709
    "Created: / 08-06-1996 / 08:46:18 / cg"
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 11710
    "Modified: / 06-06-2007 / 11:21:57 / cg"
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11711
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11712
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11713
cyanComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11714
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11715
     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
 11716
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11717
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11718
	"/ 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
 11719
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11720
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11721
	    ^ 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
 11722
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11723
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11724
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11725
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11726
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11727
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11728
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11729
cyanComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11730
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11731
     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
 11732
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11733
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11734
	"/ 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
 11735
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11736
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11737
	    ^ 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
 11738
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11739
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11740
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11741
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11742
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11743
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11744
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11745
greenBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11746
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11747
     return the green bits of a pixelValue as integer 0..maxGreenValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11748
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11749
     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
 11750
     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
 11751
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11752
    |blueBits greenBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11753
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11754
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11755
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11756
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11757
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11758
	^ (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
 11759
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11760
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11761
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11762
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11763
    "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
 11764
    "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
 11765
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11766
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11767
greenComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11768
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11769
     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
 11770
     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
 11771
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11772
    |greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11773
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 11774
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11775
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11776
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11777
	"/ 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
 11778
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11779
	greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11780
	greenBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11781
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11782
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11783
	s := (1 bitShift:greenBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11784
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11785
	^ 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
 11786
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11787
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11788
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11789
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11790
    "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
 11791
    "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
 11792
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11793
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11794
greenMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11795
    "return the mask used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11796
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11797
    |greenBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11798
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11799
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11800
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11801
	^ (1 bitShift:greenBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11802
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11803
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11804
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11805
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11806
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11807
greenShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11808
    "return the shift amount used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11809
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 11810
    |greenBits|
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11811
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11812
    samplesPerPixel >= 3 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11813
	greenBits := bitsPerSample at:3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11814
	^ greenBits negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11815
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11816
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11817
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11818
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 11819
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11820
heightOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11821
    "return my height, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11822
     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
 11823
     return the pixel-height"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11824
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 11825
    ^ height
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11826
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11827
    "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
 11828
    "Modified: 13.5.1996 / 10:26:36 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11829
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 11830
3700
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11831
isDithered
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11832
    "for compatibility with color protocol"
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11833
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11834
    ^ false
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11835
!
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 11836
3507
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11837
isGrayscaleImage
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11838
    ^ (photometric ~= #palette)
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11839
      and:[photometric ~= #rgb]
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11840
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11841
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11842
    "Created: 22.4.1997 / 14:12:02 / cg"
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11843
!
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 11844
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11845
isImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11846
    "return true, if the receiver is some kind of image;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11847
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11848
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11849
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11850
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11851
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11852
isImageOrForm
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11853
    "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
 11854
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11855
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11856
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11857
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11858
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11859
isMask
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11860
    ^ false
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11861
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11862
    "Created: 22.4.1997 / 14:12:02 / cg"
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11863
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11864
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11865
magentaComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11866
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11867
     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
 11868
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11869
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11870
	"/ 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
 11871
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11872
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11873
	    ^ 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
 11874
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11875
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11876
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11877
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11878
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11879
!
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
magentaComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11882
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11883
     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
 11884
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11885
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11886
	"/ 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
 11887
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11888
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11889
	    ^ 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
 11890
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11891
    ].
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
    self subclassResponsibility
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
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 11896
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11897
pixelArraySpecies
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11898
    "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
 11899
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 11900
    self depth > 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11901
	^ Array
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11902
    ].
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11903
    ^ ByteArray
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11904
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11905
    "Created: 6.3.1997 / 15:24:05 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 11906
    "Modified: 24.4.1997 / 15:34:34 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11907
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 11908
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11909
realColorMap
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11910
    "return a collection usable as a real colormap of the image.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11911
     For palette images, this is the internal colormap;
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11912
     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
 11913
     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
 11914
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11915
    |d nEntries "{ Class: SmallInteger }"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11916
     colorArray|
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11917
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11918
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11919
	^ colorMap asArray
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11920
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11921
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11922
    d := self depth.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11923
    d > 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11924
	self error:'deep palette images not supported'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11925
	^ nil.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11926
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11927
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11928
    nEntries := 1 bitShift:d.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11929
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11930
    colorArray := Array new:nEntries.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11931
    1 to:nEntries do:[:idx |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11932
	colorArray at:idx put:(self colorFromValue:(idx-1)).
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11933
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11934
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11935
    ^ colorArray
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11936
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11937
    "Created: 11.7.1996 / 20:20:35 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11938
    "Modified: 11.7.1996 / 20:49:21 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11939
!
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 11940
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11941
realUsedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 11942
    "return a collection of colors which are really used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 11943
     This goes through the pixels and adds up colors as present in the image
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 11944
     (as opposed to #usedColors, which looks at the colorMap if present)"
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11945
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11946
    |values|
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11947
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11948
    values := self realUsedValues asArray.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11949
    ^ values collect:[:pixel | self colorFromValue:pixel]
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11950
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11951
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11952
realUsedValues
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11953
    "return a collection of color values used in the receiver.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11954
     Notice, that the interpretation of the pixels depends on the photometric
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11955
     of the image.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11956
     This is a general and therefore slow implementation; subclasses
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 11957
     may want to redefine this method for more performance.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 11958
     This goes through the pixels and adds up colors as present in the image
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 11959
     (as opposed to #usedColors, which looks at the colorMap if present)"
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11960
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11961
    |set last|
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11962
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11963
    set := IdentitySet new.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11964
    self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11965
	pixel ~~ last ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11966
	    set add:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11967
	    last := pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11968
	]
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11969
    ].
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11970
    ^ set
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11971
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11972
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11973
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11974
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedValues
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11975
    "
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11976
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11977
    "Modified: / 29.7.1998 / 21:29:44 / cg"
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11978
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 11979
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11980
redBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11981
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11982
     return the red component of a pixelValue as integer 0..maxRedValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11983
     MaxRedValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11984
     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
 11985
     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
 11986
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11987
    |redBits greenBits blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11988
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11989
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11990
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11991
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11992
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11993
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11994
	^ (pixel bitShift:(greenBits + blueBits) negated)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11995
	   bitAnd:(1 bitShift:redBits)-1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11996
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11997
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11998
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 11999
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12000
    "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
 12001
    "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
 12002
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12003
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12004
redComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12005
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12006
     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
 12007
     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
 12008
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12009
    |redBits   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12010
     greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12011
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12012
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12013
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12014
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12015
	"/ 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
 12016
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12017
	redBits := bitsPerSample at:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12018
	redBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12019
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12020
	greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12021
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12022
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12023
	s := (1 bitShift:redBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12024
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12025
	^ 100.0 / s *
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12026
	  ((pixel bitShift:(greenBits + blueBits) negated)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12027
	   bitAnd:(1 bitShift:redBits)-1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12028
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12029
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12030
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12031
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12032
    "Created: 8.6.1996 / 08:45:30 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12033
    "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
 12034
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12035
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12036
redMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12037
    "return the mask used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12038
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12039
    |redBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12040
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12041
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12042
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12043
	^ (1 bitShift:redBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12044
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12045
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12046
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12047
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12048
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12049
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12050
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12051
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12052
redShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12053
    "return the shift amount used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12054
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12055
    |greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12056
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12057
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12058
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12059
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12060
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12061
	^ (greenBits + blueBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12062
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12063
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12064
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12065
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12066
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12067
rgbFromValue:pixelValue
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12068
    "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12069
     Pixel value is in 0..2^depth - 1.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12070
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12071
     - this method is typically redefined in subclasses."
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12072
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12073
    |p maxPixel clr r g b c m y k|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12074
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12075
    p := photometric.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12076
    p isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12077
	colorMap notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12078
	    p := #palette
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12079
	] ifFalse:[
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12080
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12081
	    p := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12082
	]
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12083
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12084
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12085
    p == #blackIs0 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12086
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12087
	b := pixelValue * 255 // maxPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12088
	^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12089
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12090
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12091
    p == #whiteIs0 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12092
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12093
	b := 255 - (pixelValue * 255 // maxPixel).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12094
	^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12095
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12096
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12097
    p == #palette ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12098
	pixelValue >= colorMap size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12099
	    ^ 0 "/ black
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12100
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12101
	clr := colorMap at:(pixelValue + 1).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12102
	clr isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12103
	    ^ 0 "/ black
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12104
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12105
	^ clr rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12106
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12107
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12108
    p == #rgb ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12109
	r := self redBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12110
	g := self greenBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12111
	b := self blueBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12112
	"/ must scale to byte value...
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12113
	r := r bitShift:(8 - (bitsPerSample at:1)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12114
	g := g bitShift:(8 - (bitsPerSample at:2)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12115
	b := b bitShift:(8 - (bitsPerSample at:3)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12116
	^ (((r bitShift:8) bitOr:g) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12117
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12118
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12119
    p == #cmyk ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12120
	c := self cyanComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12121
	m := self magentaComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12122
	y := self yellowComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12123
	k := self blackComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12124
	^ (Color cyan:c magenta:m yellow:y black:k) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12125
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12126
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12127
    p == #cmy ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12128
	c := self cyanComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12129
	m := self magentaComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12130
	y := self yellowComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12131
	^ (Color cyan:c magenta:m yellow:y) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12132
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12133
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12134
    self error:'invalid (unsupported) photometric'
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12135
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12136
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12137
usedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 12138
    "return a collection of colors used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 12139
     This looks at the colorMap only if present.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 12140
     (as opposed to #realUsedColors, which goes through the pixels if the bitmap)"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12141
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12142
    |colors|
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12143
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12144
    colors := self usedColorsMax:4096.
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12145
    colors isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12146
	self error:'too many colors in image'.
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12147
    ].
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12148
    ^ colors
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12149
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12150
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12151
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12152
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12153
    "
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12154
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12155
    "Modified: / 7.9.1998 / 17:56:12 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12156
!
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12157
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12158
usedColorsMax:nMax
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12159
    "return a collection of colors used in the receiver;
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 12160
     This looks at the colorMap only if present
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 12161
     (as opposed to #realUsedColors, which goes through the pixels if the bitmap).
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 12162
     However, stop looking for more, if more than nMax colors have been found
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12163
     (useful when searching rgb images)."
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12164
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 12165
    |usedValues max colors|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12166
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12167
    photometric == #rgb ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12168
	usedValues := IdentitySet new.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12169
	self valuesFromX:0 y:0 toX:(width-1) y:(height-1)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12170
	  do:[:x :y :pixel |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12171
	    usedValues add:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12172
	    usedValues size > nMax ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12173
		"/ too many to be returned here (think of the mass of
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12174
		"/ data to be returned by a 24bit image ... ;-)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12175
		^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12176
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12177
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12178
	"/ code below is slightly faster ...
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12179
	"/ colors := usedValues collect:[:pixel | self colorFromValue:pixel].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12180
	colors := usedValues collect:[:pixel | |r g b|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12181
					r := self redBitsOf:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12182
					g := self greenBitsOf:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12183
					b := self blueBitsOf:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12184
					"/ must scale to byte value...
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12185
					r := r bitShift:(8 - (bitsPerSample at:1)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12186
					g := g bitShift:(8 - (bitsPerSample at:2)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12187
					b := b bitShift:(8 - (bitsPerSample at:3)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12188
					Color redByte:r greenByte:g blueByte:b
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12189
				     ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12190
	^ colors.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12191
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12192
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12193
    usedValues := self usedValues asArray.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12194
    photometric == #palette ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12195
	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
 12196
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12197
	"/ (photometric == #blackIs0 or:[photometric == #whiteIs0])
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12198
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12199
	max := (1 bitShift:self depth) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12200
	colors :=  usedValues collect:[:val | (Color gray:(100 * val / max ))].
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 12201
    ].
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 12202
    ^ colors asSet
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12203
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12204
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12205
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12206
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12207
    "
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
 12208
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12209
    "Created: / 7.9.1998 / 17:54:17 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 12210
    "Modified: / 7.9.1998 / 17:56:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12211
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12212
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12213
usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12214
    "return a collection of color values used in the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12215
     Notice, that the interpretation of the pixels depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12216
     of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12217
     This is a general and therefore slow implementation; subclasses
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12218
     may want to redefine this method for more performance."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12219
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12220
    ^ self realUsedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12221
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12222
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12223
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12224
     (Image fromFile:'lib tool/bitmaps/SBrowser.xbm') usedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12225
    "
2206
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 12226
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 12227
    "Modified: / 29.7.1998 / 21:29:44 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12228
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12229
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12230
valueFromColor:color
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12231
    "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
 12232
     Non-representable colors return nil."
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12233
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12234
    |pixel maxPixel redBits greenBits blueBits alphaBits r g b a|
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12235
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12236
    photometric == #whiteIs0 ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12237
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12238
        ^ maxPixel - (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12239
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12240
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12241
    photometric == #blackIs0 ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12242
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12243
        ^ (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12244
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12245
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12246
    photometric == #palette ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12247
        colorMap isNil ifTrue:[ 
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12248
            "/ same as blackIs0
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12249
            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12250
            ^ (color brightness * maxPixel) rounded.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12251
        ].
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12252
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12253
        pixel := colorMap indexOf:color.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12254
        pixel == 0 ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12255
            "
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12256
             the color is not in the images colormap
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12257
            "
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12258
            ^ nil
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12259
        ].
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12260
        ^ pixel - 1
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12261
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12262
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12263
    photometric == #rgb ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12264
        samplesPerPixel >= 3 ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12265
            redBits := bitsPerSample at:1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12266
            greenBits := bitsPerSample at:2.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12267
            blueBits := bitsPerSample at:3.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12268
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12269
            "/ map r/g/b to 0..255
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12270
            r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12271
            g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12272
            b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12273
            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12274
            ^ pixel
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 12275
        ]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12276
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12277
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12278
    photometric == #rgba ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12279
        samplesPerPixel >= 4 ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12280
            redBits := bitsPerSample at:1.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12281
            greenBits := bitsPerSample at:2.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12282
            blueBits := bitsPerSample at:3.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12283
            alphaBits := bitsPerSample at:4.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12284
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12285
            "/ map r/g/b/a to 0..255
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12286
            r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12287
            g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12288
            b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12289
            a := (color alpha * ((1 bitShift:alphaBits)-1)) rounded.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12290
            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12291
            ^ pixel
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12292
        ]
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12293
    ].
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 12294
    ImageErrorSignal raiseErrorString:'format not supported'.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12295
    ^ nil
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12296
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12297
    "Modified: / 06-06-2007 / 11:26:15 / cg"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12298
!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 12299
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12300
valueFromRGB:rgb
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12301
    "given a color, return the corresponding pixel value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12302
     Non-representable colors return nil."
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12303
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12304
    |pixel redBits greenBits blueBits alphaBits r g b a|
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12305
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12306
    r := rgb bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12307
    g := (rgb bitShift:-8) bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12308
    b := (rgb bitShift:-16) bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12309
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12310
"/    photometric == #whiteIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12311
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12312
"/        ^ maxPixel - (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12313
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12314
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12315
"/    photometric == #blackIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12316
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12317
"/        ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12318
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12319
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12320
"/    photometric == #palette ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12321
"/        colorMap isNil ifTrue:[ 
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12322
"/            "/ same as blackIs0
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12323
"/            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12324
"/            ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12325
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12326
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12327
"/        pixel := colorMap indexOf:color.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12328
"/        pixel == 0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12329
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12330
"/             the color is not in the images colormap
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12331
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12332
"/            ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12333
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12334
"/        ^ pixel - 1
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12335
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12336
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12337
    photometric == #rgb ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12338
        samplesPerPixel >= 3 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12339
            redBits := bitsPerSample at:1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12340
            greenBits := bitsPerSample at:2.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12341
            blueBits := bitsPerSample at:3.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12342
            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12343
            ^ pixel
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12344
        ]
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12345
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12346
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12347
    photometric == #rgba ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12348
        samplesPerPixel >= 4 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12349
            redBits := bitsPerSample at:1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12350
            greenBits := bitsPerSample at:2.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12351
            blueBits := bitsPerSample at:3.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12352
            alphaBits := bitsPerSample at:4.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12353
            a := 255.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12354
            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12355
            ^ pixel
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12356
        ]
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12357
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12358
    ImageErrorSignal raiseErrorString:'format not supported'.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12359
    ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12360
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12361
    "Created: / 15-01-2008 / 15:55:08 / cg"
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12362
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 12363
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12364
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12365
    "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
 12366
     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
 12367
     For now, only useful with RGB images"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12368
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12369
    |pixel numGreenBits numBlueBits|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12370
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12371
    photometric == #rgb ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12372
	samplesPerPixel >= 3 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12373
	    numGreenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12374
	    numBlueBits := bitsPerSample at:3.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12375
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12376
	    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
 12377
	    ^ pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12378
	]
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12379
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12380
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12381
    ImageErrorSignal raiseErrorString:'format not supported'.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12382
    ^ nil
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12383
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12384
    "Modified: / 30.9.1998 / 22:03:50 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12385
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12386
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12387
widthOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12388
    "return my width, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12389
     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
 12390
     return the pixel-width"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12391
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 12392
    ^ width
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12393
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12394
    "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
 12395
    "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
 12396
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12397
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12398
yellowComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12399
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12400
     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
 12401
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12402
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12403
	"/ 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
 12404
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12405
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12406
	    ^ 100.0 / 255 * (pixel bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12407
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12408
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12409
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12410
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12411
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12412
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12413
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12414
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12415
yellowComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12416
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12417
     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
 12418
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12419
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12420
	"/ 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
 12421
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12422
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12423
	    ^ 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
 12424
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12425
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12426
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12427
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12428
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12429
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12430
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12431
!Image methodsFor:'saving on file'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12432
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12433
saveOn:aFileName
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12434
    "save the image in aFileName. The suffix of the filename controls the format.
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 12435
     Currently, not all formats may be supported
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12436
     (see ImageReader subclasses implementing save:onFile:).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 12437
     May raise a signal, if the image cannot be written by the reader."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12438
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12439
    |suffix readerClass|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12440
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12441
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12442
    "/ from the extension, get the imageReader class
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12443
    "/ (which should know how to write images as well)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12444
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12445
    suffix := aFileName asFilename suffix.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 12446
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12447
    readerClass notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12448
	^ self saveOn:aFileName using:readerClass
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12449
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12450
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12451
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12452
    "/ no known extension - could ask user for the format here.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12453
    "/ currently default to tiff format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12454
    "/
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 12455
    '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
 12456
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12457
    ^ self saveOn:aFileName using:TIFFReader
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 12458
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 12459
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 12460
     |image|
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 12461
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12462
     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
 12463
     image saveOn:'myImage.tiff'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 12464
     image saveOn:'myImage.xbm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 12465
     image saveOn:'myImage.xpm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 12466
     image saveOn:'myImage.xwd'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 12467
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 12468
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 12469
    "Modified: 30.6.1997 / 22:06:34 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 12470
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 12471
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12472
saveOn:aFileName using:readerClass
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12473
    "save the receiver using the representation class
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12474
     (which is usually a concrete subclasses of ImageReader).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 12475
     May raise a signal, if the image cannot be written by the reader."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12476
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 12477
    ^ readerClass save:self onFile:aFileName
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12478
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12479
    "
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12480
     |anImage|
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12481
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12482
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12483
     anImage saveOn:'myImage.tiff' using:TIFFReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12484
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12485
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12486
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12487
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12488
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12489
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12490
     anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12491
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12492
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12493
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12494
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12495
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12496
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12497
     Image cannotRepresentImageSignal handle:[:ex |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12498
	self warn:'cannot save the image in this format'
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12499
     ] do:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12500
	anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12501
     ]
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12502
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12503
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12504
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12505
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12506
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12507
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12508
     anImage saveOn:'myImage.xpm' using:XPMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12509
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12510
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12511
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12512
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12513
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12514
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12515
     anImage saveOn:'myImage.gif' using:GIFReader.
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12516
    "
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 12517
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 12518
    "Modified: 10.4.1997 / 17:49:26 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 12519
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12520
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12521
!Image methodsFor:'screen capture'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12522
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12523
from:aDrawable in:aRectangle
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12524
    "read an image from aDrawable.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12525
     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
 12526
     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
 12527
     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
 12528
     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
 12529
     and to read hardcopy images from the screen."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12530
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12531
    | visType
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12532
     x        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12533
     y        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12534
     w        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12535
     h        "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12536
     dstIndex "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12537
     srcIndex "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12538
     srcRow   "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12539
     dstRow   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12540
     inData tmpData usedPixels mapSize
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12541
     map bytesPerLine
2534
35d91dcc4604 removed unused local
Claus Gittinger <cg@exept.de>
parents: 2533
diff changeset
 12542
     bitOrder spaceBitsPerPixel
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12543
     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
 12544
     bitsR "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12545
     bitsG "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 12546
     bitsB "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12547
     maskR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12548
     maskG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12549
     maskB "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12550
     shR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12551
     shG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12552
     shB "{ Class: SmallInteger }"
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 12553
     shR2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 12554
     shG2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 12555
     shB2 "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12556
     r "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12557
     g "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12558
     b "{ Class: SmallInteger }"
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12559
     word "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12560
     lword
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12561
     device ddepth isMSB|
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12562
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12563
    depth := self depth.
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12564
    bitsPerPixel := self bitsPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12565
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
 12566
    device := aDrawable graphicsDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12567
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12568
    (aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12569
	"/ a monochrome bitmap ?
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12570
	visType := #StaticGray.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12571
	ddepth := 1.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12572
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12573
	(aDrawable isForm) ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12574
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12575
	     get some attributes of the display device
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12576
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12577
	    visType := device visualType.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12578
	    ddepth := device depth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12579
	] ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12580
	    ddepth := aDrawable depth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12581
	    visType := aDrawable photometric
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12582
	].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12583
    ].
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12584
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12585
    "/ kludge for 15bit XFree server
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 12586
    ddepth == 15 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12587
	ddepth := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12588
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12589
4421
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 12590
    aDrawable isForm ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12591
	photometric := aDrawable photometric.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12592
	samplesPerPixel := ddepth == 24 ifTrue:3 ifFalse:1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12593
	bitsPerSample := ddepth == 24 ifTrue:#[8 8 8 ] ifFalse:[ByteArray with:bitsPerPixel].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12594
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12595
	(visType == #StaticGray) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12596
	    (device blackpixel == 0) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12597
		photometric := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12598
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12599
		photometric := #whiteIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12600
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12601
	    samplesPerPixel := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12602
	    bitsPerPixel := ddepth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12603
	    bitsPerSample := ByteArray with:bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12604
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12605
	    ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12606
		photometric := #palette.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12607
		samplesPerPixel := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12608
		bitsPerPixel := ddepth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12609
		bitsPerSample := ByteArray with:bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12610
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12611
		((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12612
		    photometric := #rgb.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12613
		    samplesPerPixel := 3.
4421
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 12614
    "/                bitsPerPixel := depth.
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 12615
    "/                bitsPerSample := ByteArray with:device bitsRed
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 12616
    "/                                       with:device bitsGreen
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 12617
    "/                                       with:device bitsBlue
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12618
		    bitsPerPixel := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12619
		    bitsPerSample := #(8 8 8).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12620
		] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12621
		    self error:'screen visual not supported'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12622
		    ^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12623
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12624
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12625
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12626
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12627
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12628
    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12629
     dont know yet, how the display pads; assume worst case,
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12630
     offering enough space for 32 bit padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12631
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12632
    w := width := aRectangle width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12633
    h := height := aRectangle height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12634
    x := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12635
    y := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12636
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12637
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12638
     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
 12639
     (its too late when info is present ...)
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12640
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12641
    spaceBitsPerPixel := bitsPerPixel.
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12642
    (bitsPerPixel > 8) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12643
	spaceBitsPerPixel := 16.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12644
	(bitsPerPixel > 16) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12645
	    spaceBitsPerPixel := 32.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12646
	    (bitsPerPixel > 32) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12647
		spaceBitsPerPixel := bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12648
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12649
	]
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12650
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12651
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12652
    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
 12653
    "/ 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
 12654
    inData := ByteArray new:(bytesPerLine * height).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12655
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12656
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12657
     get the pixels
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12658
    "
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 12659
    aDrawable isForm ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12660
	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
 12661
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12662
	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
 12663
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12664
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12665
    bitsPerPixelIn := info at:#bitsPerPixel.
2533
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 12666
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 12667
    isMSB := ((info at:#byteOrder) == #msbFirst).
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 12668
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12669
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12670
    "/ check if bitorder is what I like (msbFirst)
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12671
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12672
    "/ mhmh - thats not needed
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12673
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12674
    bitsPerPixelIn < 8 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12675
	bitOrder := info at:#bitOrder.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12676
	bitOrder ~~ #msbFirst ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12677
	    inData
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12678
		expandPixels:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12679
		width:(inData size)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12680
		height:1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12681
		into:inData
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12682
		mapping:(ImageReader reverseBits "TODO: reverseBitsForDepth:bitsPerPixelIn").
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12683
	].
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12684
    ].
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 12685
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 12686
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12687
     check, if the devices padding is different ..
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12688
     or if the bitsPerPixels are different
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12689
    "
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12690
    bytesPerLineIn := (info at:#bytesPerLine).                    "what I got"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12691
    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
 12692
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12693
    maskR := info at:#redMask ifAbsent:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12694
    maskG := info at:#greenMask ifAbsent:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12695
    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
 12696
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12697
    ((bytesPerLine ~~ bytesPerLineIn)
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 12698
    or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12699
	tmpData := inData.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12700
	inData := ByteArray uninitializedNew:(bytesPerLine * height).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12701
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12702
	srcRow := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12703
	dstRow := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12704
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12705
	bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12706
	    "/ for now, only 32 -> 24 is supported
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12707
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12708
	    maskR == 0 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12709
		bitsR := device bitsRed.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12710
		bitsG := device bitsGreen.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12711
		bitsB := device bitsBlue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12712
		maskR := (1 bitShift:bitsR) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12713
		maskG := (1 bitShift:bitsG) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12714
		maskB := (1 bitShift:bitsB) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12715
		shR := device shiftRed negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12716
		shG := device shiftGreen negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12717
		shB := device shiftBlue negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12718
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12719
		shR := (maskR lowBit - 1) negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12720
		bitsR := maskR highBit - maskR lowBit + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12721
		maskR := maskR bitShift:shR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12722
		shG := (maskG lowBit - 1) negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12723
		bitsG := maskG highBit - maskG lowBit + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12724
		maskG := maskG bitShift:shG.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12725
		shB := (maskB lowBit - 1) negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12726
		bitsB := maskB highBit - maskB lowBit + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12727
		maskB := maskB bitShift:shB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12728
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12729
	    shR2 := (8 - bitsR).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12730
	    shG2 := (8 - bitsG).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12731
	    shB2 := (8 - bitsB).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12732
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12733
	    ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12734
		"/ 'reformatting 32->24...' printNL.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12735
		1 to:h do:[:hi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12736
		    srcIndex := srcRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12737
		    dstIndex := dstRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12738
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12739
		    1 to:w do:[:wi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12740
			lword := tmpData doubleWordAt:srcIndex MSB:isMSB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12741
			r := (lword bitShift:shR) bitAnd:maskR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12742
			g := (lword bitShift:shG) bitAnd:maskG.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12743
			b := (lword bitShift:shB) bitAnd:maskB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12744
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12745
			inData at:dstIndex   put:r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12746
			inData at:dstIndex+1 put:g.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12747
			inData at:dstIndex+2 put:b.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12748
			srcIndex := srcIndex + 4.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12749
			dstIndex := dstIndex + 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12750
		    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12751
		    dstRow := dstRow + bytesPerLine.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12752
		    srcRow := srcRow + bytesPerLineIn
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12753
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12754
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12755
		((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12756
		    "/ 'reformatting 16->24...' printNL.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12757
		    1 to:h do:[:hi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12758
			srcIndex := srcRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12759
			dstIndex := dstRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12760
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12761
			1 to:w do:[:wi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12762
			    word := tmpData wordAt:srcIndex MSB:isMSB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12763
			    r := (word bitShift:shR) bitAnd:maskR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12764
			    g := (word bitShift:shG) bitAnd:maskG.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12765
			    b := (word bitShift:shB) bitAnd:maskB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12766
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12767
			    inData at:dstIndex   put:(r bitShift:shR2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12768
			    inData at:dstIndex+1 put:(g bitShift:shG2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12769
			    inData at:dstIndex+2 put:(b bitShift:shB2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12770
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12771
			    srcIndex := srcIndex + 2.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12772
			    dstIndex := dstIndex + 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12773
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12774
			dstRow := dstRow + bytesPerLine.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12775
			srcRow := srcRow + bytesPerLineIn
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12776
		    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12777
		] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12778
		    ('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12779
							bitsPerPixel printString) errorPrintCR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12780
		    self shouldImplement.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12781
		    ^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12782
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12783
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12784
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12785
	    "/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12786
	    "/ repad in the buffer
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12787
	    "/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12788
	    1 to:h do:[:hi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12789
		inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12790
			      with:tmpData startingAt:srcRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12791
		dstRow := dstRow + bytesPerLine.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12792
		srcRow := srcRow + bytesPerLineIn
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12793
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12794
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12795
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12796
	(bytesPerLine * height) ~~ inData size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12797
	    tmpData := inData.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12798
	    inData := ByteArray uninitializedNew:(bytesPerLine * height).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12799
	    inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12800
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12801
    ].
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 12802
    self bits:inData.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12803
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 12804
    "/
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 12805
    "/  if not #palette we are done, the pixel values are the rgb/grey values
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 12806
    "/
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12807
    photometric == #palette ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12808
	"/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12809
	"/ what we have now are the color numbers - still need the r/g/b values.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12810
	"/ find out, which colors are in the picture
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12811
	"/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12812
	usedPixels := inData usedValues.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12813
	mapSize := usedPixels max + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12814
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12815
	"get the palette"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12816
	map := Array new:mapSize.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12817
	usedPixels do:[:colorIndex |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12818
	    |i|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12819
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12820
	    i := colorIndex + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12821
	    device getRGBFrom:colorIndex into:[:r :g :b |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12822
		map at:i put:(Color red:r green:g blue:b)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12823
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12824
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12825
	self setColorMap:map.
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 12826
    ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 12827
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 12828
    "Modified: / 9.1.1998 / 21:32:36 / stefan"
2054
3d1619286006 fixed readout from 32bit servers
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
 12829
    "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
 12830
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12831
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12832
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12833
    "read an image from the display screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12834
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12835
	      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
 12836
	      (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
 12837
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12838
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12839
	fromScreen:aRectangle
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12840
	on:Screen current
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12841
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12842
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12843
    "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
 12844
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12845
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12846
fromScreen:aRectangle on:aDevice
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12847
    "read an image from aDevices display screen.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12848
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12849
     and PseudoColor cases have been tested ...
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12850
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12851
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12852
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12853
	      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
 12854
	      (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
 12855
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12856
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12857
	fromScreen:aRectangle
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12858
	on:aDevice
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12859
	grab:true
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12860
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12861
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12862
     Image fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12863
     Image fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12864
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12865
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12866
    "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
 12867
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12868
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12869
fromScreen:aRectangle on:aDevice grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12870
    "read an image from aDevices display screen.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12871
     If the doGrab argument is true, the display
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12872
     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
 12873
     shown while the readout is done.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12874
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12875
     and PseudoColor cases have been tested ...
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12876
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12877
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 12878
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12879
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12880
	      (use with a false grabArg then)."
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12881
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12882
    |curs rootView prevGrab|
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12883
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12884
"/    doGrab ifTrue:[ |cid|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12885
"/        curs := Cursor sourceForm:(Image fromFile:'bitmaps/Camera.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12886
"/                         maskForm:(Image fromFile:'bitmaps/Camera_m.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12887
"/                          hotSpot:16@16.
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12888
"/        curs notNil ifTrue:[
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12889
"/            cid := (curs onDevice:aDevice) id
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12890
"/        ].
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12891
"/    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12892
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12893
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12894
     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
 12895
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12896
    rootView := aDevice rootView.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12897
    doGrab ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12898
	prevGrab := aDevice activePointerGrab.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12899
	aDevice grabPointerInView:rootView withCursor:curs.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12900
    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12901
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12902
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12903
     get the pixels
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 12904
    "
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12905
    [
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12906
	self from:rootView in:aRectangle.
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 12907
    ] ensure:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12908
	doGrab ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12909
	    aDevice ungrabPointer.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12910
	    prevGrab notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12911
		 aDevice grabPointerInView:prevGrab.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12912
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12913
	]
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12914
    ]
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 12915
3092
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 12916
    "
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 12917
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:false
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 12918
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:true
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 12919
    "
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12920
!
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12921
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12922
photometricFromScreen:aDevice
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12923
    "read aDevices display photometric and set my colormap for it.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12924
     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
 12925
     or from an offScreen bitmap, for correct pixel interpretation."
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12926
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12927
    |depth visType bitsPerPixel|
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12928
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12929
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12930
     get some attributes of the display device
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12931
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12932
    visType := aDevice visualType.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12933
    depth := aDevice depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12934
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12935
    "/ kludge for 15bit XFree server
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12936
    depth == 15 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12937
	depth := 16
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12938
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12939
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12940
    (visType == #StaticGray) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12941
	(aDevice blackpixel == 0) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12942
	    photometric := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12943
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12944
	    photometric := #whiteIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12945
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12946
	samplesPerPixel := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12947
	bitsPerPixel := depth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12948
	bitsPerSample := ByteArray with:bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12949
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12950
	 were done, the pixel values are the grey values
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12951
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12952
	^ self
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12953
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12954
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12955
    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12956
	photometric := #rgb.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12957
	samplesPerPixel := 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12958
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12959
	"/ for now - only support 24bit TrueColor
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12960
	depth ~~ 24 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12961
	    'IMAGE: unsupported display depth' errorPrintCR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12962
	].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12963
"/                bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 12964
"/                bitsPerSample := ByteArray with:aDevice bitsRed
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12965
"/                                       with:aDevice bitsGreen
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12966
"/                                       with:aDevice bitsBlue
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12967
	bitsPerPixel := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12968
	bitsPerSample := #[8 8 8].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12969
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12970
	 were done, the pixel values are the rgb values
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12971
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12972
	^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12973
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12974
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12975
    ((visType ~~ #PseudoColor)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12976
    and:[(visType ~~ #StaticColor)
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12977
    and:[visType ~~ #GrayScale]]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12978
	self error:'screen visual not supported'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12979
	^ nil
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12980
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12981
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12982
    photometric := #palette.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12983
    samplesPerPixel := 1.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12984
    bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 12985
    bitsPerSample := ByteArray with:bitsPerPixel.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12986
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12987
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12988
     still need the pixels r/g/b values ...
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12989
    "
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
 12990
    self setColorMap:aDevice colorMap
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12991
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 12992
    "Modified: 11.7.1996 / 11:11:34 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12993
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12994
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
 12995
!Image class methodsFor:'documentation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12996
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12997
version
4893
137719991c5a defaultPhotometric in #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 4888
diff changeset
 12998
    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.400 2008-02-04 12:26:25 cg Exp $'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
 12999
! !
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 13000
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13001
Image initialize!