Image.st
author Claus Gittinger <cg@exept.de>
Thu, 20 Jan 2011 22:39:16 +0100
changeset 5675 51d438d3033c
parent 5655 37bd5c7eb765
child 5710 9928e8b52195
permissions -rw-r--r--
changed: #focusIn focusIn from topView now forces a focusView change in the windowGroup; other \"same-window\" focus events are now ignored in the windowGroup.
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
5319
da10fd2cd945 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5315
diff changeset
    17
		photometric redMask greenMask blueMask alphaMask device
da10fd2cd945 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5315
diff changeset
    18
		deviceForm monoDeviceForm fullColorDeviceForm mask
da10fd2cd945 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5315
diff changeset
    19
		maskedPixelsAre0 fileName imageSequence'
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    20
	classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    21
		CollectGarbageWhenRunningOutOfColors ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    22
		ImageNotFoundQuerySignal BadImageFormatQuerySignal
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
    23
		ImageSaveErrorSignal ImageLoadErrorSignal FileCreationErrorSignal
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    24
		CannotRepresentImageSignal InformationLostQuerySignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    25
		UnrepresentableColorSignal'
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    26
	poolDictionaries:''
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    27
	category:'Graphics-Images'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    28
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    29
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
    30
!Image class methodsFor:'documentation'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    31
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    32
copyright
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    33
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    34
 COPYRIGHT (c) 1991 by Claus Gittinger
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
    35
	      All Rights Reserved
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    36
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    37
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    38
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    39
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    40
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    41
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    42
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    43
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    44
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    45
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    46
documentation
48194c26a46c Initial revision
claus
parents:
diff changeset
    47
"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    48
    this class provides (some time in the future) representation
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    49
    for all kinds of images (monochrome, greyscale and color)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    50
    and will finally replace Form.
622
565e2301c064 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    51
    For now (only ;-) depths of 1, 2, 4, 8, 16 and 24 are supported.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    52
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    53
    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
    54
    but may be associated to a device.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    55
    The data held keeps all information which was originally present,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    56
    even if the display-device has lower resolution.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    57
    Therefore, it is possible to process and manipulate images without loosing
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    58
    color information.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    59
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    60
    Images may be created manually (by providing a pixel array),
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    61
    by screen capture or by reading a file (using an ImageReader).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    62
    This gives a device independent image.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    63
    For display, a device representation is required, which can be
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    64
    aquired by sending the
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    65
	'onDevice:aDevice'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    66
    message to the image. This will create a (possibly dithered) device-form,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    67
    representing the image using the currently available colors.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    68
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    69
    In rare cases, an explicit monochrome representation of the image is needed
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    70
    (X servers take monochrome icons only), this can be created by sending
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    71
    it the message
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
    72
	'monochromeOn:aDevice'.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    73
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    74
    Also, it is planned to generate another hi-color resolution version,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    75
    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
    76
    (this is not currently implemented).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    77
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    78
    An images pixel interpretation is controlled by the photometric instance variable
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    79
    and (if that is #palette) a colorMap.
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    80
    This is in contrast to the ST-80 way, where all of this info is in the colorMap
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    81
    (and using specialized colorMaps for b&w / greyScale images).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    82
    This may change in future versions for more application compatibility.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    83
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    84
    To convert pictures from/to external file-formats, image readers are used
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    85
    which have the file-format knowledge built in.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    86
    There are readers for most common formats available
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    87
    (see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    88
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    89
    File formats are handled by subclasses of ImageReader, which understand
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    90
    a specific format. You can add more readers, by adding an association
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    91
    such as ('.jpg' -> JPEGReader) to the class variable 'FileFormats'
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    92
    (see the classes #initialize method, which sets up some default, and the
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    93
    patches/display.rc files, which add more).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    94
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    95
    Some algorithms used here (especially dithering & color allocation) are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    96
    experimental and far from being perfect (some are very slow).
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    97
    For now, the most common cases have been optimized and perform reasonably
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    98
    fast - however, with uncommon depth/visualType combinations, you may
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    99
    run into slower fallback methods ...
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   100
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   101
    Much more work is needed if you plan to do heavy image processing and will
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   102
    (may) be done in the future if there is a demand for it ...
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   103
    Dithering can be controlled by the DitherAlgorithm classVariable:
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   104
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   105
       DitherAlgorithm:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   106
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   107
       nil                  a simple threshold algorithm
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   108
			    (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   109
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   110
       #pattern             patterned dither
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   111
			    (for p, take dithered color to fill pixel;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   112
			     uses dithering in color-class)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   113
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   114
       #error               error diffusion dither (Floyd-Steinberg)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   115
			    planned - not yet implemented.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   116
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   117
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   118
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   119
    [instance variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   120
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   121
	width               <Integer>       the width in pixels
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   122
	height              <Integer>       the height in pixels
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   123
	bytes               <ByteArray>     the full image information
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   124
	photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   125
	samplesPerPixel     <Integer>       the number of planes
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   126
	bitsPerSample       <Array>         the number of bits per plane
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   127
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   128
	colorMap            <Array>         only if photometric is #palette;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   129
					    maps pixel values to r/g/b values.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   130
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   131
	device              <Workstation>   the device on which deviceForm,
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   132
					    monoDeviceForm and lowResDeviceForm are
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   133
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   134
	deviceForm          <Form>          the device form which gives the best
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   135
					    possible aproximation of the image on
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   136
					    device using standard colors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   137
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   138
	monoDeviceForm      <Form>          the device form which gives a monochrome
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   139
					    aproximation of the image on device.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   140
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   141
	fullColorDeviceForm <Form>          the device form which gives the best
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   142
					    possible aproximation of the image on
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   143
					    device using private colors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   144
					    (not yet implemented)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   145
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   146
	mask                <ImageMask>     an optional mask;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   147
					    if non-nil, only pixels for which the
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   148
					    corresponding mask bit is non-zero
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   149
					    are drawn.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   150
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   151
	maskedPixelsAre0    <Boolean>       a hint for image processors and drawers
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   152
					    if true, masked pixels are known to be
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   153
					    zero in the pixel bytes.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   154
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   155
	fileName            <String>        the name of the file from which the
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   156
					    image was loaded - nil otherwise.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   157
					    Useful for image save functions
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   158
					    and for the UIPainter utility.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   159
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   160
	imageSequence                       the imageSequence, of which the
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   161
					    instance is a frame or nil,
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   162
					    if its not part of a sequence.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   163
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   164
	bitsPerPixel                        not used in ST/X
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   165
	depth                               - these have been added in instVar-slots
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   166
	maxPixelValue                       - according to the ST-80's image class.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   167
	rowByteSize                         - to allow loading of st-80 images
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   168
					    - (which are stored as instVarAt:put: expressions)
1288
9af08a658acc added ST-80 dummy instVars - allows ST-80 images stored via #storeOn:
Claus Gittinger <cg@exept.de>
parents: 1279
diff changeset
   169
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   170
    [class variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   171
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   172
	Lobby               <Registry>      keeps track of known images
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   173
					    (for resource freeing with garbage collector)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   174
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   175
	DitherAlgorithm     <Symbol>        defines how to dither
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   176
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   177
	NumberOfDitherColors <Integer>      defines, how many dither colors to use
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   178
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   179
	FileFormats         <Dictionary>    associates filename extensions to
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   180
					    image reader classes (now set-up in startup-file)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   181
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   182
	CollectGarbageWhenRunningOutOfColors
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   183
			    <Boolean>       if true, and we run out of available
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   184
					    device colors during creation of a
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   185
					    device image, collect garbage for
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   186
					    possible image reclamation.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   187
					    If false, proceed immediately.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   188
					    Default is true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   189
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   190
	ImageNotFoundQuerySignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   191
			    <QuerySignal>   raised, if an image could not be loaded
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   192
					    from a file. The parameter is the images
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   193
					    fileName.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   194
					    A handler may return a replacement
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   195
					    image or proceed with nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   196
					    If unhandled, a nil is returned from the
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   197
					    image creation.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   198
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   199
	BadImageFormatQuerySignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   200
			    <QuerySignal>   raised, if an image could not be loaded
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   201
					    from a file due to a file error or
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   202
					    unsupported format.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   203
					    A handler may return a replacement
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   204
					    image or proceed with nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   205
					    If unhandled, a nil is returned from the
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   206
					    image creation.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   207
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   208
	ImageSaveErrorSignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   209
			    <Signal>        parent of errors below.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   210
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   211
	FileCreationErrorSignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   212
			    <Signal>        file could not be created when saving an
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   213
					    image.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   214
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   215
	CannotRepresentImageSignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   216
			    <Signal>        the specified ImageReader cannot represent
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   217
					    the given image.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   218
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   219
	InformationLostQuerySignal
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   220
			    <Signal>        the specified ImageReader can represent
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   221
					    the given image, but some information
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   222
					    (typically color resolution) is lost.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   223
					    If unhandled, the save proceeds as usual.
3872
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
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   226
    caveat:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   227
	the information in
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   228
	    photometric, bitsPerPixel, bitsPerSample, samplesPerPixel, depth , colorMap and maxPixelValue
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   229
	is partially redundant and its handling stupid (not to say: braindamaged ;-).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   230
	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
   231
	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
   232
	a stupid seqColl to a color-aware real colorMap.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   233
	(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
   234
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   235
    todo:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   236
	support alpha masks
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   237
	cleanup the dithering & conversion code
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   238
	cleanup the color/photometric mess
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   239
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   240
    [See also:]
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   241
	Form Icon ImageReader
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   242
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   243
    [author:]
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   244
	Claus Gittinger
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   245
"
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   246
!
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   247
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   248
examples
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   249
"
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   250
    reading from a file (many formats are supported):
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   251
    (notice, that the bitmaps directory is searched for along
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   252
     the system path - therefore, you may add your own bitmap
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   253
     directory to the beginning of the path and thus override
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   254
     any default bitmaps, or make certain that your application
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   255
     finds its bitmaps - even if they are in a separate directory)
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   256
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   257
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   258
        (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   259
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   260
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   261
        (Image fromFile:'libtool/bitmaps/SmalltalkX.xbm') inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   262
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   263
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   264
        (Image fromFile:'goodies/bitmaps/winBitmaps/okSmily_up.bmp') inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   265
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   266
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   267
    The following examples demonstrate various depth
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   268
    and colorMap variations ...
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   269
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   270
    inline image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   271
      default: depth=1 & #blackIs0
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   272
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   273
        (Image width:8 height:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   274
               fromArray:#( 2r11111111
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
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   281
                            2r11111111 )) inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   282
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   283
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   284
      with #whiteIs0 photometric
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   285
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   286
        ((Image width:8 height:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   287
               fromArray:#( 2r11111111
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
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   294
                            2r11111111 ))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   295
            photometric:#whiteIs0)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   296
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   297
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   298
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   299
      with a colorMap
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   300
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   301
        ((Image width:8 height:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   302
               fromArray:#( 2r11111111
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
                            2r10000001
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   309
                            2r11111111 ))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   310
            colorMap:(Array with:(Color red)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   311
                            with:(Color yellow)))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   312
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   313
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   314
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   315
      a depth4 greyScale image:
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   316
      (default photometric is #blackIs0)
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   317
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   318
        (Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   319
             width:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   320
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   321
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   322
                            16r00 16r11 16r22 16r33
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   323
                            16r44 16r55 16r66 16r77
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   324
                            16r88 16r99 16raa 16rbb
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   325
                            16rcc 16rdd 16ree 16rff
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   326
                        ]) inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   327
                                                                        [exEnd]
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   328
      the same, magnified:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   329
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   330
        ((Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   331
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   332
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   333
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   334
                            16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   335
                            16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   336
                            16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   337
                            16rcd 16ref
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   338
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   339
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   340
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   341
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   342
      the following has the same effect:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   343
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   344
        ((Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   345
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   346
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   347
             depth:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   348
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   349
                            16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   350
                            16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   351
                            16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   352
                            16rcd 16ref
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   353
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   354
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   355
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   356
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   357
      with reverse grey-interpretation:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   358
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   359
        ((Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   360
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   361
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   362
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   363
                            16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   364
                            16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   365
                            16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   366
                            16rcd 16ref
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   367
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   368
            photometric:#whiteIs0;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   369
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   370
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   371
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   372
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   373
      with 1-bit-per-pixel rgb interpretation:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   374
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   375
        ((Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   376
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   377
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   378
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   379
                            16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   380
                            16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   381
                            16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   382
                            16rcd 16ref
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   383
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   384
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   385
            samplesPerPixel:3;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   386
            bitsPerSample:#(1 1 1);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   387
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   388
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   389
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   390
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   391
      with 1/2/1 rgb interpretation:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   392
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   393
        ((Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   394
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   395
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   396
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   397
                            16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   398
                            16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   399
                            16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   400
                            16rcd 16ref
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   401
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   402
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   403
            samplesPerPixel:3;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   404
            bitsPerSample:#(1 2 1);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   405
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   406
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   407
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   408
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   409
      a 2/2/0 rgb image (i.e. no blue):
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   410
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   411
         |i|
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   412
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   413
         i := Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   414
                    width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   415
                    height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   416
                    fromArray:#[ 16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   417
                                 16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   418
                                 16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   419
                                 16rcd 16ref ].
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   420
         i photometric:#rgb.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   421
         i samplesPerPixel:3.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   422
         i bitsPerSample:#(2 2 0).
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   423
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   424
         i := i magnifiedBy:30.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   425
         i inspect.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   426
                                                                        [exEnd]
809
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
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   429
      a 0/0/4 rgb image (i.e. no red or green):
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   430
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   431
         |i|
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   432
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   433
         i := Depth4Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   434
                    width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   435
                    height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   436
                    fromArray:#[ 16r01 16r23
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   437
                                 16r45 16r67
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   438
                                 16r89 16rab
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   439
                                 16rcd 16ref ].
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   440
         i photometric:#rgb.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   441
         i samplesPerPixel:3.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   442
         i bitsPerSample:#(0 0 4).
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   443
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   444
         i := i magnifiedBy:30.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   445
         i inspect.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   446
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   447
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   448
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   449
      a 2plane greyscale image:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   450
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   451
        ((Depth2Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   452
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   453
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   454
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   455
                            4r0123
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   456
                            4r1230
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   457
                            4r2301
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   458
                            4r3012
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   459
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   460
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   461
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   462
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   463
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   464
      with colors:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   465
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   466
        ((Depth2Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   467
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   468
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   469
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   470
                            4r0123
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   471
                            4r1230
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   472
                            4r2301
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   473
                            4r3012
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   474
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   475
            colorMap:(Array with:(Color black)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   476
                            with:(Color red)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   477
                            with:(Color green)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   478
                            with:(Color blue));
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   479
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   480
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   481
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   482
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   483
      depth8 image with 3/3/2 rgb interpretation:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   484
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   485
        ((Depth8Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   486
             width:16
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   487
             height:16
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   488
             fromArray:(ByteArray withAll:(0 to:16rFF)))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   489
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   490
            samplesPerPixel:3;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   491
            bitsPerSample:#(3 3 2);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   492
            magnifiedBy:10)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   493
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   494
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   495
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   496
      depth8 image with 2/2/2 rgb interpretation:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   497
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   498
        ((Depth8Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   499
             width:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   500
             height:8
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   501
             fromArray:(ByteArray withAll:(0 to:16r3F)))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   502
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   503
            samplesPerPixel:3;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   504
            bitsPerSample:#(2 2 2);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   505
            magnifiedBy:10)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   506
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   507
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   508
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   509
                                                                        [exBegin]
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   510
        ((Depth8Image
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   511
             width:4
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   512
             height:4
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   513
             fromArray:#[
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   514
                    16r30 16r0C  16r03 16r3F 
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   515
                    16r20 16r08  16r02 16r2A  
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   516
                    16r10 16r04  16r01 16r15  
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   517
                    16r00 16r00  16r00 16r00  
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   518
                        ])
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   519
            photometric:#rgb;
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   520
            samplesPerPixel:3;
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   521
            bitsPerSample:#(2 2 2);
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   522
            magnifiedBy:30)
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   523
                 inspect
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   524
                                                                        [exEnd]
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   525
2760
94d2d524081b example added (24-bit image)
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   526
      trueColor image:
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   527
                    remember: bytes are MSB 
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   528
                                                                        [exBegin]
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   529
        ((Depth16Image
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   530
             width:4
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   531
             height:5
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   532
             fromArray:#[
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   533
                    2r01111100 2r00000000  2r00000011 2r11100000  2r00000000 2r00011111  2r01111111 2r11111111
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   534
                    2r00111100 2r00000000  2r00000001 2r11100000  2r00000000 2r00001111  2r00111101 2r11101111
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   535
                    2r00011100 2r00000000  2r00000000 2r11100000  2r00000000 2r00000111  2r00011100 2r11100111
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   536
                    2r00001100 2r00000000  2r00000000 2r01100000  2r00000000 2r00000001  2r00001100 2r01100011
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   537
                    2r00000100 2r00000000  2r00000000 2r00100000  2r00000000 2r00000001  2r00000100 2r00100001
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   538
                        ])
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   539
            photometric:#rgb;
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   540
            samplesPerPixel:3;
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   541
            bitsPerSample:#(5 5 5);
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   542
            magnifiedBy:30)
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   543
                 inspect
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   544
                                                                        [exEnd]
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   545
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   546
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   547
        ((Depth24Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   548
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   549
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   550
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   551
                    16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   552
                    16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   553
                    16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   554
                    16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   555
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   556
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   557
            samplesPerPixel:3;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   558
            bitsPerSample:#(8 8 8);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   559
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   560
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   561
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   562
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   563
      32bit trueColor image:
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   564
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   565
        ((Depth32Image
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   566
             width:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   567
             height:4
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   568
             fromArray:#[
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   569
                    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
   570
                    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
   571
                    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
   572
                    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
   573
                        ])
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   574
            photometric:#rgb;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   575
            samplesPerPixel:4;
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   576
            bitsPerSample:#(8 8 8 8);
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   577
            magnifiedBy:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   578
                 inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   579
                                                                        [exEnd]
2760
94d2d524081b example added (24-bit image)
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   580
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   581
    storing - only a few formats (TIFF, XBM, XPM) currently support storing:
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
        |img|
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   584
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   585
        img := Image fromFile:'goodies/bitmaps/winBitmaps/okSmily_up.bmp'.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   586
        img saveOn:'myImage.tiff'.
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   587
        (Image fromFile:'myImage.tiff') inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   588
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   589
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   590
    magnifying (any factor):
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   591
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   592
        ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   593
            magnifiedTo:(48@48))
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   594
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   595
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   596
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   597
        ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   598
            magnifiedBy:0.7)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   599
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   600
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   601
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   602
    rotating:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   603
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   604
        ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   605
            rotated:90)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   606
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   607
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   608
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   609
        (((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   610
            magnifiedBy:0.3@0.7) rotated:270)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   611
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   612
                                                                        [exEnd]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   613
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   614
        (((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   615
            ) rotated:30)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   616
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   617
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   618
    negative:
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   619
                                                                        [exBegin]
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   620
        ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   621
            negative)
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   622
                inspect
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   623
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   624
"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   625
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   626
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   627
!Image class methodsFor:'initialization'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   628
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   629
addReader:aReaderClass suffix:aSuffix
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
   630
    <resource: #obsolete>
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   631
    "register an additional image reader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   632
     This is provided for subclasses, to regster themself when
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   633
     loaded (or from the startup scripts)"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   634
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   635
    self obsoleteMethodWarning.
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   636
    self addReader:aReaderClass suffix:aSuffix mimeType:nil
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   637
!
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   638
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   639
addReader:aReaderClass suffix:aSuffix mimeType:mimeType
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
   640
    <resource: #obsolete>
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   641
    "register an additional image reader.
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   642
     This interface is kept for backward compatibility.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   643
     The knowledge has been concentrated in MIMETypes"
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   644
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   645
    self obsoleteMethodWarning.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   646
    MIMETypes
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   647
	defineImageType:mimeType suffix:aSuffix reader:aReaderClass
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   648
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   649
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   650
     Image addReader:GIFReader suffix:'gif'
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   651
     Image addReader:GIFReader suffix:'gif' mimeType:'image/gif'
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   652
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   653
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   654
    "Modified: 30.6.1997 / 21:59:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   655
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   656
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   657
fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   658
    "return the collection of supported file formats.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   659
     The returned dictionary maps file-extensions to image reader classes."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   660
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   661
    ^ MIMETypes fileSuffixToImageReaderMapping
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   662
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   663
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   664
     Image fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   665
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   666
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   667
    "Modified: 30.6.1997 / 22:05:58 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   668
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   669
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   670
flushDeviceImages
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   671
    "simply release all deviceForms"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   672
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   673
    Lobby do:[:anImage |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   674
	anImage release
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   675
    ]
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   676
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   677
    "Modified: 15.6.1996 / 15:45:02 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   678
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   679
48194c26a46c Initial revision
claus
parents:
diff changeset
   680
initialize
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   681
    "initialize class constants"
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   682
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   683
    "setup tracker of known pictures"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   684
    Lobby isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   685
	Lobby := Registry new.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   686
	ObjectMemory addDependent:self.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   687
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   688
	"/ define the algorithm to use for dithering -
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   689
	"/ supported values are:
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   690
	"/      #threshold
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   691
	"/      #ordered
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   692
	"/      #floydSteinberg
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   693
	"/      #burkes
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   694
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   695
	DitherAlgorithm := #floydSteinberg.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   696
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   697
	(Display notNil and:[Display hasGrayscales]) ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   698
	    NumberOfDitherColors := 64
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   699
	] ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   700
	    "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
   701
	    NumberOfDitherColors := 100
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   702
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   703
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   704
	"define reader classes"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   705
	self initializeFileFormatTable.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   706
	self initializeMIMETable.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   707
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   708
	CollectGarbageWhenRunningOutOfColors := false.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   709
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   710
	ImageErrorSignal := Error newSignalMayProceed:true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   711
	ImageErrorSignal nameClass:self message:#imageErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   712
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   713
	ImageSaveErrorSignal := ImageErrorSignal newSignalMayProceed:true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   714
	ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   715
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   716
	FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   717
	FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   718
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   719
	CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   720
	CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   721
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   722
	ImageLoadErrorSignal := QuerySignal new.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   723
	ImageLoadErrorSignal nameClass:self message:#imageLoadErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   724
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   725
	ImageNotFoundQuerySignal := QuerySignal new.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   726
	ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   727
	ImageNotFoundQuerySignal parent:ImageLoadErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   728
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   729
	InformationLostQuerySignal := QuerySignal new.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   730
	InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   731
	InformationLostQuerySignal parent:ImageLoadErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   732
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   733
	BadImageFormatQuerySignal := QuerySignal new.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   734
	BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   735
	BadImageFormatQuerySignal parent:ImageLoadErrorSignal.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   736
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   737
	UnrepresentableColorSignal := ImageErrorSignal newSignalMayProceed:true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   738
	UnrepresentableColorSignal nameClass:self message:#unrepresentableColorSignal.
386
f9a80cac659e only init once
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
   739
    ]
748
818c6312acd1 grey vs. gray
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   740
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
   741
    "Modified: / 18.5.1999 / 15:50:03 / cg"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   742
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   743
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   744
initializeFileFormatTable
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   745
    "initialize a default table to map from file extension to reader class.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   746
     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
   747
     see the 'smalltalk.rc'/'display.rc' startup files for a real (full) map."
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   748
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   749
    MIMETypes notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   750
	MIMETypes imageReaderForSuffix:'xbm'  put:XBMReader.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   751
	MIMETypes imageReaderForSuffix:'tiff' put:TIFFReader.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   752
	MIMETypes imageReaderForSuffix:'gif'  put:GIFReader.
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   753
    ].
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   754
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   755
    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   756
     Image initializeFileFormatTable
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   757
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   758
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   759
    "Modified: 30.6.1997 / 22:07:28 / cg"
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   760
!
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   761
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   762
initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   763
    "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
   764
     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
   765
     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
   766
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   767
    MIMETypes notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   768
	MIMETypes mimeTypeForSuffix:'gif'       put:'image/gif'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   769
	MIMETypes mimeTypeForSuffix:'tiff'      put:'image/tiff'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   770
	MIMETypes mimeTypeForSuffix:'tif'       put:'image/tiff'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   771
	MIMETypes mimeTypeForSuffix:'xbm'       put:'image/x-xbitmap'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   772
	MIMETypes mimeTypeForSuffix:'xpm'       put:'image/x-xpixmap'.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   773
    ].
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   774
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   775
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   776
     Image initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   777
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   778
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   779
    "Created: 27.6.1997 / 16:43:48 / cg"
1815
50212910fc13 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   780
    "Modified: 21.7.1997 / 17:33:59 / cg"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   781
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   782
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   783
update:something with:aParameter from:changedObject
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   784
    "flush all device specific stuff when restarted from a snapshot"
48194c26a46c Initial revision
claus
parents:
diff changeset
   785
48194c26a46c Initial revision
claus
parents:
diff changeset
   786
    (something == #restarted) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   787
	self flushDeviceImages
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   788
    ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   789
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   790
    "Created: 21.6.1996 / 19:47:43 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   791
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   792
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   793
!Image class methodsFor:'instance creation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   794
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   795
extent:ext
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   796
    "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
   797
     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
   798
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   799
    ^ 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
   800
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   801
    "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
   802
    "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
   803
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   804
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   805
extent:ext depth:d
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   806
    "ST-80 compatibility"
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   807
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   808
    ^ self width:ext x height:ext y depth:d
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   809
!
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   810
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   811
extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   812
    ^ self extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor mixedArray:#(1.0 0.8 0.6 0.4 0.2)
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   813
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   814
    "
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   815
        |colorMap aaImgArray|
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   816
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   817
        colorMap := Array with:Color white with:Color blue.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   818
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   819
        aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   820
        aaImgArray last
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   821
            fillAntiAliasedArc:200@200 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   822
            radius:80 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   823
            from:0 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   824
            angle:360 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   825
            withColor:Color blue 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   826
            antiAliasedPalette:aaImgArray first 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   827
            startWith:aaImgArray second.    
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   828
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   829
        aaImgArray last inspect.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   830
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   831
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   832
        |colorMap aaImgArray|
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   833
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   834
        colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   835
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   836
        aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   837
        aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   838
            colorDictionary:aaImgArray first 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   839
            blendStart:aaImgArray second.   
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   840
        aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   841
            colorDictionary:aaImgArray first 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   842
            blendStart:aaImgArray second. 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   843
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   844
        aaImgArray last inspect.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   845
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   846
    "
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   847
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   848
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   849
extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor mixedArray:mixedArray
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   850
    |colors colorMap colorIndex colorDictionary tmpDic newImage emptyBits|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   851
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   852
    colors := OrderedCollection new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   853
    colorMap := OrderedCollection new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   854
    colorIndex := 0.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   855
    colorDictionary := Dictionary new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   856
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   857
    aBasicColorArray do:[:aColor |
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   858
        colorMap add:aColor.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   859
        colorIndex := colorIndex + 1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   860
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   861
        tmpDic := Dictionary new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   862
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   863
        mixedArray do:[:aFloat |
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   864
            tmpDic at:aFloat put:colorIndex. 
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   865
            colorMap add:(aColor mixed:aFloat with:bgColor).
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   866
            colorIndex := colorIndex + 1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   867
        ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   868
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   869
        colorDictionary at:aColor put:tmpDic.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   870
    ].  
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   871
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   872
    newImage := (self implementorForDepth:d) new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   873
    newImage width:ext x height:ext y depth:d palette:colorMap.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
   874
    newImage createPixelStore.
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
   875
"/    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
   876
"/    newImage bits:emptyBits.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   877
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   878
    ^ Array with:colorDictionary with:mixedArray first with:newImage
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   879
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   880
    "
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   881
        |colorMap aaImgArray|
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   882
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   883
        colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   884
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   885
        aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   886
        aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   887
            colorDictionary:aaImgArray first 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   888
            blendStart:aaImgArray second.   
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   889
        aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   890
            colorDictionary:aaImgArray first 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   891
            blendStart:aaImgArray second. 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   892
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   893
        aaImgArray last inspect.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   894
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   895
 ###################
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   896
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   897
        |colorMap aaImgArray|
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   898
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   899
        colorMap := Array with:Color white with:Color blue.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   900
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   901
        aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   902
        aaImgArray last
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   903
            fillAntiAliasedArc:200@200 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   904
            radius:80 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   905
            from:0 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   906
            angle:360 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   907
            withColor:Color blue 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   908
            antiAliasedPalette:aaImgArray first 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   909
            startWith:aaImgArray second.    
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   910
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   911
        aaImgArray last inspect.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   912
    "
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
   913
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
   914
    "Modified: / 02-11-2010 / 20:57:41 / cg"
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   915
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   916
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   917
extent:ext depth:d bits:bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   918
    "ST-80 compatibility; assume 32-bit padding"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   919
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   920
    ^ self extent:ext depth:d bits:bits pad:32
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   921
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   922
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   923
extent:ext depth:d bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   924
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   925
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   926
    ^ self width:ext x height:ext y depth:d fromArray:bits pad:padding
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   927
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   928
1276
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   929
extent:ext depth:d bitsPerPixel:bpp palette:aColormap usingBits:bits
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   930
    "ST-80 compatibility"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   931
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   932
    |img|
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   933
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   934
    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
   935
    img colorMap:aColormap.
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   936
    ^ img
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   937
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   938
    "Created: 25.1.1997 / 03:50:22 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   939
    "Modified: 25.1.1997 / 12:27:35 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   940
!
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   941
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   942
extent:ext depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   943
    "create & return a blank image of the given size.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   944
     ST-80 compatibility"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   945
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   946
    |newImage emptyBits|
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   947
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   948
    newImage := (self implementorForDepth:d) new.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   949
    newImage width:ext x height:ext y depth:d palette:aColormap.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
   950
    newImage createPixelStore.
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
   951
"/    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
   952
"/    newImage bits:emptyBits.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   953
    ^ newImage
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   954
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   955
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   956
     Image extent:16@16 depth:8 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   957
     Image extent:16@16 depth:4 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   958
     Image extent:16@16 depth:2 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   959
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   960
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
   961
    "Created: / 06-03-1997 / 15:24:01 / cg"
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
   962
    "Modified: / 02-11-2010 / 20:56:53 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   963
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
   964
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   965
extent:ext depth:d palette:aColormap bits:bits
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   966
    "ST-80 compatibility"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   967
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   968
    ^ self extent:ext depth:d palette:aColormap bits:bits pad:16
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   969
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   970
    "Modified: 7.10.1996 / 11:32:16 / cg"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   971
!
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   972
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   973
extent:ext depth:d palette:aColormap bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   974
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   975
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   976
    |img|
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   977
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   978
    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
   979
    img colorMap:aColormap.
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   980
    ^ img
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   981
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
   982
    "Modified: 7.10.1996 / 11:32:00 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   983
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   984
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   985
extent:ext fromArray:bits offset:offset
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   986
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   987
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   988
    ^ self width:ext x height:ext y fromArray:bits
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   989
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   990
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   991
fromForm:aForm
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
   992
    "create & return an Image given a aForm"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   993
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
   994
    ^ self fromSubForm:(0@0 extent:aForm extent) in:aForm
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   995
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   996
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   997
     |f|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   998
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   999
     f := Form width:16 height:16.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1000
     f clear.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1001
     f displayLineFromX:0 y:0 toX:15 y:15.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1002
     f inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1003
     (Image fromForm:f) inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1004
    "
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1005
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1006
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1007
     |f|
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1008
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1009
     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
  1010
     f clear.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1011
     f paint:(Color red).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1012
     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
  1013
     f paint:(Color green).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1014
     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
  1015
     f inspect.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1016
     (Image fromForm:f) inspect
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1017
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1018
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1019
    "Modified: 11.7.1996 / 11:21:42 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1020
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1021
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1022
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1023
    "create & return an Image given another image. This can be used to
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1024
     convert an image to another depth."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1025
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1026
    ^ 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
  1027
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1028
    "
3448
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1029
     |i i2 idx|
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1030
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1031
     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
  1032
     i2 := i deepCopy.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1033
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1034
     idx := i2 colorMap indexOfPaintNearest:(Color green).
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1035
     i2 colorMap at:idx put:Color red.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1036
     i2 inspect.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1037
     i inspect.
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1038
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1039
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1040
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1041
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1042
    "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
  1043
     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
  1044
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1045
    (self == Image
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1046
    or:[anImage class == self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1047
	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
  1048
    ^ self new fromImage:anImage photometric:photometricOrNil.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1049
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1050
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1051
     |i1 i8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1052
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1053
     i1 := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1054
     i8 := Depth8Image fromImage:i1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1055
     i8 inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1056
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1057
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1058
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1059
fromSubForm:aRectangle in:aForm
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1060
    "create & return an subImage given a aForm"
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1061
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1062
    |depth device vis img photometric|
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1063
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1064
    depth := aForm depth.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1065
    device := aForm device.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1066
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1067
    photometric := (depth > 8) ifTrue:#rgb ifFalse:#palette.
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1068
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1069
    (device notNil and:[depth == device depth]) ifTrue:[
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1070
        "/
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1071
        "/ for truecolor displays, return a Depth24Image
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1072
        "/ (must do this for depth15 & depth16 displays, since
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1073
        "/  Depth16Image has no way to specify r/g/b masks ...)
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1074
        "/
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1075
        vis := device visualType.
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1076
        (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1077
            depth > 8 ifTrue:[
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1078
                depth := 24.
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1079
            ]
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1080
        ].
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1081
    ].
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1082
    img := self newForDepth:depth.
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1083
    img photometric:photometric.    
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1084
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1085
    device isNil ifTrue:[
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1086
        ^ img from:aForm in:aRectangle.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1087
    ].
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1088
    ^ img from:aForm in:aRectangle
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1089
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1090
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1091
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1092
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1093
     f := Form width:16 height:16.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1094
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1095
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1096
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1097
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1098
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1099
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1100
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1101
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1102
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1103
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1104
     f := Form width:16 height:16 depth:(Display depth) on:Display.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1105
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1106
     f paint:(Color red).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1107
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1108
     f paint:(Color green).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1109
     f displayLineFromX:15 y:0 toX:0 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1110
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1111
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1112
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1113
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1114
!
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1115
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1116
fromSubImage:anImage in:aRectangle
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1117
    "create & return an Image from a rectangular area in another image.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1118
     This can also be used to get a subimage in another depth."
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1119
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1120
    |cls newImage|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1121
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1122
    self == Image ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1123
	cls := (self implementorForDepth:anImage depth).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1124
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1125
	cls := self.
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1126
    ].
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1127
    newImage := cls new.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1128
    ^ newImage fromSubImage:anImage in:aRectangle.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1129
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1130
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1131
     |i1 i8|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1132
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1133
     i1 := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1134
     i8 := Depth8Image fromSubImage:i1 in:(0@0 corner:20@20).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1135
     i8 inspect
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1136
    "
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1137
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1138
     |i1 i8|
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1139
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1140
     i1 := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1141
     i8 := Depth8Image fromSubImage:i1 in:(70@50 extent:50@50).
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1142
     i8 inspect
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1143
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1144
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1145
     |i1 i8|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1146
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1147
     i1 := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1148
     i8 := Image fromSubImage:i1 in:(70@50 extent:50@50).
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1149
     i8 inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1150
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1151
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1152
    "Created: 20.9.1995 / 01:05:43 / claus"
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1153
    "Modified: 24.4.1997 / 23:13:02 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1154
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1155
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1156
new
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1157
    "create a new image. Redefined to set the photometric to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1158
     greyScale with black being 0 as default."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1159
4416
fb209558d622 proper #initialize
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
  1160
    ^ self basicNew initialize
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1161
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1162
    "Modified: 10.6.1996 / 18:08:37 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1163
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1164
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1165
newForDepth:depth
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1166
    "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
  1167
     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
  1168
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1169
    |cls|
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1170
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1171
    cls := self implementorForDepth:depth.
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1172
    ^ cls new
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1173
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1174
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1175
     Image newForDepth:8
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1176
    "
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1177
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1178
    "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
  1179
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1180
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1181
width:w height:h
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1182
    "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
  1183
     Assume a depth of 1, unless an explicit imageClass is the receiver."
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1184
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1185
    |cls|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1186
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1187
    cls := self.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1188
    cls == Image ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1189
        cls := self implementorForDepth:1
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1190
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1191
    ^ cls new width:w height:h
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1192
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1193
    "Modified: / 06-06-2007 / 11:10:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1194
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1195
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1196
width:w height:h depth:d
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1197
    "create a new image, given width, height and depth"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1198
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1199
    ^ (self newForDepth:d)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1200
	width:w height:h depth:d
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1201
!
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1202
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1203
width:w height:h depth:d fromArray:pixelData
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1204
    "create a new image, given width, height, depth and data.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1205
     Data must be a ByteArray containing correctly aligned bits for the specified
134
claus
parents: 132
diff changeset
  1206
     depth (8-bit padded)."
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1207
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1208
    ^ (self newForDepth:d)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1209
	width:w height:h depth:d fromArray:pixelData
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1210
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1211
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1212
     Image width:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1213
	   height:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1214
	   depth:1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1215
	   fromArray:#[2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1216
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1217
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1218
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1219
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1220
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1221
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1222
		       2r00110011].
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1223
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1224
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1225
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1226
     Image width:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1227
	   height:8
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1228
	   depth:2
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1229
	   fromArray:#[4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1230
		       4r0011 4r0011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1231
		       4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1232
		       4r0011 4r0011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1233
		       4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1234
		       4r0011 4r0011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1235
		       4r1100 4r1100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1236
		       4r0011 4r0011].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1237
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1238
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1239
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1240
     Image width:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1241
	   height:8
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1242
	   depth:4
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1243
	   fromArray:#[16r00 16r01 16rf0 16rf1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1244
		       16r02 16r03 16rf2 16rf3
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1245
		       16r04 16r05 16rf4 16rf5
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1246
		       16r06 16r07 16rf6 16rf7
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1247
		       16r08 16r09 16rf8 16rf9
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1248
		       16r0a 16r0b 16rfa 16rfb
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1249
		       16r0c 16r0d 16rfc 16rfd
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1250
		       16r0e 16r0f 16rfe 16rff].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1251
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1252
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1253
    "Modified: 10.6.1996 / 18:18:10 / cg"
132
claus
parents: 125
diff changeset
  1254
!
claus
parents: 125
diff changeset
  1255
134
claus
parents: 132
diff changeset
  1256
width:w height:h depth:d fromArray:pixelData pad:padding
claus
parents: 132
diff changeset
  1257
    "create a new image, given width, height, depth and data.
claus
parents: 132
diff changeset
  1258
     Data must be a ByteArray containing correctly aligned bits for the specified
claus
parents: 132
diff changeset
  1259
     depth."
claus
parents: 132
diff changeset
  1260
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1261
    |img newBits
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1262
     srcRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1263
     dstRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1264
     nextDstIndex "{ Class: SmallInteger }"
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1265
     srcIndex "{ Class: SmallInteger }"
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1266
     dstIndex "{ Class: SmallInteger }" |
134
claus
parents: 132
diff changeset
  1267
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1268
    img := (self newForDepth:d) width:w height:h depth:d .
134
claus
parents: 132
diff changeset
  1269
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1270
    srcRowBytes := ((w * d + padding - 1) bitShift:-5) bitShift:2.
5341
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1271
    dstRowBytes := img bytesPerRow.
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1272
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1273
    (padding ~~ 8 and:[(srcRowBytes \\ 4 ~~ 0) or:[srcRowBytes ~= dstRowBytes]]) ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1274
        "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
  1275
         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
  1276
        "
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1277
        dstRowBytes := img bytesPerRow.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1278
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1279
        newBits := ByteArray uninitializedNew:(dstRowBytes * h).
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1280
        srcIndex := 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1281
        dstIndex := 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1282
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1283
        1 to:h do:[:row |
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1284
            nextDstIndex := dstIndex + dstRowBytes.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1285
            newBits replaceFrom:dstIndex
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1286
                             to:(nextDstIndex - 1)
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1287
                           with:pixelData
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1288
                     startingAt:srcIndex.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1289
            srcIndex := srcIndex + srcRowBytes.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1290
            dstIndex := nextDstIndex.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1291
        ].
134
claus
parents: 132
diff changeset
  1292
    ] ifFalse:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1293
        pixelData class isBytes ifFalse:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1294
            newBits := ByteArray withAll:pixelData
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1295
        ] ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1296
            newBits := pixelData
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1297
        ]
134
claus
parents: 132
diff changeset
  1298
    ].
claus
parents: 132
diff changeset
  1299
    img bits:newBits.
claus
parents: 132
diff changeset
  1300
    ^ img
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1301
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1302
    "Modified: / 27-05-2007 / 14:01:32 / cg"
134
claus
parents: 132
diff changeset
  1303
!
claus
parents: 132
diff changeset
  1304
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1305
width:w height:h fromArray:anArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1306
    "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
  1307
     receiving class is Image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1308
     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
  1309
     (i.e. 8 bits per byte)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1310
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1311
    |cls d pixels|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1312
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1313
    cls := self.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1314
    cls == Image ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1315
	cls := self implementorForDepth:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1316
	d := 1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1317
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1318
	d := cls imageDepth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1319
    ].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1320
    anArray class isBytes ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1321
	pixels := ByteArray withAll:anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1322
    ] ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1323
	pixels := anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1324
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1325
    ^ cls new width:w height:h depth:d fromArray:pixels
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1326
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1327
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1328
     Image width:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1329
	   height:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1330
	   fromArray:#[2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1331
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1332
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1333
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1334
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1335
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1336
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1337
		       2r00110011].
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1338
    "
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1339
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1340
    "Modified: 8.6.1996 / 10:07:26 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1341
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1342
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1343
!Image class methodsFor:'Signal constants'!
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1344
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1345
badImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1346
    "return the (query-) signal, which is raised if some
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1347
     bitmap-image could not be loaded due to an unrecognized format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1348
     If unhandled, the image-load returns nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1349
     Otherwise, it returns whatever the handler proceeds with.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1350
     The exception gets either the images fileName or an input stream
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1351
     as parameter"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1352
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1353
    ^ BadImageFormatQuerySignal
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
    "Created: 1.2.1997 / 14:40:29 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1356
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1357
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1358
cannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1359
    "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
  1360
     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
  1361
     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
  1362
     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
  1363
     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
  1364
     (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
  1365
     format then."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1366
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1367
    ^ CannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1368
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1369
    "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
  1370
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1371
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1372
fileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1373
    "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
  1374
     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
  1375
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1376
    ^ FileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1377
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1378
    "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
  1379
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1380
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1381
imageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1382
    "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
  1383
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1384
    ^ ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1385
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1386
    "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
  1387
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1388
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1389
imageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1390
    "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
  1391
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1392
    ^ ImageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1393
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1394
    "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
  1395
!
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1396
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1397
imageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1398
    "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
  1399
     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
  1400
     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
  1401
     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
  1402
     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
  1403
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1404
    ^ ImageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1405
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1406
    "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
  1407
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1408
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1409
imageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1410
    "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
  1411
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1412
    ^ ImageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1413
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1414
    "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
  1415
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1416
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1417
informationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1418
    "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
  1419
     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
  1420
     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
  1421
     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
  1422
     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
  1423
     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
  1424
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1425
    ^ InformationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1426
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1427
    "Created: 27.2.1997 / 12:43:50 / cg"
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1428
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1429
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1430
unrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1431
    "return the signal, which is raised if some color is not
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1432
     representable in the image (when storing a pixel)."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1433
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1434
    ^ UnrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1435
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1436
    "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
  1437
! !
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1438
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1439
!Image class methodsFor:'cleanup'!
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1440
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1441
releaseResourcesOnDevice:aDevice
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1442
    "this is sent when a display connection is closed,
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1443
     to release all cached Images from that device"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1444
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1445
    Lobby
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1446
	unregisterAllForWhich:[:eachImage |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1447
	    |ok|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1448
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1449
	    ok := eachImage graphicsDevice == aDevice.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1450
	    ok ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1451
		eachImage releaseFromDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1452
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1453
	    ok
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1454
	]
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1455
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1456
    "Created: 16.1.1997 / 19:30:44 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1457
    "Modified: 16.1.1997 / 19:33:49 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1458
! !
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1459
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1460
!Image class methodsFor:'file reading'!
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1461
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1462
fromFile:aFileName
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1463
    "read an image from a file - this methods tries to find
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1464
     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
  1465
     and lets the appropriate reader read the file.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1466
     Also, all bitmap directories along the searchPath are checked
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1467
     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
  1468
     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
  1469
     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
  1470
     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
  1471
     proceed with some replacement image. If unhandled, nil is returned."
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1472
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1473
    |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
  1474
     mustDecompress inPipe readersErrorMsg|
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1475
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1476
    "before trying each reader, check if the file is readable"
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1477
4158
930761d24ab2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4156
diff changeset
  1478
    name := aFileName asFilename.
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1479
    name isAbsolute ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1480
        fn := name asFilename.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1481
    ] ifFalse:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1482
        inStream := Smalltalk systemFileStreamFor:name.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1483
        inStream isNil ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1484
            inStream := Smalltalk bitmapFileStreamFor:name.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1485
            inStream isNil ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1486
                "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
  1487
                 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
  1488
                ^ ImageNotFoundQuerySignal
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1489
                            raiseRequestWith:aFileName
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1490
                            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
  1491
            ].
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1492
        ].
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1493
        fn := inStream pathName asFilename.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1494
        inStream close.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1495
    ].
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1496
4158
930761d24ab2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4156
diff changeset
  1497
    nm := fn name.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1498
    suffix := fn suffix.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1499
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1500
    "handle compressed-suffix"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1501
    (#('Z' 'gz') includes:suffix) ifTrue:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1502
        fn := fn withoutSuffix.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1503
        nm := fn name.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1504
        suffix := fn suffix.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1505
        mustDecompress := true.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1506
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1507
    suffix isEmpty ifTrue:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1508
        suffix := nm.
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1509
    ].
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1510
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1511
    "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
  1512
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1513
    readerClass notNil ifTrue:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1514
        mustDecompress == true ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1515
            inPipe := PipeStream readingFrom:'gunzip <' , fn pathName.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1516
            inPipe notNil ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1517
                [
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1518
                    image := readerClass fromStream:inPipe.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1519
                ] ensure:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1520
                    inPipe close
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1521
                ].
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1522
            ]
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1523
        ] ifFalse:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1524
            BadImageFormatQuerySignal handle:[:ex |
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1525
                Transcript showCR:(readersErrorMsg := ex description).
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1526
                image := nil.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1527
                ex return.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1528
            ] do:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1529
                image := readerClass fromFile:fn.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1530
            ].
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1531
        ].
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1532
        image notNil ifTrue:[^ image].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1533
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1534
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1535
    (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
  1536
        "no known extension (or wrong extension)
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1537
         - 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
  1538
         ... 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
  1539
         therefore, it takes a bit longer."
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1540
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1541
        MIMETypes imageReaderClasses do:[:mimeReaderClass |
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1542
            (mimeReaderClass notNil
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1543
            and:[mimeReaderClass ~~ readerClass]) ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1544
               (mimeReaderClass isValidImageFile:name) ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1545
                    image := mimeReaderClass fromFile:name.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1546
                    image notNil ifTrue:[
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1547
                        ^ image
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1548
                    ]
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1549
                ]
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1550
            ]
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1551
        ].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1552
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1553
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1554
    "nope - unknown format
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1555
     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
  1556
     However, a handler may provide a replacement image."
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1557
3656
11670e0e6fcb invalid format notification fixed
Claus Gittinger <cg@exept.de>
parents: 3623
diff changeset
  1558
    ^ BadImageFormatQuerySignal
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1559
        raiseRequestWith:aFileName
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1560
        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
  1561
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1562
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1563
     Image fromFile:'goodies/bitmaps/gifImages/claus.gif'
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1564
     Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1565
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1566
     Image fromFile:'goodies/bitmaps/winBitmaps/a11.ico'
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1567
     Image fromFile:'goodies/bitmaps/xpmBitmaps/countries/czech.xpm'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1568
     Image fromFile:'goodies/bitmaps/xpmBitmaps/countries/czech.xpm.gz'
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
  1569
     Image fromFile:'clients/Demos/bitmaps/hello_world.icon'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1570
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1571
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1572
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1573
     Image fromFile:'fooBar'
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1574
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1575
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1576
    "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
  1577
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1578
     Image imageNotFoundQuerySignal
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1579
     handle:[:ex |
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1580
        Transcript showCR:ex description.
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1581
        ex proceedWith:nil
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1582
     ] do:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1583
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1584
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1585
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1586
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1587
    "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
  1588
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1589
     Image imageNotFoundQuerySignal
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
  1590
     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
  1591
     do:[
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1592
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1593
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1594
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1595
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1596
    "Modified: / 19-11-2007 / 15:50:52 / cg"
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1597
!
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1598
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1599
fromFile:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1600
    "read an image for a package from a file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1601
     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
  1602
     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
  1603
     and lets the appropriate reader read the file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1604
     Also, all bitmap directories along the searchPath are checked
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1605
     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
  1606
     separate directory, thereby overriding system bitmaps easily.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1607
     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
  1608
     the ImageNotFoundQuerySignal is raised, which may be handled to
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1609
     proceed with some replacement image. If unhandled, nil is returned."
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1610
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1611
    ^ Smalltalk imageFromFileNamed:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1612
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1613
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1614
     Image fromFile:'libtool/bitmaps/SBrowser.xbm'
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1615
     Image fromFile:'bitmaps/SBrowser.xbm' inPackage:'stx:libtool'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1616
     Image fromFile:'garfield.gif' inPackage:'stx:goodies/bitmaps/gifImages'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1617
    "
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1618
!
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1619
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1620
fromFile:aFileName on:aDevice
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1621
    "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
  1622
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1623
     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
  1624
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1625
    |img|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1626
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1627
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1628
    img notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1629
	^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1630
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1631
    ^ nil
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1632
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1633
    "Modified: 1.2.1997 / 14:48:07 / cg"
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1634
!
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1635
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1636
fromFile:aFileName resolution:res
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1637
    "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
  1638
     as appropriate (only req'd for very high resolution displays).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1639
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1640
     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
  1641
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1642
    ^ self fromFile:aFileName resolution:res on:nil
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1643
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1644
    "Created: 19.12.1996 / 14:02:13 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1645
    "Modified: 1.2.1997 / 14:48:16 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1646
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1647
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1648
fromFile:aFileName resolution:dpi on:aDevice
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1649
    "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
  1650
     as appropriate (only req'd with very high resolution displays).
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1651
     Prepare a device representation.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1652
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1653
     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
  1654
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1655
    |img dev dpiH mag|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1656
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1657
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1658
    img isNil ifTrue:[^ nil].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1659
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1660
    "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
  1661
    dev := aDevice.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1662
    dev isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1663
	"should not happen ..."
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1664
	dev := Screen current
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1665
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1666
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1667
    dev notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1668
	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
  1669
    ] ifFalse:[
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1670
	dpiH := 90
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1671
    ].
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1672
    ((dpi >= (dpiH * 0.75)) and:[dpi <= (dpiH * 1.5)]) ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1673
    mag := (dpiH / dpi) rounded.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1674
    mag = 0 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1675
    mag = 1 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1676
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1677
    img := img magnifiedBy:(mag @ mag).
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1678
    aDevice notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1679
	^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1680
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1681
    ^ img
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1682
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1683
    "Modified: 1.2.1997 / 14:48:20 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1684
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1685
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1686
fromStream:aStream
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1687
    "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
  1688
     out the file format itself (by contents)
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1689
     and lets the appropriate reader read the file.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1690
     To do this, the stream must be positionable.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1691
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1692
     if the stream does not contain an appropriate image."
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1693
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1694
    |image|
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1695
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1696
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1697
     ask all readers if they know
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1698
     this format ...
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1699
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1700
    MIMETypes imageReaderClasses do:[:readerClass |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1701
	readerClass notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1702
	    image := readerClass fromStream:aStream.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1703
	    image notNil ifTrue:[^ image].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1704
	]
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1705
    ].
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1706
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1707
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1708
     nope - unknown format
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1709
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1710
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1711
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1712
    ^ ImageNotFoundQuerySignal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1713
		raiseRequestWith:aStream
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1714
		errorString:('IMAGE [warning]: unknown image file format in stream').
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1715
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1716
    "
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1717
     Image fromFile:'goodies/bitmaps/gifImages/claus.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1718
     Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1719
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1720
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1721
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm.Z'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1722
     Image fromFile:'clients/Demos/bitmaps/hello_world.icon'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1723
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1724
     Image fromFile:'librun/stx.ico'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1725
     Image fromFile:'libwidg3/bitmaps/wall.tiff'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1726
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1727
     Image fromFile:'goodies/bitmaps/test.fax'
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1728
     Image fromFile:'fileIn/bitmaps/founders.im8'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1729
     Image fromFile:'goodies/faces/next.com/steve.face'
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1730
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1731
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1732
    "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
  1733
    "Modified: 30.6.1997 / 22:03:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1734
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1735
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1736
fromStream:aStream using:aReaderClass
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1737
    "read an image from a stream, given an imageReaderClass.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1738
     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
  1739
     extension (or non-definite header), so #fromStream: could not
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1740
     find out the images format.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1741
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1742
     if the stream does not contain an appropriate image."
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1743
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1744
    |image|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1745
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1746
    image := aReaderClass fromStream:aStream.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1747
    image notNil ifTrue:[^ image].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1748
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1749
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1750
     nope - unknown format
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1751
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1752
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1753
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1754
    ^ ImageNotFoundQuerySignal
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1755
		raiseRequestWith:aStream
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1756
		errorString:('IMAGE: unknown image file format in stream').
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1757
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1758
    "Created: 1.2.1997 / 14:46:20 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1759
    "Modified: 1.2.1997 / 14:48:53 / cg"
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1760
! !
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1761
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1762
!Image class methodsFor:'misc'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1763
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1764
ditherAlgorithm
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1765
    "return the way we dither -
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1766
	#threshold, or nil        -> no dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1767
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1768
	#error or #floydSteinberg -> errorDiffusion; much better
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1769
	#burkes                   -> errorDiffusion; even better."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1770
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1771
    ^ DitherAlgorithm
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1772
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1773
    "Created: 17.6.1996 / 18:57:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1774
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1775
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1776
ditherAlgorithm:aSymbol
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1777
    "define how to dither -
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1778
	#threshold, or nil        -> no dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1779
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1780
	#error or #floydSteinberg -> errorDiffusion; much better
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1781
	#burkes                   -> errorDiffusion; even better."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1782
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1783
    DitherAlgorithm := aSymbol
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1784
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1785
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1786
     Image dither:#pattern
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1787
     Image dither:#floydSteinberg
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1788
     Image dither:#burkes
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1789
     Image dither:nil
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1790
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1791
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1792
    "Modified: 10.6.1996 / 12:27:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1793
    "Created: 17.6.1996 / 18:57:19 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1794
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1795
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1796
numberOfDitherColors:n
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1797
    "define how many colors (i.e. patterns) to use when
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1798
     doing a pattern dither"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1799
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1800
    NumberOfDitherColors := n
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1801
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1802
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1803
orderedDitherMatrixOfSize:sz
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1804
    sz == 2 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1805
	^ #[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1806
		0 2
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1807
		3 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1808
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1809
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1810
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1811
    sz == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1812
	^ #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1813
		 0  8  2 10
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1814
		12  4 14  6
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1815
		 3 11  1  9
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1816
		15  7 13  5
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1817
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1818
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1819
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1820
    sz == 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1821
	^  #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1822
		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
  1823
	       48 16 56 24   50 18 58 26
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1824
	       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
  1825
	       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
  1826
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1827
		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
  1828
	       51 19 59 27   49 17 57 25
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1829
	       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
  1830
	       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
  1831
	    ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1832
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1833
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1834
    ^ nil
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1835
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1836
    "Created: 7.6.1996 / 14:15:05 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1837
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1838
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1839
!Image class methodsFor:'queries'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1840
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1841
bytesPerRowForWidth:width depth:bitsPerPixel padding:padding
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1842
    "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
  1843
     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
  1844
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1845
    |bitsPerRow paddedUnitsPerRow|
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1846
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1847
    bitsPerRow := width * bitsPerPixel.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1848
    paddedUnitsPerRow := bitsPerRow // padding.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1849
    ((bitsPerRow \\ padding) ~~ 0) ifTrue:[
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  1850
        paddedUnitsPerRow := paddedUnitsPerRow + 1
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1851
    ].
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1852
    ^ paddedUnitsPerRow * (padding // 8)
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1853
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  1854
    "
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  1855
     self bytesPerRowForWidth:7 depth:1 padding:8
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  1856
     self bytesPerRowForWidth:7 depth:1 padding:16
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  1857
     self bytesPerRowForWidth:7 depth:1 padding:32
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  1858
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  1859
     self bytesPerRowForWidth:15 depth:1 padding:8    
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  1860
     self bytesPerRowForWidth:15 depth:1 padding:16   
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  1861
     self bytesPerRowForWidth:15 depth:1 padding:32   
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  1862
    "
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1863
!
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  1864
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1865
defaultPhotometric
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1866
    "return the default photometric pixel interpretation"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1867
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1868
    ^ #blackIs0
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1869
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1870
    "Modified: 20.4.1996 / 23:40:41 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1871
    "Created: 10.6.1996 / 18:08:12 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1872
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1873
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1874
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1875
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1876
     this class.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1877
     Must be redefined in concrete subclasses"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1878
2913
c51ac85e9aa2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2891
diff changeset
  1879
    ^ self subclassResponsibility
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1880
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  1881
    "Modified: 20.4.1996 / 23:40:41 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1882
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1883
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1884
imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1885
    "return a collection of suffixes which are recognized as image-file suffix"
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1886
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1887
    ^ MIMETypes imageFileSuffixes
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1888
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1889
    "
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1890
     Image imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1891
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1892
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1893
    "Modified: 30.6.1997 / 22:04:39 / cg"
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1894
!
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  1895
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1896
imageReaderClassForMIME:mimeType
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1897
    "return an appropriate imageReader class for a given mime type;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1898
     nil if there is none (or it did not install itself)"
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1899
1801
3dff7fb2bd59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1800
diff changeset
  1900
    ^ MIMETypes imageReaderForType:mimeType
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1901
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1902
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1903
     Image imageReaderClassForMIME:'image/tiff'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1904
     Image imageReaderClassForMIME:'image/x-portable-pixmap'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1905
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1906
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1907
    "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
  1908
    "Modified: 30.6.1997 / 21:54:10 / cg"
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1909
!
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1910
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1911
imageReaderClassForSuffix:aSuffix
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1912
    "return an appropriate imageReader class for a given file-suffix;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1913
     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
  1914
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1915
    ^ MIMETypes imageReaderForSuffix:aSuffix
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1916
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1917
    "
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1918
     Image imageReaderClassForSuffix:'tiff'
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1919
     Image imageReaderClassForSuffix:'foo'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1920
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1921
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1922
    "Modified: 30.6.1997 / 22:05:14 / cg"
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1923
!
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  1924
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  1925
implementorForDepth:depth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1926
    "return the class, which best implements images of depth"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1927
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1928
    depth == 1 ifTrue:[^ Depth1Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1929
    depth == 2 ifTrue:[^ Depth2Image].
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1930
    depth <= 4 ifTrue:[^ Depth4Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1931
    depth <= 8 ifTrue:[^ Depth8Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1932
    depth <= 16 ifTrue:[^ Depth16Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  1933
    depth <= 24 ifTrue:[^ Depth24Image].
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1934
    depth <= 32 ifTrue:[^ Depth32Image].
5299
6b1d1dcf5c85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5237
diff changeset
  1935
    depth <= 48 ifTrue:[^ Depth48Image].
5313
7c40ea0163ee *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  1936
    depth <= 64 ifTrue:[^ Depth64Image].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1937
    ^ self
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1938
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  1939
    "Modified: 24.4.1997 / 19:04:52 / cg"
1611
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1940
!
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1941
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1942
isImageFileSuffix:aSuffix
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1943
    "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
  1944
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1945
     ^ self imageFileSuffixes includes:(aSuffix asLowercase)
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1946
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1947
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1948
     Image isImageFileSuffix:'gif'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1949
     Image isImageFileSuffix:'xbm'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1950
     Image isImageFileSuffix:'foo'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1951
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1952
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  1953
    "Created: 18.4.1997 / 14:55:28 / cg"
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1954
!
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1955
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1956
mimeTypeFromSuffix:suffix
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1957
    "search my suffix information for a mime type and
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1958
     return it; return nil if unknown"
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1959
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1960
    ^ MIMETypes mimeTypeForSuffix:suffix
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1961
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1962
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1963
     Image mimeTypeFromSuffix:'gif'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1964
     Image mimeTypeFromSuffix:'tiff'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1965
     Image mimeTypeFromSuffix:'foobar'
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1966
    "
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  1967
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1968
    "Modified: 1.7.1997 / 00:17:27 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1969
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1970
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1971
!Image class methodsFor:'screen capture'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1972
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1973
fromScreen
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1974
    "return an image of the full screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1975
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1976
	      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
  1977
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1978
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1979
    |display|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1980
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1981
    display := Screen current.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1982
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1983
	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
  1984
	on:display
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1985
	grab:true
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1986
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1987
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  1988
     Image fromScreen
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1989
     Image fromScreen inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1990
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1991
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1992
    "Modified: 26.3.1997 / 10:44:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1993
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1994
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1995
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1996
    "return an image of a part of the screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  1997
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1998
	      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
  1999
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2000
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2001
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2002
	fromScreen:aRectangle
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2003
	on:Screen current
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2004
	grab:true
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2005
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2006
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2007
     Image fromScreen:(0@0 corner:100@100)
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2008
     (Image fromScreen:(0@0 corner:100@100)) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2009
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2010
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2011
    "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
  2012
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2013
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2014
fromScreen:aRectangle on:aDevice
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2015
    "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
  2016
     another display device.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2017
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2018
	      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
  2019
	      (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
  2020
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2021
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2022
	fromScreen:aRectangle
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2023
	on:aDevice
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2024
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2025
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2026
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2027
     Image fromScreen:(0@0 corner:100@100)
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2028
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2029
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2030
    "get a snapshot of your friends screen ...
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2031
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2032
     |dpy2|
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2033
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2034
     dpy2 := XWorkstation new initializeFor:'idefix:0'.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2035
     (Image fromScreen:(dpy2 bounds) on:dpy2) inspect
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2036
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2037
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2038
    "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
  2039
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2040
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2041
fromScreen:aRectangle on:aDisplay grab:doGrab
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2042
    "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
  2043
     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
  2044
     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
  2045
     shown while the readout is done.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2046
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2047
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2048
	      (use with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2049
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2050
    |depth vis img|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2051
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2052
    depth := aDisplay depth.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2053
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2054
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2055
    "/ 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
  2056
    "/ (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
  2057
    "/  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
  2058
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2059
    vis := aDisplay visualType.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2060
    (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2061
	depth > 8 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2062
	    depth := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2063
	]
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2064
    ].
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2065
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  2066
    img := self newForDepth:depth.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2067
    ^ img fromScreen:aRectangle on:aDisplay grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2068
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
  2069
    "Modified: / 26.1.1998 / 22:23:08 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2070
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2071
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2072
fromScreenArea
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2073
    "return an image of a part of the screen;
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2074
     let user specify screen area.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2075
     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
  2076
     Use #fromUser for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2077
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2078
	      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
  2079
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2080
2102
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2081
    |r|
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2082
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2083
    [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
  2084
    r := Rectangle fromUser.
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2085
    r width == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2086
    r height == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2087
    ^ self fromScreen:r
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2088
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2089
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2090
     Image fromScreenArea
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2091
     Image fromScreenArea inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2092
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2093
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2094
    "Modified: / 10.9.1998 / 15:59:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2095
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2096
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2097
fromUser
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2098
    "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
  2099
     Same as fromScreenArea, for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2100
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2101
	      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
  2102
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2103
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2104
    ^ self fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2105
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2106
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2107
     Image fromUser
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2108
     Image fromUser inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2109
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2110
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2111
    "Modified: 26.3.1997 / 10:45:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2112
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2113
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2114
fromView:aView
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2115
    "return an image taken from a views contents as currently
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2116
     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
  2117
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2118
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2119
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2120
     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
  2121
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2122
	      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
  2123
	      (use #fromView:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2124
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2125
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2126
	fromView:aView
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2127
	grab:true
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2128
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2129
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2130
     Image fromView:(Launcher allInstances first window topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2131
     Image fromView:(BrowserView allInstances first topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2132
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2133
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2134
    "get a snapshot from whichever view is active:
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2135
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2136
     |active|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2137
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2138
     active := WindowGroup activeGroup topViews first.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2139
     (Image fromView:active) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2140
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2141
1043
0688425d02c9 Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents: 1041
diff changeset
  2142
    "Modified: 9.9.1996 / 22:41:01 / stefan"
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2143
    "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
  2144
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2145
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2146
fromView:aView grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2147
    "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
  2148
     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
  2149
     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
  2150
     shown while the readout is done.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2151
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2152
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2153
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2154
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2155
     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
  2156
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2157
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2158
	      (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2159
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2160
    ^ self fromView:aView grab:doGrab withDecoration:false
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2161
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2162
    "Created: / 26.3.1997 / 10:34:20 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2163
    "Modified: / 10.10.2001 / 14:13:29 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2164
!
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2165
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2166
fromView:aView grab:doGrab withDecoration:withDecoration
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2167
    "return an image taken from a views contents as currently
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2168
     on the screen, optionally with decoration included.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2169
     If the doGrab argument is true, the display
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2170
     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
  2171
     shown while the readout is done.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2172
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2173
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2174
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2175
     the returned Image is NOT correct.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2176
     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
  2177
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2178
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2179
	      (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2180
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2181
    |org ext device cH bW bH|
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2182
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2183
    device := aView graphicsDevice.
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2184
    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
  2185
    ext := aView extent.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2186
    withDecoration ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2187
	device platformName = 'WIN32' ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2188
	    cH := device captionHeight.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2189
	    bW := (device getSystemMetrics: #SM_CXFRAME )
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2190
		  "+ ( device getSystemMetrics: #borderFrameWidth )".
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2191
	    bH := (device getSystemMetrics: #SM_CYFRAME )
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2192
		  " + ( device getSystemMetrics: #borderFrameHeight )".
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2193
	    org := org - (bW @ (bH + cH)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2194
	    ext := ext + ((bW + bW) @ (bH+bH+cH)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2195
	].
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2196
    ].
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2197
    ^ self fromScreen:(org extent:ext) on:device grab:doGrab
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2198
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2199
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2200
     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
  2201
     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
  2202
    "
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2203
4574
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2204
    "Created: / 26-03-1997 / 10:34:20 / cg"
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2205
    "Modified: / 08-09-2006 / 15:41:41 / cg"
157
claus
parents: 154
diff changeset
  2206
! !
claus
parents: 154
diff changeset
  2207
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2208
!Image methodsFor:'Compatibility-Squeak'!
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2209
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2210
boundingBox
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2211
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2212
    ^ self bounds
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2213
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2214
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2215
colormapIfNeededForDepth:d
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2216
    ^ nil
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2217
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2218
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2219
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2220
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2221
fill:aRectangle fillColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2222
    "fill the rectangular area specified by aRectangle with the given color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2223
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2224
    self fillRectangle:aRectangle withColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2225
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2226
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2227
fillBlack:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2228
    "fill the rectangular area specified by aRectangle with the black color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2229
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2230
    self fillRectangle:aRectangle withColor:Color black
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2231
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2232
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2233
     |img|
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2234
     img := Image extent:100@100 depth:24.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2235
     img photometric:#rgb.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2236
     img data:(ByteArray new:100*100*3).
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2237
     img fillWhite:(0@0 corner:100@100).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2238
     img fillBlack:(10@10 corner:90@90).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2239
     img inspect.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2240
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2241
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2242
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2243
fillWhite:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2244
    "fill the rectangular area specified by aRectangle with the white color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2245
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2246
    self fillRectangle:aRectangle withColor:Color white
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2247
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2248
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2249
isTransparentAt:aPoint
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2250
    mask isNil ifTrue:[ ^ false].
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2251
    ^ (mask pixelAt:aPoint) == 0
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2252
! !
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2253
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2254
!Image methodsFor:'Compatibility-VW'!
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2255
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2256
asCachedImage
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2257
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2258
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2259
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2260
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2261
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2262
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2263
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2264
!
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2265
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2266
asRetainedMedium
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2267
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2268
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2269
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2270
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2271
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2272
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2273
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2274
    "Created: 27.1.1997 / 15:49:08 / cg"
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2275
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2276
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2277
bounds:newBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2278
    ^ self
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2279
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2280
    "Created: 10.2.1997 / 12:44:46 / cg"
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2281
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2282
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2283
containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2284
    "in st-80, images are visualComponents ..."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2285
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2286
    ^ self bounds containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2287
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2288
    "Created: 6.3.1997 / 15:24:12 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2289
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2290
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2291
convertToPalette:aColormap renderedBy:anImageRenderer
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2292
    "this does not really mimicri the corresponding ST-80 functionality"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2293
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2294
    |monoBits convertedImage|
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2295
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2296
    aColormap size == 2 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2297
	anImageRenderer class == OrderedDither ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2298
	    monoBits := self orderedDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2299
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2300
	    monoBits := self floydSteinbergDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2301
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2302
	(((aColormap at:1) = Color black)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2303
	and:[(aColormap at:2) = Color white]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2304
	    "/ ok
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2305
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2306
	    (((aColormap at:1) = Color white)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2307
	    and:[(aColormap at:2) = Color black]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2308
		monoBits invert
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2309
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2310
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2311
	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
  2312
	convertedImage palette:aColormap.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2313
	^ convertedImage
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2314
    ].
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2315
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2316
    self error:'unimplemented operation'.
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2317
    ^ self
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2318
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2319
    "Modified: 1.3.1997 / 17:25:50 / cg"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2320
!
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2321
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2322
paintBasis
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2323
    "huh - whats that;
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2324
     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
  2325
     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
  2326
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2327
    ^ ColorValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2328
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2329
    "Created: 6.3.1997 / 15:24:19 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2330
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2331
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2332
preferredBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2333
    ^ self bounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2334
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2335
    "Created: 10.2.1997 / 12:42:36 / cg"
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2336
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2337
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2338
tile:bounds from:origin in:tile rule:rule
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2339
    |orgX orgY tW tH|
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2340
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2341
    origin ~= (0@0) ifTrue:[
5074
ccb5a78e2119 Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents: 5051
diff changeset
  2342
        self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2343
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2344
    bounds ~= self bounds ifTrue:[
5074
ccb5a78e2119 Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents: 5051
diff changeset
  2345
        self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2346
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2347
    rule ~= #over ifTrue:[
5074
ccb5a78e2119 Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents: 5051
diff changeset
  2348
        self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2349
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2350
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2351
    orgX := origin x.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2352
    orgY := origin y.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2353
    tW := tile width.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2354
    tH := tile height.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2355
    (bounds top) to:(bounds bottom) by:tH do:[:dstY |
5074
ccb5a78e2119 Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents: 5051
diff changeset
  2356
        (bounds left) to:(bounds right) by:(tile width) do:[:dstX |
ccb5a78e2119 Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents: 5051
diff changeset
  2357
            self
ccb5a78e2119 Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents: 5051
diff changeset
  2358
                copyFrom:tile
ccb5a78e2119 Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents: 5051
diff changeset
  2359
                x:orgX y:orgY
ccb5a78e2119 Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents: 5051
diff changeset
  2360
                toX:dstX y:dstY
ccb5a78e2119 Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents: 5051
diff changeset
  2361
                width:tW height:tH.
ccb5a78e2119 Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents: 5051
diff changeset
  2362
        ].
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2363
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2364
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2365
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2366
valueAtPoint:aPoint put:aColorValue
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2367
    aColorValue isInteger ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2368
	self colorAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2369
    ] ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2370
	self pixelAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2371
    ]
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2372
! !
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2373
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2374
!Image methodsFor:'accessing'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2375
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2376
bitsPerSample
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2377
    "return the number of bits per sample.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2378
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2379
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2380
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2381
    ^ Array with:self depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2382
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2383
    "Modified: 10.6.1996 / 18:04:21 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2384
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2385
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2386
colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2387
    "return the colormap"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2388
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2389
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2390
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2391
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2392
colorMap:aColorMap
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2393
    "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
  2394
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2395
    |newSize "{ Class: SmallInteger }"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2396
     oldSize "{ Class: SmallInteger }"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2397
     sameColors|
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2398
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2399
    (aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2400
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2401
    photometric == #palette ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2402
	"/ any change at all ?
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2403
	(newSize := aColorMap size) >= (oldSize := colorMap size) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2404
	    sameColors := true.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2405
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2406
	    1 to:oldSize do:[:idx |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2407
		(aColorMap at:idx) = (colorMap at:idx) ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2408
		    sameColors := false.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2409
		]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2410
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2411
	].
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2412
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2413
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2414
    self setColorMap:aColorMap.
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2415
    sameColors ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2416
	^ self
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2417
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2418
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2419
    colorMap notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2420
	photometric := #palette.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2421
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2422
	(photometric == #palette) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2423
	    photometric := #blackIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2424
	]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2425
    ].
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2426
    deviceForm notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2427
	self release
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2428
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2429
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2430
    "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
  2431
    "Modified: / 22.8.1998 / 12:29:58 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2432
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2433
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2434
colorMapFromArray: anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2435
    "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
  2436
     The (byte-)Array argument should be of the form:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2437
	#( 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
  2438
     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
  2439
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2440
    self colorMap:(MappedPalette rgbBytesVector:anArray)
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2441
!
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2442
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2443
colorMapFromRGBValueArray:anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2444
    "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
  2445
     The (integer-)Array argument should be of the form:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2446
	#( rgb0 rgb1  ... rgbN)
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2447
     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
  2448
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2449
    self colorMap:(MappedPalette rgbValueVector:anArray)
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2450
!
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2451
757
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2452
container:aVisualContainer
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2453
    "ignored here - added to allow images to be used like
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2454
     VisualComponents (later, Image should inherit from it)"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2455
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2456
    "Created: 28.5.1996 / 23:43:49 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2457
    "Modified: 29.5.1996 / 10:22:23 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2458
!
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2459
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2460
depth
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2461
    "return the depth of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2462
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2463
    ^ self bitsPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2464
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2465
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2466
device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2467
    "return the device, the receiver is associated with.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2468
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2469
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2470
    ^ device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2471
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2472
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2473
extent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2474
    "return the images extent"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2475
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2476
    ^ width@height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2477
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2478
1950
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2479
fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2480
    "return the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2481
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2482
    ^ fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2483
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2484
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2485
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2486
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2487
fileName:something
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2488
    "set the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2489
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2490
    fileName := something.
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2491
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2492
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2493
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2494
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2495
fullColorId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2496
    "return the id of the full color image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2497
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2498
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2499
    fullColorDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2500
    ^ fullColorDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2501
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2502
728
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2503
graphicsDevice
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2504
    "same as #device - for ST-80 compatibility"
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2505
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2506
    ^ device
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2507
!
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
  2508
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2509
height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2510
    "return the height of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2511
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2512
    ^ height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2513
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2514
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2515
id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2516
    "return the id of the image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2517
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2518
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2519
    deviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2520
    ^ deviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2521
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2522
2081
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2523
imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2524
    "return the frameSequence of which this image is a part of;
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2525
     nil if it is not part of a sequence."
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2526
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2527
    ^ imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2528
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2529
    "Created: / 1.4.1998 / 14:43:00 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2530
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2531
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2532
imageSequence:aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2533
    "private entry for imageReaders - set the frameSequence of which
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2534
     this image is a part of"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2535
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2536
    imageSequence := aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2537
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2538
    "Created: / 1.4.1998 / 14:42:36 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2539
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2540
896
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2541
mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2542
    ^ mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2543
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2544
    "Created: 21.6.1996 / 12:57:44 / cg"
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2545
!
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2546
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2547
mask:anotherImage
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2548
    "set the images mask - currently, this may be nil or a Depth1Image.
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2549
     (it is planned to support alpha information in a Depth8 maskImage in
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2550
      the near future).
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2551
     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
  2552
		       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
  2553
		       0-bit mask pixels lead to transparent pixels.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2554
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2555
     For depth8 masks: (future):
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2556
		       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
  2557
		       which specifies the transparency of that pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2558
		       0 means completely transparent, 255 means completely
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2559
		       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
  2560
		       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
  2561
		       alpha value of 255."
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2562
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2563
    mask := anotherImage.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2564
    maskedPixelsAre0 := false.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2565
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2566
    "Created: 27.6.1996 / 17:45:22 / cg"
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2567
    "Modified: 12.4.1997 / 12:04:39 / cg"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2568
!
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2569
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2570
maskedPixelsAre0
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2571
    "return true if masked pixels have been cleared to zero"
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2572
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2573
    ^ maskedPixelsAre0 == true
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2574
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2575
    "Modified: / 22.8.1998 / 11:27:22 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2576
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2577
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2578
maskedPixelsAre0:aBoolean
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2579
    "set/clear the flag which states if masked pixels
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2580
     have been set to zero. Knowing this to be true allows
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2581
     faster drawing of the image later; (however, not setting
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2582
     it will still produce correct output).
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2583
     This flag is typically set by image readers."
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2584
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2585
    maskedPixelsAre0 := aBoolean
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2586
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2587
    "Modified: 12.4.1997 / 12:08:42 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2588
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2589
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2590
monochromeId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2591
    "return the id of the monochrome image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2592
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2593
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2594
    monoDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2595
    ^ monoDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2596
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2597
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2598
palette
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2599
    "return the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2600
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2601
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2602
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2603
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2604
palette:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2605
    "set the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2606
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2607
    self colorMap:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2608
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2609
    "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
  2610
    "Modified: 8.6.1996 / 09:54:02 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2611
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2612
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2613
photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2614
    "return the photometric, a symbol such as #palette, #rgb etc."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2615
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2616
    ^ photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2617
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2618
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2619
samplesPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2620
    "return the number of samples per pixel in the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2621
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2622
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2623
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2624
    ^ 1
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2625
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2626
    "Modified: 10.6.1996 / 18:03:30 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2627
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2628
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2629
setColorMap:aColorMap
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2630
    (aColorMap isNil or:[aColorMap isKindOf:Colormap]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2631
	colorMap := MappedPalette withColors:aColorMap
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2632
    ] ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2633
	colorMap := aColorMap
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2634
    ]
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2635
!
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2636
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2637
width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2638
    "return the width of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2639
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2640
    ^ width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2641
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2642
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  2643
!Image methodsFor:'accessing-pixels'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2644
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2645
at:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2646
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2647
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2648
     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
  2649
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2650
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2651
     retrieve the pixel at aPoint; return a color.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2652
     Pixels start at 0@0 for upper left pixel, end at
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2653
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2654
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2655
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2656
     (it is meant to access individual pixels - for example, in a bitmap editor)"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2657
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2658
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2659
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2660
    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
  2661
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2662
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2663
    "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
  2664
    "Modified: / 9.1.1998 / 20:33:52 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2665
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2666
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2667
at:aPoint put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2668
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2669
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2670
     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
  2671
     Use #colorAt:put: - for future compatibility.
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
     set the pixel at aPoint to aColor.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2674
     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
  2675
     (width-1)@(height-1) for lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2676
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2677
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2678
     (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
  2679
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2680
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2681
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2682
    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
  2683
    ^ self colorAtX:aPoint x y:aPoint y put:aColor
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2684
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2685
    "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
  2686
    "Modified: / 9.1.1998 / 20:34:15 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2687
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2688
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2689
atImageAndMask:aPoint put:aColorOrPixelOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2690
    "set the pixel at x/y to aColor.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2691
     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
  2692
     otherwise to 1. Nil is treated like noColor.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2693
     (used by the bitmap editor)"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2694
2523
4c197af8cc50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2502
diff changeset
  2695
    |maskVal|
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2696
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2697
    (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
  2698
	maskVal := 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2699
	aColorOrPixelOrNil isInteger ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2700
	    self pixelAt:aPoint put:aColorOrPixelOrNil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2701
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2702
	    self colorAt:aPoint put:aColorOrPixelOrNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2703
	]
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2704
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2705
	maskVal := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2706
	self pixelAt:aPoint put:0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2707
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2708
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2709
	mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2710
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2711
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2712
    "Modified: / 30.9.1998 / 22:42:44 / cg"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2713
!
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2714
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2715
atImageAndMask:aPoint putValue:aPixelValueOrNil
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2716
    "set the pixel at x/y to aColor.
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2717
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  2718
     otherwise to 1. (used by the bitmap editor)"
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2719
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2720
    |pixVal maskVal|
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2721
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2722
    aPixelValueOrNil notNil ifTrue:[
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  2723
        pixVal := aPixelValueOrNil.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  2724
        maskVal := 1.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2725
    ] ifFalse:[
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  2726
        pixVal := 0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  2727
        maskVal := 0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2728
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2729
    mask notNil ifTrue:[
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  2730
        mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2731
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2732
    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
  2733
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2734
    "Modified: / 30.9.1998 / 22:42:44 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2735
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  2736
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2737
atPoint:aPoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2738
    "ST-80 compatibility: return the pixelValue at:aPoint."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2739
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2740
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2741
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2742
    "Modified: 24.4.1997 / 16:18:44 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2743
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2744
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2745
atPoint:aPoint put:aPixelValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2746
    "ST-80 compatibility: set the pixelValue at:aPoint."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2747
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2748
    ^ self pixelAtX:aPoint x y:aPoint y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2749
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2750
    "Modified: 24.4.1997 / 17:17:59 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2751
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2752
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2753
atX:x y:y
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2754
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2755
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2756
     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
  2757
     Use #colorAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2758
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2759
     Retrieve a pixel at x/y; return a color.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2760
     Pixels start at 0@0 for upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2761
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2762
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2763
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2764
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2765
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2766
    '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
  2767
    ^ self colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2768
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2769
    "Modified: 21.6.1997 / 13:10:32 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2770
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2771
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2772
atX:x y:y put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2773
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2774
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2775
     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
  2776
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2777
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2778
     set the pixel at x/y to aColor.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2779
     Pixels start at 0@0 for the upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2780
     (width-1)@(height-1) for the lower right pixel.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2781
     This method checks if the color can be stored in the image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2782
     (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
  2783
     You should not use this method for image-processing, it is very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2784
     (it is meant to access individual pixels - for example, in a bitmap editor)"
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2785
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2786
    aColor isInteger ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2787
	'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
  2788
	^ self pixelAtX:x y:y put:aColor
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2789
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2790
    ^ self colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2791
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  2792
    "Modified: 21.6.1997 / 13:10:44 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2793
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2794
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2795
atX:x y:y putValue:aPixelValue
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2796
    "set the pixel at x/y to aPixelValue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2797
     The interpretation of the pixelValue depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2798
     and the colormap. (see also: Image>>atX:y:put:)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2799
     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
  2800
     (width-1) @ (height-1) for the lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2801
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2802
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2803
     (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
  2804
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2805
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2806
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2807
    self obsoleteMethodWarning:'use #pixelAtX:y:put:'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2808
    ^ self pixelAtX:x y:y put:aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2809
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2810
    "Modified: 24.4.1997 / 17:15:45 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2811
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2812
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2813
bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2814
    "return the raw image data; depending on the photometric,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2815
     this has to be interpreted as monochrome, greyscale,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2816
     palette or rgb data.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2817
     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
  2818
     will store 2 pixels per byte, whereas a 2-bitPerPixel image will store
be0fa075e4c4 comment
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
  2819
     4 pixels per byte."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2820
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2821
    ^ bytes
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2822
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2823
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2824
colorAt:aPoint
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2825
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2826
     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
  2827
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2828
     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
  2829
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2830
     (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
  2831
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2832
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2833
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2834
    "Created: 24.4.1997 / 17:02:31 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2835
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2836
1962
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2837
colorAt: aPoint put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2838
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2839
    self colorAtX: aPoint x y: aPoint y put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2840
!
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  2841
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2842
colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2843
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2844
     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
  2845
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2846
     You should not use this method for image-processing, its
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2847
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2848
     (it is meant to access individual pixels - for example, in a bitmap editor)"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2849
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2850
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2851
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2852
    pixel := self pixelAtX:x y:y.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2853
    ^ self colorFromValue:pixel
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2854
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2855
    "Modified: 24.4.1997 / 16:18:53 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2856
    "Created: 24.4.1997 / 17:00:52 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2857
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2858
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2859
colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2860
    "set the pixel at x/y to aColor.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2861
     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
  2862
     (width-1)@(height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2863
     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
  2864
     (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
  2865
     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
  2866
     (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
  2867
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2868
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2869
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2870
    pixel := self valueFromColor:aColor.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2871
    pixel isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2872
	^ UnrepresentableColorSignal raiseErrorString:'cannot store color - not in colormap'.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2873
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2874
    self pixelAtX:x y:y put:pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2875
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2876
    "Modified: 24.4.1997 / 17:36:20 / cg"
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
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2879
data
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2880
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2881
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2882
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2883
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2884
    self obsoleteMethodWarning:'use #bits'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  2885
    ^ self bits
1660
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
    "Modified: 24.4.1997 / 17:37:57 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2888
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2889
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2890
data:aByteArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2891
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2892
4175
a9e65365e590 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 4173
diff changeset
  2893
    <resource:#obsolete>
3966
950a2db201c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3964
diff changeset
  2894
    self obsoleteMethodWarning:'use #bits:'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  2895
    self bits:aByteArray
1660
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
    "Modified: 24.4.1997 / 17:38:18 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2898
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2899
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2900
maskAt:aPoint
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2901
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2902
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2903
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2904
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2905
    ^ self maskAtX:aPoint x y:aPoint y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2906
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2907
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2908
maskAt:aPoint put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2909
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2910
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2911
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2912
    ^ self maskAtX:aPoint x y:aPoint y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2913
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2914
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2915
maskAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2916
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2917
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2918
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2919
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2920
    mask isNil ifTrue:[^ 1].
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2921
    ^ mask pixelAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2922
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  2923
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2924
maskAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2925
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2926
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2927
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2928
    mask isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  2929
	maskValue == 1 ifTrue:[^ self].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  2930
	self error:'image has no mask'.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2931
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2932
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2933
    ^ mask pixelAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2934
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  2935
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2936
pixelAt:aPoint
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2937
    "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
  2938
     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
  2939
     (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
  2940
     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
  2941
     very slow ...
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2942
     (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
  2943
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2944
    ^ 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
  2945
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2946
    "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
  2947
!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  2948
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2949
pixelAt:aPoint put:aPixelValue
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2950
    "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
  2951
     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
  2952
     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
  2953
     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
  2954
     (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
  2955
     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
  2956
     very slow ...
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2957
     (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
  2958
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2959
    ^ 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
  2960
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2961
    "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
  2962
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  2963
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2964
pixelAtX:x y:y
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2965
    "retrieve the pixelValue at aPoint; return an integer number.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2966
     Pixels start at 0/0 for upper left pixel, and end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2967
     width-1@height-1 for lower right pixel.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2968
     The returned numbers interpretation depends on the photometric
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2969
     and the colormap. (see also Image>>at: and Image>>atX:y:)
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2970
     You should not use this method for image-processing of
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2971
     big images, its very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2972
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2973
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2974
    ^ self subclassResponsibility
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2975
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2976
    "Created: 24.4.1997 / 16:06:56 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2977
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2978
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2979
pixelAtX:x y:y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2980
    "set the pixel at x/y to aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2981
     The interpretation of the pixelValue depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2982
     and the colormap. (see also: Image>>atX:y:put:)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2983
     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
  2984
     (width-1) @ (height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2985
     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
  2986
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2987
     (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
  2988
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2989
    ^ self subclassResponsibility
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2990
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2991
    "Created: 24.4.1997 / 17:05:11 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2992
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2993
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2994
rgbValueAt:aPoint
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2995
    "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
  2996
     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
  2997
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2998
    ^ self rgbValueAtX:(aPoint x) y:(aPoint y)
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  2999
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3000
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3001
rgbValueAtX:x y:y
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3002
    "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
  3003
     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
  3004
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3005
    |pixel|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3006
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3007
    pixel := self pixelAtX:x y:y.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3008
    ^ self rgbFromValue:pixel
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3009
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3010
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3011
rgbValueAtX:x y:y put:newRGBValue         
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3012
    |value|
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3013
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3014
    value := self valueFromRGB:newRGBValue.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3015
    self pixelAtX:x y:y put:value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3016
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3017
    "Created: / 15-01-2008 / 15:56:10 / cg"
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3018
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3019
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3020
rowAt:y
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3021
    "retrieve an array filled with pixel values from
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3022
     a single row.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3023
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3024
     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
  3025
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3026
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3027
    |pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3028
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3029
    pixelArray := self pixelArraySpecies new:width.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3030
    self rowAt:y into:pixelArray startingAt:1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3031
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3032
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3033
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3034
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3035
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3036
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3037
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3038
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3039
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3040
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3041
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3042
     i := Image fromFile:'libtool/bitmaps/SBrowser.xbm'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3043
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3044
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3045
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3046
    "Modified: 24.4.1997 / 15:51:24 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3047
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3048
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3049
rowAt:y into:aPixelBuffer
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3050
    "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
  3051
     Notice: row coordinate starts at 0."
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3052
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3053
    ^ self rowAt:y into:aPixelBuffer startingAt:1
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3054
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3055
    "Created: 24.4.1997 / 15:44:46 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3056
    "Modified: 24.4.1997 / 15:51:35 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3057
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3058
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3059
rowAt:y into:aPixelBuffer startingAt:startIndex
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3060
    "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
  3061
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3062
     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
  3063
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3064
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3065
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3066
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3067
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3068
    0 to:w do:[:col |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3069
	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
  3070
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3071
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3072
    "Created: 24.4.1997 / 15:05:21 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3073
    "Modified: 24.4.1997 / 16:52:43 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3074
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3075
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3076
rowAt:y putAll:pixelArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3077
    "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
  3078
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3079
     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
  3080
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3081
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3082
    ^ self rowAt:y putAll:pixelArray startingAt:1
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3083
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3084
    "Modified: 24.4.1997 / 15:51:58 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3085
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3086
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3087
rowAt:y putAll:pixelArray startingAt:startIndex
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3088
    "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
  3089
     return the pixelArray.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3090
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3091
     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
  3092
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3093
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3094
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3095
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3096
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3097
    0 to:w do:[:col |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3098
	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
  3099
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3100
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3101
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3102
    "Modified: 24.4.1997 / 17:05:57 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3103
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3104
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3105
valueAt:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3106
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3107
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3108
     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
  3109
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3110
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3111
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3112
     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
  3113
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3114
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3115
     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
  3116
     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
  3117
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3118
     (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
  3119
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3120
    '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
  3121
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3122
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3123
    "Modified: 21.6.1997 / 13:11:19 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3124
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3125
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3126
valueAtX:x y:y
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3127
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3128
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3129
     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
  3130
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3131
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3132
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3133
     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
  3134
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3135
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3136
     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
  3137
     You should not use this method for image-processing of
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3138
     big images, its very slow ...
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3139
     (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
  3140
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3141
    '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
  3142
    ^ self pixelAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3143
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3144
    "Modified: 21.6.1997 / 13:11:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3145
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3146
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  3147
!Image methodsFor:'accessing-private'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3148
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3149
bits:aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3150
    "set the raw data.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3151
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3152
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3153
     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
  3154
     existing image may confuse later pixel interpretation
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3155
     (it does not care for colormaps and/or cached device image flushing)."
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3156
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3157
    bytes := aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3158
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3159
    "Modified: 23.4.1996 / 11:08:28 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3160
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3161
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
  3162
bitsPerSample:aCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3163
    "set the number of bits per sample.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3164
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3165
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3166
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3167
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3168
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
  3169
    bitsPerSample := aCollection
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3170
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3171
    "Modified: 23.4.1996 / 11:08:31 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3172
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3173
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3174
depth:d
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3175
    "set the depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3176
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3177
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3178
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3179
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3180
1362
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  3181
    depth := self depth.
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  3182
    bitsPerPixel := d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3183
    d == 24 ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3184
        samplesPerPixel := 3.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3185
        bitsPerSample := #[8 8 8]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3186
    ] ifFalse:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3187
        d == 32 ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3188
            samplesPerPixel := 4.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3189
            bitsPerSample := #[8 8 8 8]
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3190
        ] ifFalse:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3191
            d == 16 ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3192
                samplesPerPixel := 3.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3193
                bitsPerSample := #[5 5 5]
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3194
            ] ifFalse:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3195
                samplesPerPixel := 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3196
                bitsPerSample := ByteArray with:d
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3197
            ]
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3198
        ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3199
    ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3200
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3201
    "Modified: / 27-05-2007 / 16:59:47 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3202
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3203
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3204
extent:anExtent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3205
    "set the images extent.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3206
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3207
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3208
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3209
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3210
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3211
    width := anExtent x.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3212
    height := anExtent y
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3213
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3214
    "Modified: 23.4.1996 / 11:08:38 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3215
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3216
5326
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3217
hasAlphaChannel
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3218
    ^ false
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3219
!
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3220
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3221
height:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3222
    "set the height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3223
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3224
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3225
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3226
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3227
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3228
    height := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3229
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3230
    "Modified: 23.4.1996 / 11:08:40 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3231
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3232
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3233
photometric:aSymbol
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3234
    "set the photometric interpretation of the pixel values.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3235
     The argument, aSymbol is one of:
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3236
	#blackIs0, #whiteIs0, #palette, #rgb
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3237
     See TIFF documentation, from which the photometric concept is borrowed.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3238
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3239
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3240
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3241
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3242
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3243
    |b|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3244
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3245
    photometric := aSymbol.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3246
    bitsPerSample isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3247
	photometric == #rgb ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3248
	    b := self class imageDepth // 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3249
	    bitsPerSample := ByteArray with:b with:b with:b
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3250
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3251
	    bitsPerSample := ByteArray with:(self class imageDepth)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3252
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3253
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3254
    samplesPerPixel isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3255
	photometric == #rgb ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3256
	    samplesPerPixel := 3
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3257
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3258
	    samplesPerPixel := 1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3259
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3260
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3261
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3262
    "Modified: 10.6.1996 / 18:21:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3263
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3264
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3265
samplesPerPixel:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3266
    "set the array of samples per pixel.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3267
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3268
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3269
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3270
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3271
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3272
    samplesPerPixel := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3273
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3274
    "Modified: 23.4.1996 / 11:08:45 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3275
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3276
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3277
width:aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3278
    "set the width of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3279
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3280
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3281
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3282
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3284
    width := aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3285
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3286
    "Modified: 23.4.1996 / 11:08:48 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3287
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3288
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3289
width:w height:h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3290
    "set the width and height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3291
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3292
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3293
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3294
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3295
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3296
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3297
    height := h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3298
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3299
    "Modified: 23.4.1996 / 11:08:53 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3300
!
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3301
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3302
width:w height:h depth:d
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3303
    "set the width, height and depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3304
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3305
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3306
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3307
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3308
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3309
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3310
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3311
    self depth:d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3312
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3313
    "Modified: 23.4.1996 / 11:08:56 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3314
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3315
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3316
width:w height:h depth:d fromArray:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3317
    "set the width, height, depth and pixels of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3318
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3319
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3320
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3321
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3322
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3323
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3324
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3325
    self depth:d.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3326
    self bits:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3327
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3328
    "Modified: 23.4.1996 / 11:08:59 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3329
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3330
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3331
width:w height:h depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3332
    "set the width, height and depth of the image.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3333
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3334
     This interface is only to be used when initializing
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3335
     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
  3336
     existing image may confuse later pixel interpretation."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3337
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3338
    width := w.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3339
    height := h.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3340
    self depth:d.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3341
    self setColorMap:aColormap.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3342
    aColormap notNil ifTrue:[
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3343
        photometric := #palette
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3344
    ] ifFalse:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3345
        photometric := #blackIs0
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3346
    ].
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3347
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3348
    "Modified: 23.4.1996 / 11:08:56 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3349
    "Created: 6.3.1997 / 15:23:57 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3350
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3351
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3352
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
  3353
    "set all relevant internal state of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3354
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3355
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3356
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3357
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3358
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3359
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3360
	width:w
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3361
	height:h
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3362
	photometric:p
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3363
	samplesPerPixel:spp
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3364
	bitsPerSample:bps
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3365
	colorMap:cm
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3366
	bits:pixels
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3367
	mask:nil
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3368
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3369
    "Modified: 20.6.1996 / 17:10:24 / cg"
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3370
!
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3371
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3372
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
  3373
    "set all relevant internal state of the image.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3374
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3375
     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
  3376
     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
  3377
     existing image may confuse later pixel interpretation."
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3378
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3379
    width := w.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3380
    height := h.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3381
    photometric := p.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3382
    samplesPerPixel := spp.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3383
    bitsPerSample := bps.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3384
    self setColorMap:cm.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3385
    self bits:pixels.
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3386
    mask := m.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3387
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3388
    "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
  3389
    "Created: 20.6.1996 / 17:09:53 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3390
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  3391
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  3392
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3393
!Image methodsFor:'conversion helpers'!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3394
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3395
rgbColormapFor:aDevice
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3396
    "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
  3397
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3398
    |nColors    "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3399
     scaleRed scaleGreen scaleBlue
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3400
     redShift   "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3401
     greenShift "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3402
     blueShift  "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3403
     colorValues|
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3404
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3405
    "/ 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
  3406
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3407
    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
  3408
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3409
    "/ 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
  3410
    "/ (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
  3411
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3412
    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
  3413
    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
  3414
    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
  3415
    redShift := aDevice shiftRed.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3416
    greenShift := aDevice shiftGreen.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3417
    blueShift := aDevice shiftBlue.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3418
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3419
    colorValues := Array uninitializedNew:nColors.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3420
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3421
    0 to:nColors-1 do:[:pixel |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3422
	|clr rv gv bv v "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3423
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3424
	clr := self colorFromValue:pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3425
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3426
	rv := (clr red * scaleRed) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3427
	gv := (clr green * scaleGreen) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3428
	bv := (clr blue * scaleBlue) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3429
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3430
	v := rv bitShift:redShift.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3431
	v := v bitOr:(gv bitShift:greenShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3432
	v := v bitOr:(bv bitShift:blueShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3433
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3434
	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
  3435
"/ clr print. ' ' print.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3436
"/ 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
  3437
"/ ' -> ' print. v printNL.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3438
    ].
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3439
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3440
    ^ colorValues
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3441
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3442
    "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
  3443
! !
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3444
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3445
!Image methodsFor:'converting'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3446
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3447
asBurkesDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3448
    "return a burkes dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3449
     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
  3450
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3451
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3452
     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
  3453
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3454
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3455
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3456
    monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3457
    ^ 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
  3458
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3459
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3460
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3461
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3462
     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
  3463
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3464
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3465
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3466
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3467
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3468
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3469
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3470
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3471
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3472
     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
  3473
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3474
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3475
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3476
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3477
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3478
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3479
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3480
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3481
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3482
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3483
	     width:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3484
	     height:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3485
	     fromArray:#[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3486
			    16r01 16r23
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3487
			    16r45 16r67
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3488
			    16r89 16rab
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3489
			    16rcd 16ref
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3490
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3491
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3492
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3493
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3494
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3495
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3496
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3497
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3498
    "Created: 10.6.1996 / 12:34:44 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3499
    "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
  3500
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3501
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3502
asDitheredImageUsing:colors
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3503
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3504
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3505
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3506
    ^ self asDitheredImageUsing:colors depth:self depth
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3507
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3508
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3509
asDitheredImageUsing:colors depth:d
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3510
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3511
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3512
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3513
    |newBits|
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3514
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3515
    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
  3516
    newBits isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3517
	self error:'dithering failed'
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3905
diff changeset
  3518
    ].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  3519
    ^ (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
  3520
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3521
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3522
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3523
asErrorDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3524
    "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
  3525
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3526
    DitherAlgorithm == #burkes ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3527
	^ self asBurkesDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3528
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3529
    DitherAlgorithm == #stevensonArce ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3530
	^ self asStevensonArceDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3531
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3532
    ^ self asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3533
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3534
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3535
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3536
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3537
     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
  3538
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3539
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3540
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3541
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3542
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3543
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3544
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3545
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3546
     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
  3547
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3548
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3549
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3550
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3551
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3552
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3553
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3554
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3555
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3556
	     width:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3557
	     height:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3558
	     fromArray:#[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3559
			    16r01 16r23
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3560
			    16r45 16r67
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3561
			    16r89 16rab
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3562
			    16rcd 16ref
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3563
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3564
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3565
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3566
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3567
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3568
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3569
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3570
    "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
  3571
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3572
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3573
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3574
    "return a floyd-steinberg dithered pseudoForm from the picture.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3575
     Use the colors in the fixColors array.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3576
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3577
     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
  3578
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3579
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3580
    |pseudoBits f deviceDepth map|
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3581
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3582
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3583
    deviceDepth == 8 ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3584
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3585
            ^ nil.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3586
        ]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3587
    ].
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3588
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3589
    pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3590
    pseudoBits isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3591
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3592
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3593
    f isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3594
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3595
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3596
    "/ have to create a funny colorMap, where
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3597
    "/ color at:index == color colorId:index
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3598
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3599
    map := Array new:256.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3600
    fixColors do:[:clr |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3601
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3602
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3603
    f colorMap:map.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3604
    f initGC.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3605
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3606
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3607
        drawBits:pseudoBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3608
        bitsPerPixel:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3609
        depth:deviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3610
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3611
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3612
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3613
        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
  3614
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3615
        with:(f gcId).
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3616
    ^ f
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3617
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3618
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3619
     example:
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3620
        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
  3621
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3622
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3623
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3624
     map := #(
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3625
                  (0     0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3626
                  (0     0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3627
                  (0    50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3628
                  (0    50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3629
                  (0   100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3630
                  (0   100 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3631
                  (100   0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3632
                  (100   0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3633
                  (100  50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3634
                  (100  50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3635
                  (100 100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3636
                  (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
  3637
                                                      green:(rgb at:2)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3638
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3639
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3640
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3641
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3642
                      colors:map
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3643
                        nRed:2
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3644
                      nGreen:3
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3645
                       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3646
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3647
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3648
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3649
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3650
    "Modified: 14.6.1996 / 16:52:34 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3651
    "Created: 23.6.1997 / 15:25:37 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3652
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  3653
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3654
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3655
    "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
  3656
     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
  3657
     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
  3658
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3659
     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
  3660
     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
  3661
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3662
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3663
    |pseudoBits f deviceDepth map|
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3664
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3665
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3666
    deviceDepth == 8 ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3667
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3668
            ^ nil
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3669
        ]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3670
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3671
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3672
    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
  3673
    pseudoBits isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3674
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3675
    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
  3676
    f isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3677
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3678
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3679
    "/ have to create a funny colorMap, where
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3680
    "/ color at:index == color colorId:index
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3681
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3682
    map := Array new:256.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3683
    fixColors do:[:clr |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3684
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3685
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3686
    f colorMap:map.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3687
    f initGC.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3688
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3689
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3690
        drawBits:pseudoBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3691
        bitsPerPixel:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3692
        depth:deviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3693
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3694
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3695
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3696
        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
  3697
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3698
        with:(f gcId).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3699
    ^ f
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3700
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3701
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3702
     example:
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3703
        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
  3704
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3705
     |img8 reducedImg8 img4 map form|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3706
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3707
     map := #(
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3708
                  (0     0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3709
                  (0     0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3710
                  (0    50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3711
                  (0    50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3712
                  (0   100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3713
                  (0   100 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3714
                  (100   0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3715
                  (100   0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3716
                  (100  50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3717
                  (100  50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3718
                  (100 100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3719
                  (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
  3720
                                                      green:(rgb at:2)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3721
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3722
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3723
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3724
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3725
                      colors:map
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3726
                        nRed:2
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3727
                      nGreen:3
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3728
                       nBlue:2.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3729
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3730
     img4 := Depth4Image fromImage:img8.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3731
    "
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3732
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3733
    "Modified: 14.6.1996 / 16:52:34 / cg"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3734
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  3735
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3736
asFloydSteinbergDitheredGrayFormOn:aDevice
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3737
    "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
  3738
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3739
    |depth bits|
809
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
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3742
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3743
    or:[aDevice hasGrayscales not]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3744
	"/ for monochrome, there is specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3745
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3746
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3747
	bits := self floydSteinbergDitheredMonochromeBits.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3748
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3749
	bits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3750
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3751
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3752
    ^ 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
  3753
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3754
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3755
     |i|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3756
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3757
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3758
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3759
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3760
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3761
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3762
     |i|
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3763
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3764
     i := Image fromFile:'bitmaps/granite.tiff'.
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3765
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3766
    "
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  3767
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3768
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3769
    "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
  3770
!
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
asFloydSteinbergDitheredGrayImageDepth:depth
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3773
    "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
  3774
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3775
    |ditheredBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3776
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  3777
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3778
	^ self asFloydSteinbergDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3779
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3780
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1778
diff changeset
  3781
    ditheredBits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3782
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3783
	width:width height:height fromArray:ditheredBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3784
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3785
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3786
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3787
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3788
     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
  3789
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3790
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3791
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3792
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3793
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3794
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3795
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3796
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3797
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3798
     i := Depth24Image width:4 height:1
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3799
	  fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3800
	    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
  3801
	    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
  3802
	    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
  3803
	    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
  3804
     i := i magnifiedBy:4@1.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3805
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3806
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3807
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3808
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3809
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3810
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3811
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3812
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3813
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3814
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3815
     i := Depth24Image width:4 height:6
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3816
	  fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3817
	    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
  3818
	    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
  3819
	    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
  3820
	    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
  3821
	    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
  3822
	    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
  3823
     i := i magnifiedBy:30.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3824
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3825
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3826
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3827
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3828
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3829
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3830
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3831
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3832
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3833
     i := Image fromFile:'granite.tiff'.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3834
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3835
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3836
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3837
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3838
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3839
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3840
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3841
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  3842
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3843
     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
  3844
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3845
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3846
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3847
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3848
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3849
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3850
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3851
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3852
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3853
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3854
	     width:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3855
	     height:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3856
	     fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3857
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3858
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3859
			    16r89 16rab
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3860
			    16rcd 16ref
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3861
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3862
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3863
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3864
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3865
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3866
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3867
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3868
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3869
    "Created: 10.6.1996 / 12:33:47 / cg"
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  3870
    "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
  3871
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3872
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3873
asFloydSteinbergDitheredMonochromeFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3874
    "return a dithered moncohrome form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3875
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  3876
    |monoBits|
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3877
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3878
    monoBits := self floydSteinbergDitheredMonochromeBits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3879
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3880
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3881
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3882
     |i f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3883
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3884
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3885
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3886
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3887
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3888
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3889
     |i f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3890
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3891
     i := Depth2Image width:8 height:8
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3892
	  fromArray:#[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3893
			4r0000 4r0000
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3894
			4r0000 4r0000
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3895
			4r1111 4r1111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3896
			4r1111 4r1111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3897
			4r2222 4r2222
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3898
			4r2222 4r2222
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3899
			4r3333 4r3333
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3900
			4r3333 4r3333
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3901
		     ].
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3902
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3903
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  3904
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3905
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3906
    "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
  3907
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3908
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3909
asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3910
    "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
  3911
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3912
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3913
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3914
    monoBits := self floydSteinbergDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3915
    ^ 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
  3916
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3917
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3918
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3919
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3920
     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
  3921
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3922
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3923
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3924
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3925
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3926
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3927
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3928
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3929
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3930
     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
  3931
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3932
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3933
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3934
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3935
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3936
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3937
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3938
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3939
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3940
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3941
	     width:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3942
	     height:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3943
	     fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3944
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3945
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3946
			    16r89 16rab
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3947
			    16rcd 16ref
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3948
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3949
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3950
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3951
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3952
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3953
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3954
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3955
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3956
    "Created: 10.6.1996 / 12:33:47 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  3957
    "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
  3958
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3959
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3960
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3961
    "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
  3962
     using colors in colors for dithering."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3963
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3964
    |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
  3965
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3966
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3967
    has8BitImage := (deviceDepth == 8)
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3968
                    or:[ (aDevice supportedImageFormatForDepth:8) notNil ].
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  3969
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3970
    has8BitImage ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3971
        deviceDepth == 4 ifFalse:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3972
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3973
        pseudoBits8 := self nfloydSteinbergDitheredDepth8BitsColors:colors.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3974
        pseudoBits8 isNil ifTrue:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3975
        "/ convert to devices depth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3976
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3977
        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
  3978
        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
  3979
        d := 4.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  3980
    ] ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3981
        pseudoBits := self nfloydSteinbergDitheredDepth8BitsColors:colors.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3982
        pseudoBits isNil ifTrue:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3983
        d := 8.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3984
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3985
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3986
    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
  3987
    f isNil ifTrue:[^ nil].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3988
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3989
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3990
    "/ have to create a funny colorMap, where
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3991
    "/ color at:index == color colorId:index
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3992
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3993
    map := Array new:256 withAll:0.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  3994
    colors do:[:clr |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3995
        clr notNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  3996
            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
  3997
        ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3998
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3999
    f colorMap:map.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4000
    f initGC.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4001
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4002
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4003
        drawBits:pseudoBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4004
        bitsPerPixel:d
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4005
        depth:deviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4006
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4007
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4008
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4009
        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
  4010
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4011
        with:(f gcId).
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4012
    ^ f
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4013
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4014
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4015
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4016
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4017
     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
  4018
     (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
  4019
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4020
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4021
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4022
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4023
     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
  4024
     (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
  4025
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4026
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4027
    "Created: 17.6.1996 / 12:13:35 / cg"
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4028
    "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
  4029
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4030
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4031
asFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4032
    "get a device form, with best possible approximation.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4033
     remember it in case someone asks again."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4034
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4035
    |form visual|
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4036
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4037
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4038
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4039
    mask notNil ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4040
        mask := mask onDevice:aDevice
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4041
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4042
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4043
    (aDevice depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4044
    or:[aDevice hasGrayscales not]) ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4045
        form := self asMonochromeFormOn:aDevice.
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4046
    ] ifFalse:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4047
        ((visual := aDevice visualType) == #StaticGray) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4048
            form := self asGrayFormOn:aDevice.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4049
        ] ifFalse:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4050
            (visual == #PseudoColor
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4051
             or:[visual == #StaticColor]) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4052
                form := self asPseudoFormQuickOn:aDevice.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4053
            ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4054
        ]
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4055
    ].
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4056
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4057
    form isNil ifTrue:[
5237
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
  4058
        "/ kludge: repair a 'should not happen' situation...
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
  4059
        photometric isNil ifTrue:[ self repairPhotometric ].
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
  4060
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4061
        (photometric == #palette) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4062
            form := self paletteImageAsFormOn:aDevice
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4063
        ] ifFalse:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4064
            (photometric == #rgb or:[photometric == #rgba]) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4065
                form := self rgbImageAsFormOn:aDevice
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4066
            ] ifFalse:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4067
                (photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4068
                    form := self rgbImageAsFormOn:aDevice
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4069
                ] ifFalse:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4070
                    form := self greyImageAsFormOn:aDevice
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4071
                ]
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4072
            ]
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4073
        ].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4074
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4075
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4076
    (device isNil or:[aDevice == device]) ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4077
        "remember this form in the receiver ..."
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4078
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4079
        form notNil ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4080
            form := form asImageForm.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4081
            deviceForm := form.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4082
            maskedPixelsAre0 := nil.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4083
            device isNil ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4084
                device := aDevice.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4085
                Lobby register:self
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4086
            ] ifFalse:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4087
                Lobby registerChange:self
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4088
            ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4089
            "
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4090
             can save space, by not keeping the images data-bits
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4091
             twice (here and in the device form)
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4092
            "
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4093
            form forgetBits
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4094
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4095
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4096
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4097
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4098
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4099
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4100
     |i|
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4101
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4102
     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
  4103
     (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
  4104
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4105
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4106
    "Modified: / 06-06-2007 / 12:18:43 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4107
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4108
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4109
asGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4110
    "get a gray device form"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4111
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4112
    ^ self asGrayFormOn:aDevice dither:DitherAlgorithm.
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
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4116
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4117
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4118
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4119
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4120
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4121
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4122
    "Created: 10.6.1996 / 18:44:42 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4123
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4124
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4125
asGrayFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4126
    "get a greyscale device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4127
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4128
    |depth|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4129
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4130
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4131
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4132
    or:[aDevice hasGrayscales not]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4133
	^ self asMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4134
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4135
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4136
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4137
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4138
	^ self asThresholdGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4139
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4140
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4141
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4142
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4143
	^ self asOrderedDitheredGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4144
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4145
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4146
    ^ self asFloydSteinbergDitheredGrayFormOn:aDevice.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4147
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4148
    "Created: 10.6.1996 / 18:42:01 / cg"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  4149
    "Modified: 14.6.1996 / 15:17:28 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4150
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4151
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4152
asGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4153
    "get a gray image from the receiver"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4154
5160
f465233332f1 fixed asGrayImage
sr
parents: 5143
diff changeset
  4155
    ((self colorMap notNil and:[depth == self depth]) 
f465233332f1 fixed asGrayImage
sr
parents: 5143
diff changeset
  4156
    or:[ self depth >= 8 "do need for dither" ]) ifTrue:[
f465233332f1 fixed asGrayImage
sr
parents: 5143
diff changeset
  4157
        ^ self copyWithColorMapProcessing:[:clr | Color brightness:(clr brightness)].
4417
5e5d9b696293 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  4158
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4159
    ^ self asGrayImageDepth:depth dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4160
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4161
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4162
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4163
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4164
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4165
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4166
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4167
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4168
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4169
    "Created: 10.6.1996 / 19:07:08 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4170
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4171
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4172
asGrayImageDepth:depth dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4173
    "get a greyscale image, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4174
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4175
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4176
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4177
	^ self asThresholdGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4178
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4179
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4180
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4181
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4182
	^ self asOrderedDitheredGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4183
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4184
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4185
    ^ self asFloydSteinbergDitheredGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4186
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4187
    "Created: 10.6.1996 / 19:08:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4188
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4189
4423
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4190
asImageWithDepth:depth
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4191
    "return a new image with another depth. Notice that this
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4192
     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
  4193
     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
  4194
     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
  4195
     In the other case, use one of the dithering converters"
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4196
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4197
    |imageClass|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4198
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4199
    imageClass := Image implementorForDepth:depth.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4200
    ^ imageClass fromImage:self
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4201
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4202
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4203
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4204
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4205
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4206
     (i asImageWithDepth:24) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4207
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4208
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4209
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4210
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4211
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4212
     (i asImageWithDepth:4) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4213
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4214
!
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4215
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4216
asMonochromeFormOn:aDevice
48194c26a46c Initial revision
claus
parents:
diff changeset
  4217
    "get a monochrome device form"
48194c26a46c Initial revision
claus
parents:
diff changeset
  4218
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4219
    |form|
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4220
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4221
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm].
4390
8d752f4cd9e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  4222
    self depth == 1 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4223
	((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4224
	^ self asFormOn:aDevice
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4225
    ].
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4226
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4227
    form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4228
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4229
    (device isNil or:[aDevice == device]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4230
	"remember this form in the receiver ..."
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4231
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4232
	form notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4233
	    form := form asImageForm.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4234
	    monoDeviceForm := form.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4235
	    device isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4236
		device := aDevice.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4237
		Lobby register:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4238
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4239
		Lobby registerChange:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4240
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4241
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4242
	     can save space, by not keeping the images data-bits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4243
	     twice (here and in the device form)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4244
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4245
	    form forgetBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4246
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4247
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4248
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4249
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4250
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4251
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4252
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4253
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4254
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4255
     (i asMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4256
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4257
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4258
    "Modified: 23.10.1997 / 00:44:59 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4259
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4260
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4261
asMonochromeFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4262
    "get a monochrome device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4263
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4264
    |monoBits|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4265
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4266
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4267
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4268
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4269
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4270
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4271
    aDitherAlgorithm == #burkes ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4272
	monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4273
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4274
	aDitherAlgorithm == #stevensonArce ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4275
	    monoBits := self stevensonArceDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4276
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4277
	    (aDitherAlgorithm == #pattern
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4278
	    or:[aDitherAlgorithm == #ordered]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4279
		^ self asOrderedDitheredGrayFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4280
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4281
		^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4282
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4283
	]
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4284
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4285
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
    "/ make its pixel interpretation correct for the device
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4288
    "/
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4289
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4290
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4291
    "Modified: 10.6.1996 / 20:18:05 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4292
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4293
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4294
asNearestPaintDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4295
    "return a nearest paint pseudoForm from the palette picture.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4296
     Use the colors in the fixColors array.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4297
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4298
     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
  4299
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4300
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4301
    ^ 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
  4302
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4303
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4304
     example:
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4305
	color reduction from Depth8 to Depth4 can be done by:
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4306
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4307
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4308
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4309
     map := #(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4310
		  (0     0   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4311
		  (0     0 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4312
		  (0    50   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4313
		  (0    50 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4314
		  (0   100   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4315
		  (0   100 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4316
		  (100   0   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4317
		  (100   0 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4318
		  (100  50   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4319
		  (100  50 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4320
		  (100 100   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4321
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4322
						      green:(rgb at:2)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4323
						       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4324
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4325
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4326
     form := img8 asNearestPaintDepth8FormOn:Display
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4327
		      colors:map
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4328
			nRed:2
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4329
		      nGreen:3
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4330
		       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4331
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4332
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4333
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4334
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4335
    "Modified: 17.6.1996 / 18:52:47 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4336
    "Created: 23.6.1997 / 15:26:09 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4337
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4338
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4339
asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4340
    "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
  4341
     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
  4342
     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
  4343
     Color class.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4344
     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
  4345
     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
  4346
     for example to create dithered Depth4Images from Depth8Images."
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4347
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4348
    |pseudoBits f deviceDepth map|
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4349
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4350
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4351
    deviceDepth == 8 ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4352
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4353
            ^ nil
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4354
        ]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4355
    ].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4356
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4357
    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
  4358
    pseudoBits isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4359
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4360
    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
  4361
    f isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4362
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4363
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4364
    "/ have to create a funny colorMap, where
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4365
    "/ color at:index == color colorId:index
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4366
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4367
    map := Array new:256.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4368
    fixColors do:[:clr |
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4369
        map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4370
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4371
    f colorMap:map.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4372
    f initGC.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4373
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4374
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4375
        drawBits:pseudoBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4376
        bitsPerPixel:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4377
        depth:deviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4378
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4379
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4380
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4381
        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
  4382
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4383
        with:(f gcId).
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4384
    ^ f
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4385
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4386
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4387
     example:
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4388
        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
  4389
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4390
     |img8 reducedImg8 img4 map form|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4391
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4392
     map := #(
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4393
                  (0     0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4394
                  (0     0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4395
                  (0    50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4396
                  (0    50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4397
                  (0   100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4398
                  (0   100 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4399
                  (100   0   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4400
                  (100   0 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4401
                  (100  50   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4402
                  (100  50 100)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4403
                  (100 100   0)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4404
                  (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
  4405
                                                      green:(rgb at:2)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4406
                                                       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4407
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4408
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4409
     form := img8 asNearestPaintDepth8FormOn:Display
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4410
                      colors:map
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4411
                        nRed:2
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4412
                      nGreen:3
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4413
                       nBlue:2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4414
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4415
     img4 := Depth4Image fromImage:img8.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4416
    "
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4417
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4418
    "Created: 17.6.1996 / 18:47:46 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4419
    "Modified: 17.6.1996 / 18:52:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4420
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4421
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4422
asNearestPaintImageDepth:d colors:colors
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4423
    "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
  4424
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4425
    |newBits|
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4426
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4427
    d ~~ 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  4428
	self error:'unsupported depth'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4429
    ].
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4430
    newBits := self nearestPaintDepth8BitsColors:colors nRed:nil nGreen:nil nBlue:nil.
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4431
    newBits isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  4432
	self error:'conversion failed'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4433
    ].
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4434
    ^ (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
  4435
!
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4436
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4437
asOrderedDitheredGrayFormOn:aDevice
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4438
    "return a dithered depth-x grey form from the receiver image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4439
     Uses an 8x8 dithermatrix."
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4440
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4441
    |depth bits|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4442
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4443
    depth := aDevice depth.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4444
    (depth == 1
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4445
    or:[aDevice hasGrayscales not]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4446
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4447
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4448
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4449
	^ self asOrderedDitheredMonochromeFormOn:aDevice
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4450
    ].
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4451
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4452
    bits := self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4453
		orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4454
		ditherWidth:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4455
		depth:depth.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4456
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4457
    ^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4458
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4459
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4460
     |i|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4461
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4462
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4463
     (i asOrderedDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4464
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4465
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4466
    "Modified: 24.6.1997 / 22:19:30 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4467
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4468
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4469
asOrderedDitheredGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4470
    "return a dithered depth-x grey image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4471
     Uses an 8x8 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4472
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4473
    |dither|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4474
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4475
    dither := self class orderedDitherMatrixOfSize:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4476
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4477
    (depth == 1) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4478
	"/ for monochrome, there is highly specialized
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4479
	"/ monochrome dither code available
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4480
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4481
	^ Depth1Image
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4482
	    width:width
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4483
	    height:height
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4484
	    fromArray:(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4485
		self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4486
		    orderedDitheredMonochromeBitsWithDitherMatrix:dither
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4487
		    ditherWidth:8)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4488
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4489
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4490
    ^ (self class implementorForDepth:depth)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4491
	width:width
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4492
	height:height
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4493
	fromArray:(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4494
	    self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4495
		orderedDitheredGrayBitsWithDitherMatrix:dither
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4496
		ditherWidth:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4497
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4498
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4499
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4500
     |i i1 i2 i4 i8|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4501
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4502
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4503
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4504
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4505
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4506
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4507
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4508
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4509
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4510
     i4 inspect.
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
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4513
     i8 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4514
    "
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
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4517
     |i i1 i2 i4 i8|
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4518
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4519
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4520
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4521
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4522
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4523
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4524
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4525
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4526
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4527
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4528
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4529
     i8 inspect.
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4530
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4531
     i2 := i8 asOrderedDitheredGrayImageDepth:2.
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4532
     i2 inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4533
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4534
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4535
    "Created: 7.6.1996 / 18:03:54 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4536
    "Modified: 24.6.1997 / 22:19:36 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4537
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4538
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4539
asOrderedDitheredMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4540
    "return a dithered monochrome form from the grey image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4541
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4542
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4543
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4544
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4545
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4546
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4547
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4548
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4549
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4550
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4551
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4552
	asOrderedDitheredMonochromeFormOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4553
	ditherMatrix:(self class orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4554
	ditherWidth:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4555
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4556
"/    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4557
"/        asOrderedDitheredMonochromeFormOn:aDevice
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4558
"/        ditherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4559
"/        ditherWidth:8
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
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4563
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4564
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4565
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4566
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4567
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4568
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4569
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4570
     i := (Image fromFile:'goodies/bitmaps/winBitmaps/a11.ico') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4571
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4572
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
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4575
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4576
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4577
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4578
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4579
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4580
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4581
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4582
     i := (Image fromFile:'doc/online/pictures/PasteButton.gif') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4583
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4584
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4585
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4586
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4587
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4588
     i := (Image fromFile:'goodies/bitmaps/gifImages/blue-ball.gif') magnifiedBy:1.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4589
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4590
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4591
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4592
    "Created: 7.6.1996 / 14:52:32 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4593
    "Modified: 17.4.1997 / 01:10:10 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4594
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4595
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4596
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4597
    "return a dithered monochrome form from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4598
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4599
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4600
    |monoBits|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4601
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4602
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4603
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4604
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4605
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4606
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4607
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4608
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4609
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4610
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4611
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4612
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4613
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4614
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4615
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4616
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4617
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4618
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4619
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4620
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4621
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4622
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4623
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4624
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4625
    "Created: 7.6.1996 / 14:51:42 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4626
    "Modified: 17.4.1997 / 01:08:24 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4627
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4628
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4629
asOrderedDitheredMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4630
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4631
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4632
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4633
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4634
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4635
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4636
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4637
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4638
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4639
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4640
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4641
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4642
	asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4643
	ditherWidth:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4644
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4645
"/    ^ self
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4646
"/        asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4647
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4648
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4649
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4650
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4651
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4652
     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
  4653
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4654
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4655
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4656
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4657
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4658
     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
  4659
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4660
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4661
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4662
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4663
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4664
     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
  4665
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4666
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4667
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4668
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4669
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4670
     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
  4671
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4672
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4673
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4674
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4675
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4676
     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
  4677
     i asOrderedDitheredMonochromeImage inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4678
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4679
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4680
    "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
  4681
    "Modified: 10.6.1996 / 11:15:09 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4682
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4683
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4684
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4685
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4686
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4687
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4688
    |monoBits|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4689
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4690
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4691
    ^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4692
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4693
    "order-4 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4694
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4695
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4696
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4697
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4698
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4699
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4700
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4701
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4702
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4703
    "order-6 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4704
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4705
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4706
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4707
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4708
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4709
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4710
	ditherWidth:8
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4711
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4712
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4713
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4714
    "thresholding at:0.5 (all above 0.5 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4715
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4716
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4717
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4718
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4719
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4720
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4721
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4722
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4723
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4724
    "thresholding at: 0.25 (all above 0.25 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4725
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4726
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4727
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4728
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4729
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4730
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4731
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4732
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4733
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4734
    "thresholding at: 0.75 (all above 0.75 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4735
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4736
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4737
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4738
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4739
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4740
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4741
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4742
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4743
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4744
    "Modified: 7.6.1996 / 17:23:47 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4745
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4746
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4747
asPseudoFormQuickOn:aDevice
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4748
    "return a pseudo-deviceForm from the image.
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  4749
     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
  4750
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4751
    |f d
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4752
     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
  4753
     w            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4754
     h            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4755
     dDev         "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4756
     nClr         "{ Class: SmallInteger }"
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4757
     bytesPerLine "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  4758
     usedColors pix fmt bytes|
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4759
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4760
    d := self depth.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4761
    (d == 1
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4762
    or:[d == 2
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4763
    or:[d == 4
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4764
    or:[d == 8]]]) ifFalse:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4765
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  4766
    bytes := self bits.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4767
    w := width.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4768
    h := height.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  4769
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4770
    "/ 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
  4771
    "/ if the padding is not supported: fail
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4772
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4773
    dDev := aDevice depth.
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4774
    (bytesPerLine := dDev) == 8 ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4775
        bytesPerLine := (w * dDev + 7) // 8.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4776
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4777
2532
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
  4778
    fmt := aDevice supportedImageFormatForDepth:dDev.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4779
    fmt isNil ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4780
        "/ cannot draw directly
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4781
        ^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4782
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4783
    (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
  4784
        "/ mhmh - ought to repad here;
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4785
        "/ 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
  4786
        ^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4787
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4788
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4789
    "/ see if all of the images colors are representable
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4790
    "/ on the device
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4791
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4792
    bits := self bitsPerPixel.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4793
    nClr := (1 bitShift:bits).
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4794
    cMap := Array new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4795
    idMap := ByteArray new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4796
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4797
    photometric == #palette ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4798
        nClr := nClr min:(colorMap size)
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4799
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4800
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  4801
    d == 8 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4802
        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
  4803
        1 to:nClr do:[:pixel |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4804
            (usedColors includes:(pixel - 1)) ifFalse:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4805
                clr := Color black
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4806
            ] ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4807
                clr := self colorFromValue:pixel-1.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4808
                clr := clr exactOn:aDevice.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4809
                clr isNil ifTrue:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4810
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4811
            (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
  4812
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4813
            cMap at:(pixel) put:clr.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4814
            idMap at:(pixel) put:pix.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4815
        ].
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  4816
    ] ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4817
        1 to:nClr do:[:pixel |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4818
            clr := self colorFromValue:pixel-1.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4819
            clr := clr exactOn:aDevice.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4820
            clr isNil ifTrue:[^ nil].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4821
            (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
  4822
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4823
            cMap at:(pixel) put:clr.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4824
            idMap at:(pixel) put:pix.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4825
        ].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4826
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4827
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4828
    "/ got all colors; good - simply change depth & translate pixels
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4829
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4830
    (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
  4831
        "/ only translate
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4832
        temp := ByteArray uninitializedNew:(w * h).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4833
        bytes expandPixels:8         "xlate only"
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4834
                    width:w
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4835
                   height:h
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4836
                     into:temp
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4837
                  mapping:idMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4838
    ] ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4839
        "/ 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
  4840
        "/ 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
  4841
        "/ However, those methods are faster
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4842
        "/ - even if we convert twice.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4843
        "/ 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
  4844
        "/ 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
  4845
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4846
        d ~~ 8 ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4847
            temp8 := ByteArray uninitializedNew:(w * h).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4848
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4849
            bytes expandPixels:d
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4850
                         width:w
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4851
                        height:h
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4852
                          into:temp8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4853
                       mapping:idMap.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4854
            idMap := nil.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4855
        ] ifFalse:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4856
            temp8 := bytes.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4857
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4858
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4859
        dDev ~~ 8 ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4860
            temp := ByteArray uninitializedNew:(bytesPerLine * h).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4861
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4862
            temp8 compressPixels:dDev
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4863
                         width:w
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4864
                        height:h
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4865
                          into:temp
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4866
                       mapping:idMap.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4867
        ] ifFalse:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4868
            temp := temp8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4869
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4870
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4871
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4872
    f := Form width:w height:h depth:dDev onDevice:aDevice.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4873
    f isNil ifTrue:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4874
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4875
    f colorMap:cMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4876
    f initGC.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4877
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4878
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4879
        drawBits:temp
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4880
        depth:dDev
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4881
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4882
        width:w
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4883
        height:h
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4884
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4885
        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
  4886
        width:w
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4887
        height:h
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4888
        with:(f gcId).
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4889
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4890
    ^ f
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4891
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4892
    "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4893
     (
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4894
        (((Depth4Image
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4895
             width:4
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4896
             height:4
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4897
             fromArray:#[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4898
                            16r01 16r23
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4899
                            16r45 16r67
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4900
                            16r89 16rab
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4901
                            16rcd 16ref
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4902
                        ]))
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4903
               magnifiedBy:30
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4904
         )
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4905
          asPseudoFormQuickOn:Display
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4906
      ) inspect
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4907
     "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4908
2113
c64f89f9ffba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2102
diff changeset
  4909
    "Modified: / 7.5.1998 / 19:40:47 / cg"
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4910
!
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4911
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4912
asStevensonArceDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4913
    "return a stevenson-arce dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4914
     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
  4915
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4916
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4917
     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
  4918
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4919
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4920
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4921
    monoBits := self stevensonArceDitheredMonochromeBits.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4922
    ^ (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
  4923
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4924
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4925
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4926
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  4927
     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
  4928
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4929
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4930
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4931
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4932
     i asOrderedDitheredMonochromeImage inspect.
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  4933
     (i asThresholdMonochromeImage:0.5) inspect
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4934
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4935
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4936
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4937
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4938
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4939
     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
  4940
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4941
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4942
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4943
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4944
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4945
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4946
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4947
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4948
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4949
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4950
     i := Depth4Image
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  4951
             width:4
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  4952
             height:4
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  4953
             fromArray:#[
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  4954
                            16r01 16r23
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  4955
                            16r45 16r67
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  4956
                            16r89 16rab
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  4957
                            16rcd 16ref
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  4958
                        ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4959
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4960
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4961
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4962
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4963
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4964
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4965
    "Created: 10.6.1996 / 12:38:29 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  4966
    "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
  4967
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4968
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4969
asThresholdGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4970
    "return a thresholded grey form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4971
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4972
    |depth|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4973
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4974
    (depth := aDevice depth) == 1 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4975
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4976
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4977
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4978
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4979
	makeDeviceGrayPixmapOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4980
	depth:depth
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4981
	fromArray:(self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4982
			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
  4983
			ditherWidth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4984
			depth:depth)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4985
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4986
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4987
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4988
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4989
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4990
     (i asThresholdGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4991
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4992
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4993
    "Created: 10.6.1996 / 18:38:31 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4994
    "Modified: 24.6.1997 / 22:19:46 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4995
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4996
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4997
asThresholdGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4998
    "return a thresholded depth-x grey image from the receiver image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4999
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5000
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5001
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5002
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5003
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5004
	^ Depth1Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5005
	    width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5006
	    height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5007
	    fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5008
		self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5009
		    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
  5010
		    ditherWidth:4)
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5011
    ].
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5012
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5013
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5014
	width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5015
	height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5016
	fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5017
	    self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5018
		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
  5019
		ditherWidth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5020
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5021
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5022
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5023
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5024
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5025
     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
  5026
     (i asThresholdGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5027
     (i asThresholdGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5028
     (i asThresholdGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5029
     (i asThresholdGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5030
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5031
     (i asOrderedDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5032
     (i asOrderedDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5033
     (i asOrderedDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5034
     (i asOrderedDitheredGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5035
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5036
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5037
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5038
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5039
     (i asFloydSteinbergDitheredGrayImageDepth:8) inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5040
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5041
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5042
    "Created: 7.6.1996 / 18:13:33 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5043
    "Modified: 24.6.1997 / 22:19:52 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5044
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5045
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5046
asThresholdMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5047
    "return a threshold monochrome form from the image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5048
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5049
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5050
	asOrderedDitheredMonochromeFormOn:aDevice
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5051
	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
  5052
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5053
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5054
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5055
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5056
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5057
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5058
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5059
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5060
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5061
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5062
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5063
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5064
     i := (Image fromFile:'goodies/bitmaps/a11.ico') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5065
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5066
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5067
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5068
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5069
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5070
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5071
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5072
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5073
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5074
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5075
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5076
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5077
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5078
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5079
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5080
     (i asThresholdMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5081
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5082
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5083
    "Created: 7.6.1996 / 16:15:17 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5084
    "Modified: 10.6.1996 / 17:44:29 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5085
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5086
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5087
asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5088
    "return a threshold monochrome image from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5089
     Threshold means: brightness < 0.5 -> black / otherwise white"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5090
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5091
    ^ self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5092
	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
  5093
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5094
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5095
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5096
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5097
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5098
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5099
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5100
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5101
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5102
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5103
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5104
     i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5105
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5106
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5107
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5108
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5109
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5110
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5111
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5112
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5113
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5114
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5115
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5116
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5117
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5118
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5119
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5120
    "Created: 7.6.1996 / 16:15:17 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5121
    "Modified: 7.6.1996 / 17:16:10 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5122
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5123
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5124
asThresholdMonochromeImage:thresholdBrighness
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5125
    "return a threshold monochrome image from the image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5126
     The argument (0..1) gives the threshold value;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5127
     Threshold means: brightness < threshold -> black / otherwise white"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5128
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5129
    |value ditherMatrix|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5130
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5131
    value := thresholdBrighness * 255.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5132
    ditherMatrix := ByteArray new:256 withAll:(value truncated).
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5133
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5134
    ^ self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5135
	asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5136
	ditherWidth:16
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5137
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5138
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5139
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5140
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5141
     i := Image width:4 height:4 depth:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5142
		fromArray:#[ 16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5143
			     16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5144
			     16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5145
			     16rcd 16ref ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5146
     i := i magnifiedBy:30.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5147
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5148
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5149
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5150
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5151
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5152
     (i asThresholdMonochromeImage:1) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5153
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5154
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5155
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5156
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5157
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5158
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5159
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5160
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5161
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5162
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5163
     (i asThresholdMonochromeImage:0.625) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5164
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5165
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5166
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5167
    "Created: 7.6.1996 / 16:15:17 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5168
    "Modified: 8.6.1996 / 14:51:57 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5169
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5170
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5171
clearMaskedPixels
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5172
    "assuming that I already have a device representation
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5173
     in deviceForm, clear any masked pixels.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5174
     This will allow faster drawing in the future."
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5175
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5176
    maskedPixelsAre0 == true ifTrue:[^ self].   "/ already cleared
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5177
    mask isNil ifTrue:[^ self].         "/ no mask
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5178
    deviceForm isNil ifTrue:[^ self].   "/ no device rep.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5179
    mask depth ~~ 1 ifTrue:[^ self].    "/ not done with alpha masks
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5180
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5181
    deviceForm foreground:Color allColor background:Color noColor.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5182
    deviceForm function:#and.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5183
    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
  5184
    maskedPixelsAre0 := true.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5185
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5186
    "Created: 12.4.1997 / 12:18:05 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5187
    "Modified: 12.4.1997 / 12:20:19 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5188
!
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5189
3104
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5190
exactOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5191
    "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
  5192
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5193
    ^ self onDevice:aDevice
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5194
!
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5195
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5196
exactOrNearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5197
    "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
  5198
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5199
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5200
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5201
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5202
fromForm:aForm
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5203
    "setup the receiver from a form"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5204
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5205
    |map c0 c1|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5206
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5207
    width := aForm width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5208
    height := aForm height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5209
    bitsPerSample := self bitsPerSample.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5210
    samplesPerPixel := self samplesPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5211
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5212
    aForm hasBits ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5213
	"/ must read the data from the device
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5214
	self from:aForm in:(0@0 extent:aForm extent).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5215
	^ self
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5216
    ].
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5217
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5218
    "/ the form has all data available
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5219
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5220
    self bits:(aForm bits).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5221
    map := aForm colorMap.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5222
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5223
    aForm depth == 1 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5224
	map isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5225
	    photometric := #whiteIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5226
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5227
	    c0 := map at:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5228
	    c1 := map at:2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5229
	    ((c0 = Color white)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5230
	    and:[c1 = Color black]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5231
		photometric := #whiteIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5232
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5233
		((c0 = Color black)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5234
		and:[c1 = Color white]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5235
		    photometric := #blackIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5236
		] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5237
		    photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5238
		    self setColorMap:(Array with:c0 with:c1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5239
		]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5240
	    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5241
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5242
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5243
	map notNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5244
	    photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5245
	    self setColorMap:(map copy).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5246
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5247
	    "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5248
	     photometric stays at default
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5249
	     (which is rgb for d24, greyscale for others)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5250
	    "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5251
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5252
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5253
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5254
    "Modified: 5.7.1996 / 16:24:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5255
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5256
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5257
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5258
    "setup the receiver from another image.
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5259
     Color precision may be lost, if conversion is from a higher depth image.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5260
     WARNING:
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5261
     This implementation is a slow fallback (the loop over the
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5262
     source pixels is very slow). If this method is used heavily, you
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5263
     may want to redefine it in concrete subclasses for common source images."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5264
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5265
    ^ 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
  5266
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5267
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5268
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5269
    "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
  5270
     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
  5271
     WARNING:
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5272
     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
  5273
     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
  5274
     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
  5275
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5276
    |map clr mappedRowPixels samePhotometric
1784
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5277
     h "{ Class: SmallInteger }"
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5278
     w "{ Class: SmallInteger }"|
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5279
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5280
    width := anImage width.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5281
    height := anImage height.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5282
    bitsPerSample := self bitsPerSample.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5283
    samplesPerPixel := self samplesPerPixel.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5284
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5285
    photometricOrNil isNil ifTrue:[
4893
137719991c5a defaultPhotometric in #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 4888
diff changeset
  5286
        photometric := self class defaultPhotometric
137719991c5a defaultPhotometric in #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 4888
diff changeset
  5287
        "/ photometric := anImage photometric
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5288
    ] ifFalse:[
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5289
        photometric := photometricOrNil
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5290
    ].
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5291
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5292
    photometric == #palette ifTrue:[
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5293
        self colormapFromImage:anImage photometric:photometric.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5294
    ].
1374
ab515c0576c6 preserve mask when creating an image from another image.
Claus Gittinger <cg@exept.de>
parents: 1362
diff changeset
  5295
    self mask:anImage mask.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5296
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5297
    samePhotometric := (photometric == anImage photometric).
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5298
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5299
    ((self depth = anImage depth)
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5300
    and:[samePhotometric]) ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5301
        self bits:(anImage bits copy).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5302
        ^ self.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5303
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5304
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5305
    self bits:(ByteArray uninitializedNew:(self bytesPerRow * height)).
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5306
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5307
    self depth >= anImage depth ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5308
        anImage depth <= 12 ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5309
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5310
            "/ if my depth is greater, all colors can be represented,
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5311
            "/ and the loop can be done over pixel values ...
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5312
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5313
            (colorMap isNil or:[samePhotometric not]) ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5314
                map := Array new:(1 bitShift:anImage depth).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5315
                1 to:map size do:[:i |
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5316
                    clr := anImage colorFromValue:(i - 1).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5317
                    map at:i put:(self valueFromColor:clr).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5318
                ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5319
            ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5320
            mappedRowPixels := self pixelArraySpecies new:width.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5321
            h := height-1.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5322
            w := width.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5323
            0 to:h do:[:row |
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5324
                anImage rowAt:row into:mappedRowPixels startingAt:1.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5325
                map notNil ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5326
                    1 to:w do:[:i |
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5327
                        mappedRowPixels at:i put:(map at:(mappedRowPixels at:i)+1)
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5328
                    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5329
                ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5330
                self rowAt:row putAll:mappedRowPixels
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5331
            ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5332
            ^ self
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5333
        ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5334
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5335
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5336
    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
  5337
        self colorAtX:x y:y put:clr
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5338
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5339
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5340
    "
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5341
     |i i2 i4 i8 i16 i24|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5342
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5343
     i := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5344
     i inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5345
     i2 := Depth2Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5346
     i2 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5347
     i4 := Depth4Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5348
     i4 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5349
     i8 := Depth8Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5350
     i8 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5351
     i24 := Depth24Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5352
     i24 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5353
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5354
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5355
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5356
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5357
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5358
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5359
     Transcript showCR:(
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5360
        Time millisecondsToRun:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5361
            i24 := Depth24Image fromImage:i.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5362
        ]
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5363
     ).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5364
     i24 inspect.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5365
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5366
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5367
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5368
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5369
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5370
     MessageTally spyOn:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5371
        i24 := Depth24Image fromImage:i.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5372
     ]
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5373
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5374
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  5375
    "Modified: / 05-06-2007 / 23:56:52 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5376
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5377
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5378
fromSubImage:anImage in:aRectangle
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5379
    "setup the receiver from another image, extracting a rectangular
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5380
     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
  5381
     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
  5382
     represented.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5383
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5384
     WARNING:
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5385
       This implementation is a slow fallback (the loop over the
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5386
       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
  5387
       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
  5388
       of creating a subImage with the same depth & palette."
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5389
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5390
    |xL yT xR yB maskClass|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5391
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5392
    width := aRectangle width.
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5393
    height := aRectangle height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5394
    self createPixelStore.
3458
b2e098e6288b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3457
diff changeset
  5395
    depth := self depth.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5396
    bitsPerSample := self bitsPerSample.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5397
    bitsPerPixel := self bitsPerPixel.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5398
    samplesPerPixel := self samplesPerPixel.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5399
    self colormapFromImage:anImage.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5400
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5401
    xL := aRectangle left.
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5402
    yT := aRectangle top.
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5403
    xR := xL + aRectangle width - 1.
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5404
    yB := yT + aRectangle height - 1.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5405
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5406
    ((photometric == anImage photometric)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5407
    and:[self bitsPerPixel = anImage bitsPerPixel
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5408
    and:[colorMap = anImage colorMap]]) ifTrue:[
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5409
        "/ can do it by value
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5410
        anImage
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5411
            valuesFromX:xL y:yT toX:xR y:yB
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5412
            do:[:x :y :pixelValue |
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5413
                    self pixelAtX:x-xL y:y-yT put:pixelValue.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5414
               ]
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5415
    ] ifFalse:[
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5416
        "/ must do it by colors
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5417
        anImage
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5418
            colorsFromX:xL y:yT toX:xR y:yB
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5419
            do:[:x :y :clr |
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5420
                    self colorAtX:x-xL y:y-yT put:clr.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5421
               ]
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5422
    ].
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5423
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5424
    anImage mask notNil ifTrue:[
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5425
        anImage mask depth == 1 ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5426
            maskClass := ImageMask
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5427
        ] ifFalse:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5428
            maskClass := anImage mask class.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5429
        ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5430
        mask := maskClass new
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  5431
                    fromSubImage:anImage mask in:aRectangle
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5432
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5433
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5434
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5435
     |i i2 i4 i8 i16 i24|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5436
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5437
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5438
     i inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5439
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5440
     i4 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5441
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5442
     i8 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5443
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5444
     i24 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5445
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5446
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5447
    "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
  5448
    "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
  5449
    "Modified: / 18.5.1999 / 20:06:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5450
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5451
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5452
monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5453
    "return a monochrome device image of the receiver for aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5454
     (monochrome, even if device supports colors)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5455
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5456
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5457
    (device notNil and:[aDevice ~~ device]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5458
	"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
  5459
	 - need a copy ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5460
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5461
	^ self copy monochromeOn:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5462
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5463
    monoDeviceForm := self asMonochromeFormOn:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5464
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5465
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5466
nearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5467
    "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
  5468
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5469
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5470
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5471
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5472
on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5473
    "return an image with the same pixels as the receiver, but
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5474
     associated to aDevice. If the receiver is not yet bound to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5475
     a device, this will be the receiver. Otherwise, a new image
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5476
     is returned."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5477
3623
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5478
    "/ send out a warning: #on: is typically used to create views
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5479
    "/ operating on a model.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5480
    "/ Please use #onDevice: to avoid confusion.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5481
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5482
    <resource:#obsolete>
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5483
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  5484
    self obsoleteMethodWarning:'use #onDevice:'.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5485
    ^ self onDevice:aDevice
1496
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5486
!
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5487
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5488
onDevice:aDevice
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5489
    "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
  5490
     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
  5491
     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
  5492
     is returned."
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  5493
2980
409e9547a45c ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  5494
    aDevice isNil ifTrue:[^ self].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5495
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5496
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5497
    (device notNil and:[aDevice ~~ device]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5498
	"oops, I am already accociated to another device
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5499
	 - need a copy ...
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5500
	"
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5501
	^ self copy onDevice:aDevice
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5502
    ].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5503
    deviceForm := self asFormOn:aDevice.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5504
    maskedPixelsAre0 := nil.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5505
    device := aDevice.
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5506
    Lobby register:self
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5507
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  5508
    "Modified: / 22.8.1998 / 13:34:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5509
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5510
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5511
!Image methodsFor:'converting greyscale images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5512
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5513
greyImageAsFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5514
    "return a grey-deviceForm from the grey image."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5515
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5516
    |pictureDepth nPlanes|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5517
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5518
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5519
    nPlanes := samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5520
    (nPlanes == 2) ifTrue:[
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
  5521
        'Image [info]: alpha plane ignored' infoPrintCR.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  5522
    ].
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  5523
    "/ first plane only
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5524
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5525
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5526
    "monochrome is very easy ..."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5527
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5528
    (pictureDepth == 1) ifTrue:[
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
  5529
        ^ Form width:width height:height fromArray:self bits onDevice:aDevice
283
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
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5532
    (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
  5533
        ^ self greyImageAsTrueColorFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5534
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5535
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5536
    "/ PseudoColor conversion also works for StaticColor,
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5537
    "/ GrayScale and DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5538
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5539
    ^ self greyImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5540
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5541
    "Modified: 19.10.1997 / 05:17:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5542
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5543
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5544
greyImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5545
    "return an 8-bit pseudo Form from the grey image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5546
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5547
    |wideBits pictureDepth f map
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5548
     colorMap usedColors nUsed aColor
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5549
     nColors "{ Class: SmallInteger }"
1766
08b918d293a6 fixed conversion of greyScale images with colorCube
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
  5550
     range id
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5551
     cube nR nG nB grayColors
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5552
     fit|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5553
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5554
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5555
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5556
    (#(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
  5557
        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
  5558
        ^ nil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5559
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5560
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5561
    wideBits := ByteArray uninitializedNew:(width * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5562
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5563
    (pictureDepth == 8) ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5564
        "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
  5565
         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
  5566
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5567
        (grayColors := aDevice fixGrayColors) notNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5568
            DitherAlgorithm == #floydSteinberg ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5569
                f := self
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5570
                       asFloydSteinbergDitheredDepth8FormOn:aDevice
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5571
                       colors:grayColors
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5572
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5573
            f notNil ifTrue:[^ f].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5574
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5575
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5576
        (cube := aDevice fixColors) notNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5577
            nR := aDevice numFixRed.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5578
            nG := aDevice numFixGreen.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5579
            nB := aDevice numFixBlue.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5580
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5581
            DitherAlgorithm == #floydSteinberg ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5582
                f := self
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5583
                       asFloydSteinbergDitheredDepth8FormOn:aDevice
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5584
                       colors:cube
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5585
                       nRed:nR
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5586
                       nGreen:nG
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5587
                       nBlue:nB.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5588
            ] ifFalse:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5589
                f := self
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5590
                       asNearestPaintDepth8FormOn:aDevice
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5591
                       colors:cube
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5592
                       nRed:nR
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5593
                       nGreen:nG
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5594
                       nBlue:nB.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5595
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5596
            f notNil ifTrue:[^ f].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5597
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5598
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5599
        usedColors := self bits usedValues.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5600
        nUsed := usedColors max + 1.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5601
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5602
        colorMap := Array new:nUsed.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5603
        range := 100 / 255.0.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5604
        usedColors do:[:grey |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5605
            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
  5606
        ].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5607
    ] ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5608
        nColors := (1 bitShift:pictureDepth).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5609
        colorMap := Array new:nColors.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5610
        range := 100 / (nColors - 1) asFloat.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5611
        1 to:nColors do:[:i |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5612
            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
  5613
        ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5614
    ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5615
    photometric ~~ #blackIs0 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5616
        colorMap reverse
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5617
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5618
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5619
    "allocate those colors & setup the translation map"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5620
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5621
    fit := true.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5622
    map := ByteArray uninitializedNew:256.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5623
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5624
    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
  5625
        aColor := colorMap at:i.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5626
        aColor notNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5627
            aColor := aColor onDevice:aDevice.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5628
            colorMap at:i put:aColor.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5629
            id := aColor colorId.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5630
            id isNil ifTrue:[
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5631
                id := 0.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5632
                fit := false.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5633
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5634
            map at:i put:id
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5635
        ]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5636
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5637
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5638
    fit ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5639
        "/ 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
  5640
        "/ could not be allocated.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5641
        "/ Must dither.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5642
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5643
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5644
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5645
    "expand & translate"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5646
    self bits
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5647
        expandPixels:pictureDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5648
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5649
        into:wideBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5650
        mapping:map.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5651
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5652
    f := Form width:width height:height depth:8 onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5653
    f isNil ifTrue:[^ nil].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5654
    f colorMap:colorMap.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5655
    f initGC.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5656
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5657
        drawBits:wideBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5658
        depth:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5659
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5660
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5661
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5662
        into:(f id)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5663
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5664
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5665
        with:(f gcId).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5666
    ^ f
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  5667
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  5668
    "Modified: 19.10.1997 / 05:19:44 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5669
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5670
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5671
greyImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5672
    "return a true-color device-form for the grey-image receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5673
     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
  5674
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5675
    |depth
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5676
     myDepth    "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5677
     nColors    "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5678
     colorValues
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5679
     scaleDown
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5680
     scaleRed   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5681
     scaleGreen "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5682
     scaleBlue  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5683
     redShift   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5684
     blueShift  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5685
     greenShift "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5686
     form bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  5687
     greyValue  "{ Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5688
     h          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5689
     w          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5690
     pixelArray newPixelArray i|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5691
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5692
    "/ this is a slow fallback method; this ought to be
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5693
    "/ redefined in DepthxImage for more performance.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5694
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5695
    depth := aDevice depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5696
    myDepth := self depth.
5315
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  5697
    myDepth > 16 ifTrue:[
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  5698
        self error:'unsupported depth'.
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  5699
        ^ nil
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  5700
    ].
5314
517094dfa71c changed #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5313
diff changeset
  5701
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5702
    "/ compute scale to map from my pixels into devices range
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5703
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5704
    scaleDown := 1 bitShift:myDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5705
    scaleRed := (1 bitShift:aDevice bitsRed).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5706
    scaleGreen := (1 bitShift:aDevice bitsGreen).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5707
    scaleBlue := (1 bitShift:aDevice bitsBlue).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5708
    redShift := aDevice shiftRed.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5709
    greenShift := aDevice shiftGreen.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5710
    blueShift := aDevice shiftBlue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5711
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5712
    "/ prepare the map
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  5713
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5714
    nColors := (1 bitShift:myDepth).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5715
    colorValues := Array new:nColors.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5716
    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
  5717
        |v gv bv rv nv|
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5718
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5719
        "/ scale down to 0..1
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5720
        v := (i-1) / scaleDown.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5721
        rv := (v * scaleRed) truncated.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5722
        gv := (v * scaleGreen) truncated.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5723
        bv := (v * scaleBlue) truncated.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5724
        nv := rv bitShift:redShift.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5725
        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
  5726
        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
  5727
        colorValues at:i put:nv
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5728
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5729
    photometric == #whiteIs0 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5730
        "/ 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
  5731
        colorValues reverse
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5732
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5733
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5734
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5735
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  5736
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5737
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5738
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5739
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5740
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  5741
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  5742
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5743
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5744
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5745
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5746
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5747
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5748
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5749
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5750
    w := width - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5751
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5752
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5753
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5754
    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
  5755
        self rowAt:y into:pixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5756
        0 to:w do:[:x |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5757
            greyValue := pixelArray at:(x+1).
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5758
            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
  5759
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5760
        i rowAt:y putAll:newPixelArray.
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
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5763
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5764
    form isNil ifTrue:[^ nil].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5765
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5766
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5767
    form
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5768
        copyBitsFrom:imageBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5769
        bitsPerPixel:usedDeviceBitsPerPixel
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5770
        depth:usedDeviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5771
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5772
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5773
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5774
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5775
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5776
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5777
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5778
    "Created: 20.10.1995 / 22:05:10 / cg"
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  5779
    "Modified: 24.4.1997 / 23:11:16 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5780
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  5781
48194c26a46c Initial revision
claus
parents:
diff changeset
  5782
!Image methodsFor:'converting palette images'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5783
48194c26a46c Initial revision
claus
parents:
diff changeset
  5784
paletteImageAsFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  5785
    "return a device-form for the palette-image receiver"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  5786
380
c5ffc6d48a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
  5787
    |type ddepth|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5788
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5789
    ddepth := aDevice depth.
379
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  5790
3940
b1b7dc76d7d7 not ifTrue -> ifFalse
Claus Gittinger <cg@exept.de>
parents: 3939
diff changeset
  5791
    aDevice hasGrayscales ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5792
	^ self asMonochromeFormOn:aDevice
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5793
    ].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5794
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5795
    ((type := aDevice visualType) == #StaticGray) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5796
	ddepth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5797
	    ^ self paletteImageAsGray8FormOn:aDevice
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5798
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5799
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5800
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5801
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5802
    (type == #TrueColor) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5803
	DitherAlgorithm == #floydSteinberg ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5804
	    ddepth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5805
		self depth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5806
		    "/ use fixColor dither algorithm
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5807
		    ^ self asDitheredTrueColor8FormOn:aDevice
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5808
		]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5809
	    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5810
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5811
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5812
	^ self paletteImageAsTrueColorFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5813
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5814
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5815
    "/ the PseudoColor conversion also works for
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5816
    "/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5817
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5818
    ^ self paletteImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5819
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  5820
    "Modified: 14.6.1996 / 19:31:01 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5821
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5822
48194c26a46c Initial revision
claus
parents:
diff changeset
  5823
paletteImageAsPseudoFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  5824
    "return a pseudo-deviceForm from the palette image."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5825
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5826
    |tempImage d temp8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5827
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5828
    d := self depth.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5829
    (#(1 2 4 8) includes:d) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5830
	"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5831
	 fallback code for some depth's:
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5832
	 create a temporary Depth8Image and use its conversion method
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5833
	"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5834
	temp8 := ByteArray uninitializedNew:(width * height).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5835
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5836
	self bits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5837
	    expandPixels:d
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5838
	    width:width height:height
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5839
	    into:temp8
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5840
	    mapping:nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5841
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5842
	tempImage := Image width:width height:height depth:8 fromArray:temp8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5843
	tempImage colorMap:colorMap.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5844
	^ tempImage paletteImageAsPseudoFormOn:aDevice
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5845
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  5846
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5847
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  5848
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5849
paletteImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5850
    "return a true-color device-form for the palette-image receiver."
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5851
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5852
    |depth
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  5853
     nColors "{ Class: SmallInteger }"
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  5854
     h       "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  5855
     pixel   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5856
     colorValues
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5857
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5858
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5859
     i pixelArray newPixelArray
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5860
     clr r g b rv gv bv v "{ Class: SmallInteger }" |
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5861
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5862
    "/ this is a slow fallback method; this ought to be
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5863
    "/ redefined in DepthxImage for more performance.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5864
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5865
    depth := aDevice depth.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5866
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5867
    bestFormat := self bestSupportedImageFormatFor:aDevice.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5868
    usedDeviceDepth := bestFormat at:#depth.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5869
    usedDeviceDepth == 1 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5870
        ^ self asMonochromeFormOn:aDevice.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5871
    ].
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5872
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5873
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5874
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5875
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5876
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5877
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 255.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5878
    redShift := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5879
    greenShift := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5880
    blueShift := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5881
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5882
    nColors := colorMap size.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5883
    nColors <= 4096 ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5884
        "/ 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
  5885
        "/ (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
  5886
        colorValues := Array uninitializedNew:nColors.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5887
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5888
        1 to:nColors do:[:index |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5889
            r := colorMap redByteAt:index.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5890
            g := colorMap greenByteAt:index.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5891
            b := colorMap blueByteAt:index.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5892
"/        clr := colorMap at:index.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5893
            true "clr notNil" ifTrue:[
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5894
"/            r := clr red.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5895
"/            g := clr green.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5896
"/            b := clr blue.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5897
                rv := (r * scaleRed) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5898
                gv := (g * scaleGreen) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5899
                bv := (b * scaleBlue) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5900
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5901
                v := rv bitShift:redShift.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5902
                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
  5903
                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
  5904
                colorValues at:index put:v.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5905
"/ clr print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5906
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5907
"/ ' -> ' print. v printNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5908
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5909
            ]
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5910
        ].
2864
dd151bfdff9d care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents: 2832
diff changeset
  5911
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5912
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5913
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5914
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5915
1665
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  5916
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  5917
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5918
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5919
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5920
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5921
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5922
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5923
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5924
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5925
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5926
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5927
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5928
    colorValues notNil ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5929
        0 to:h do:[:y |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5930
            self rowAt:y into:pixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5931
            1 to:width do:[:x |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5932
                pixel := pixelArray at:x.
5508
138885192b27 changed: #paletteImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5476
diff changeset
  5933
                newPixelArray at:x put:(colorValues at:pixel + 1 ifAbsent:0).
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5934
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5935
            i rowAt:y putAll:newPixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5936
        ].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  5937
    ] ifFalse:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5938
        0 to:h do:[:y |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5939
            self rowAt:y into:pixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5940
            1 to:width do:[:x |
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5941
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5942
                pixel := pixelArray at:x.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5943
                clr := self colorFromValue:pixel.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5944
                r := clr redByte.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5945
                g := clr greenByte.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5946
                b := clr blueByte.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5947
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5948
                rv := (r * scaleRed) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5949
                gv := (g * scaleGreen) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5950
                bv := (b * scaleBlue) rounded.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5951
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5952
                v := rv bitShift:redShift.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5953
                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
  5954
                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
  5955
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5956
                newPixelArray at:x put:v.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5957
            ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5958
            i rowAt:y putAll:newPixelArray.
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5959
        ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5960
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5961
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5962
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5963
    form isNil ifTrue:[^ nil].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5964
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5965
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5966
    form
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5967
        copyBitsFrom:imageBits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5968
        bitsPerPixel:usedDeviceBitsPerPixel
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5969
        depth:usedDeviceDepth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5970
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5971
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5972
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5973
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5974
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5975
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  5976
2185
756d58c52113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2182
diff changeset
  5977
    "Modified: / 24.7.1998 / 00:56:14 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  5978
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  5979
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5980
!Image methodsFor:'converting rgb images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5981
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5982
asDitheredTrueColor8FormOn:aDevice
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5983
    "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
  5984
     Return the device-form.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  5985
     This method is only valid for trueColor displays."
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5986
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5987
    |fixColors pixel
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5988
     dstIdx     "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5989
     shiftRed   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5990
     shiftGreen "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5991
     shiftBlue  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5992
     nRed    "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5993
     nGreen  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5994
     nBlue   "{ Class: SmallInteger }"|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5995
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5996
    shiftRed := aDevice shiftRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5997
    shiftGreen := aDevice shiftGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5998
    shiftBlue := aDevice shiftBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  5999
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6000
    nRed := (1 bitShift:aDevice bitsRed).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6001
    nGreen := (1 bitShift:aDevice bitsGreen).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6002
    nBlue := (1 bitShift:aDevice bitsBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6003
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6004
    fixColors := Array new:(nRed * nGreen * nBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6005
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6006
    dstIdx := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6007
    0 to:nRed - 1 do:[:sR |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6008
	0 to:nGreen - 1 do:[:sG |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6009
	    0 to:nBlue - 1 do:[:sB |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6010
		pixel := (sR bitShift:shiftRed)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6011
			 + (sG bitShift:shiftGreen)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6012
			 + (sB bitShift:shiftBlue).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6013
		fixColors at:dstIdx put:(Color colorId:(pixel)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6014
		dstIdx := dstIdx + 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6015
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6016
	]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6017
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6018
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6019
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6020
	asFloydSteinbergDitheredDepth8FormOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6021
	colors:fixColors
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6022
	nRed:nRed nGreen:nGreen nBlue:nBlue
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6023
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6024
    "Created: 14.6.1996 / 17:23:52 / cg"
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6025
    "Modified: 23.6.1997 / 15:22:36 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6026
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6027
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6028
rgbImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6029
    "convert am rgb image to a device-form on aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6030
     Return the device-form."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6031
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6032
    |visual|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6033
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6034
    visual := aDevice visualType.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6035
    (visual == #StaticGray) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6036
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6037
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6038
    (visual == #TrueColor) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6039
	^ self rgbImageAsTrueColorFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6040
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6041
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6042
    "/ PseudoColor conversion also works for StaticColor, GrayScale
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6043
    "/ and DirectColor displays; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6044
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6045
    ^ self rgbImageAsPseudoFormOn:aDevice
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6046
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6047
    "Modified: 14.6.1996 / 19:30:06 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6048
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6049
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6050
rgbImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6051
    "return a pseudocolor form from the rgb-picture"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6052
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6053
    |n     "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6054
     depth "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6055
     palette f|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6056
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6057
    (depth := self depth) <= 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6058
	"/ simulate it via a temporary palette image
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6059
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6060
	palette := Array new:(1 bitShift:depth).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6061
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6062
	n := (1 bitShift:depth)-1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6063
	0 to:n do:[:pixelValue |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6064
	    palette at:(pixelValue+1) put:(self colorFromValue:pixelValue)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6065
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6066
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6067
	self setColorMap:palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6068
	photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6069
	f := self paletteImageAsPseudoFormOn:aDevice.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6070
	self setColorMap:nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6071
	photometric := #rgb.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6072
	^ f
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6073
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6074
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6075
    ^ self subclassResponsibility
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6076
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6077
    "Modified: 8.6.1996 / 10:58:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6078
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6079
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6080
rgbImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6081
    "return a truecolor form from the rgb-picture."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6082
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6083
    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6084
     form|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6085
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6086
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6087
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6088
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6089
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6090
    "/ 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
  6091
    usedDeviceBitsPerPixel == 15 ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6092
        usedDeviceBitsPerPixel := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  6093
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  6094
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6095
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6096
    "/ only the trivial case, where the depths match
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6097
    "/ is handled here; conversions are supposed to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6098
    "/ be done in concrete subclasses (see D24Image)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6099
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6100
    self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  6101
        "/ kludge - convert to a deep image first, then to a form.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  6102
        ^ ((Image implementorForDepth:usedDeviceBitsPerPixel) fromImage:self) asFormOn:aDevice
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  6103
"/        'Image [warning]: unimplemented trueColor depth in rgbImageAsTrueColorFormOn: ' errorPrint. self bitsPerPixel errorPrintCR.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  6104
"/        ^ self asMonochromeFormOn:aDevice
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6105
    ].
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6106
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6107
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6108
    form isNil ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6109
        'Image [warning]: display bitmap creation failed' errorPrintCR.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6110
        ^ nil
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6111
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6112
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6113
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6114
    form
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6115
        copyBitsFrom:self bits
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6116
        bitsPerPixel:usedDeviceBitsPerPixel
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6117
        depth:usedDeviceDepth
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6118
        padding:8
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6119
        width:width height:height
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6120
        x:0 y:0
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6121
        toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6122
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6123
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6124
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6125
    "Modified: / 27-05-2007 / 13:44:26 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6126
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6127
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6128
!Image methodsFor:'copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6129
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6130
postCopy
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6131
    "redefined to also copy the pixels and the colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6132
     and clear out any device handles in the copy."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6133
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6134
    bytes := bytes copy.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6135
    (colorMap isNil or:[colorMap isKindOf:Colormap]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6136
	colorMap := MappedPalette withColors:colorMap.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6137
    ] ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6138
	colorMap := colorMap copy.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6139
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6140
    device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil.
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6141
    mask := mask copy.
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6142
    maskedPixelsAre0 := false.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6143
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6144
    "Modified: / 22.8.1998 / 11:27:09 / cg"
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6145
!
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6146
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6147
skipInstvarIndexInDeepCopy:index
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6148
    "a helper for deepCopy; only indices for which this method returns
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6149
     false are copied in a deep copy."
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6150
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6151
    index == 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6152
	^ true "/ skip device
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6153
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6154
    index == 13 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6155
	^ true "/ skip deviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6156
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6157
    index == 14 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6158
	^ true "/ skip monoDeviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6159
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6160
    index == 15 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6161
	^ true "/ skip fullColorDeviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6162
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6163
    ^ false
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6164
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6165
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6166
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6167
!Image methodsFor:'displaying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6168
1737
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6169
asImage
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6170
    "ST-80 compatibility
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6171
    "
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6172
    ^ self
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6173
!
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6174
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6175
displayFilledOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6176
    "display the receiver as an opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6177
     This allows Images to be wrapped by a FillingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6178
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6179
    aGC displayOpaqueForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6180
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6181
    "Created: 29.5.1996 / 10:34:18 / cg"
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6182
    "Modified: 29.5.1996 / 10:52:36 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6183
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6184
3865
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6185
displayOn:aGC x:x y:y
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6186
    "draw the receiver in the graphicsContext, aGC.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6187
     Smalltalk-80 compatibility"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6188
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6189
    aGC displayForm:self x:x y:y.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6190
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6191
    "Modified: 23.4.1996 / 11:12:31 / cg"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6192
    "Created: 12.5.1996 / 20:14:31 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6193
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6194
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6195
displayOn:aGC x:x y:y opaque:opaque
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6196
    "draw the receiver in the graphicsContext, aGC.
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6197
     Smalltalk-80 compatibility"
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6198
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6199
    opaque ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6200
	self displayOpaqueOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6201
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6202
	self displayOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6203
    ].
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6204
!
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6205
3379
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6206
displayOpaqueOn:aGC at:aPoint
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6207
    "draw the receiver in the graphicsContext, aGC.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6208
     Smalltalk-80 compatibility"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6209
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6210
    self displayOpaqueOn:aGC x:aPoint x y:aPoint y.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6211
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6212
    "Modified: 12.5.1996 / 20:16:38 / cg"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6213
!
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6214
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6215
displayOpaqueOn:aGC x:x y:y
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6216
    "draw the receiver in the graphicsContext, aGC.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6217
     Smalltalk-80 compatibility"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6218
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6219
    aGC displayOpaqueForm:self x:x y:y.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6220
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6221
    "Modified: 23.4.1996 / 11:12:31 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6222
    "Created: 22.10.1996 / 16:35:49 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6223
!
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6224
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6225
displayStrokedOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6226
    "display the receiver as an non opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6227
     This allows Images to be wrapped by a StrokingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6228
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6229
    aGC displayForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6230
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6231
    "Created: 29.5.1996 / 10:34:18 / cg"
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6232
    "Modified: 29.5.1996 / 10:52:30 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6233
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6234
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6235
!Image methodsFor:'dither helpers'!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6236
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6237
burkesDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6238
    "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
  6239
     Works for any source depths / photometric"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6240
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6241
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6242
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6243
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6244
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6245
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6246
     errorArray1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6247
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6248
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6249
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6250
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6251
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6252
     grey|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6253
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6254
    self depth > 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6255
	^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6256
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6257
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6258
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6259
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6260
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6261
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6262
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6263
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6264
    errorArray := Array new:(w+4).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6265
    errorArray1 := Array new:(w+4) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6266
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6267
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6268
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6269
    "/ 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
  6270
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6271
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6272
    greyValues := self greyMapForRange:(255*1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6273
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6274
    0 to:(h-1) do:[:y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6275
	nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6276
	byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6277
	bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6278
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6279
	t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6280
	errorArray := errorArray1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6281
	errorArray1 := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6282
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6283
	errorArray1 atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6284
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6285
	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
  6286
	    |eP "{Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6287
	     eD
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6288
	     eI "{Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6289
	     xE "{Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6290
	     xN "{Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6291
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6292
	    "/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6293
	    grey := greyValues at:(pixel + 1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6294
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6295
	    "/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6296
	    xE := x + 2 + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6297
	    grey := (grey + (errorArray at:xE)).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6298
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6299
	    byte := byte bitShift:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6300
	    grey > (127*1024) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6301
		byte := byte bitOr:1.      "/ white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6302
		e := grey - (255*1024)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6303
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6304
		e := grey                  "/ black
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6305
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6306
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6307
	    e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6308
		"/ distribute the error:
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6309
		"/                  XX  8  4
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6310
		"/             2  4  8  4  2
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6311
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6312
		eD := e.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6313
		eI := e // 32.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6314
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6315
		eP := eI * 8. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6316
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6317
		xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6318
		errorArray at:xN put:(errorArray at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6319
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6320
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6321
		errorArray1 at:xE put:(errorArray1 at:xE) + eP.
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
		eP := eI * 4. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6324
		xN := xE + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6325
		errorArray at:xN put:(errorArray at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6326
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6327
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6328
		xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6329
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6330
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6331
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6332
		xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6333
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6334
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6335
		eP := eI * 2. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6336
		xN := xE - 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6337
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6338
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6339
		"/ eD := eD.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6340
		xN := xE + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6341
		errorArray1 at:xN put:(errorArray1 at:xN) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6342
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6343
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6344
	    bitCnt := bitCnt - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6345
	    bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6346
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6347
		dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6348
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6349
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6350
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6351
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6352
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6353
	bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6354
	    byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6355
	    monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6356
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6357
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6358
	dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6359
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6360
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6361
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6362
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6363
    "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
  6364
    "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
  6365
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6366
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6367
floydSteinbergDitheredDepth8BitsColors:colors
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6368
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6369
     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
  6370
     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
  6371
     (which need not be a colorCubes colors)."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6372
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6373
    ^ self floydSteinbergDitheredDepth8BitsColors:colors map:nil
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6374
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6375
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6376
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6377
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6378
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6379
     which must be a depth-24 image.
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6380
     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
  6381
     (which need not be a colorCubes colors)."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6382
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6383
    |pseudoBits
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6384
     ditherRGBBytes ditherColors
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6385
     w       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6386
     h       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6387
     index   "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6388
     ditherIds failed lastColor qScramble
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6389
     clrLookup lookupPos
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6390
     error clr|
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6391
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6392
    self depth ~~ 24 ifTrue:[^ nil].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6393
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6394
    "/ collect valid ditherColors ...
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6395
    aMapOrNil isNil ifTrue:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6396
        ditherColors := colors select:[:clr | clr notNil].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6397
    ] ifFalse:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6398
        ditherColors := colors
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6399
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6400
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6401
    "/ ... and sort by manhatten distance from black
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6402
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6403
    qScramble := #(
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6404
                "/  2rX00X00X00X00
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6405
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6406
                    2r000000000000    "/ 0
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6407
                    2r000000000100    "/ 1
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6408
                    2r000000100000    "/ 2
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6409
                    2r000000100100    "/ 3
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6410
                    2r000100000000    "/ 4
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6411
                    2r000100000100    "/ 5
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6412
                    2r000100100000    "/ 6
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6413
                    2r000100100100    "/ 7
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6414
                    2r100000000000    "/ 8
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6415
                    2r100000000100    "/ 9
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6416
                    2r100000100000    "/ a
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6417
                    2r100000100100    "/ b
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6418
                    2r100100000000    "/ c
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6419
                    2r100100000100    "/ d
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6420
                    2r100100100000    "/ e
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6421
                    2r100100100100    "/ f
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6422
                  ).
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6423
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6424
    ditherColors := ditherColors sort:[:a :b |
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6425
                                |cr "{Class: SmallInteger }"
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6426
                                 cg "{Class: SmallInteger }"
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6427
                                 cb "{Class: SmallInteger }"
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6428
                                 i1 "{Class: SmallInteger }"
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6429
                                 i2 "{Class: SmallInteger }"|
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6430
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6431
                                cr := a redByte.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6432
                                cg := a greenByte.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6433
                                cb := a blueByte.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6434
                                i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6435
                                i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6436
                                i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6437
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6438
                                cr := b redByte.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6439
                                cg := b greenByte.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6440
                                cb := b blueByte.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6441
                                i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6442
                                i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6443
                                i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6444
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6445
                                i1 < i2
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6446
                    ].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6447
    aMapOrNil isNil ifTrue:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6448
        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
  6449
    ] ifFalse:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6450
        ditherIds := aMapOrNil asByteArray
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6451
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6452
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6453
    "/ 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
  6454
    "/ to the position in the colorList
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6455
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6456
    clrLookup := ByteArray new:(4096).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6457
    index := 0.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6458
    ditherColors keysAndValuesDo:[:clrPosition :clr |
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6459
        |r g b i|
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6460
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6461
        r := clr redByte.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6462
        g := clr greenByte.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6463
        b := clr blueByte.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6464
        i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6465
        i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6466
        i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6467
        lookupPos := i.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6468
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6469
        [index < lookupPos] whileTrue:[
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6470
            clrLookup at:(index+1) put:(clrPosition-1-1).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6471
            index := index + 1
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6472
        ]
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6473
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6474
    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
  6475
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6476
"/    [index <= (4095)] whileTrue:[
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6477
"/        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
  6478
"/        index := index + 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6479
"/    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6480
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6481
    "/ collect ditherColor components
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6482
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6483
    lastColor := ditherColors size.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6484
    ditherIds := ByteArray uninitializedNew:lastColor.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6485
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6486
    index := 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6487
    1 to:lastColor do:[:pix |
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6488
        clr := ditherColors at:pix.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6489
        ditherRGBBytes at:index put:(clr redByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6490
        ditherRGBBytes at:index+1 put:(clr greenByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6491
        ditherRGBBytes at:index+2 put:(clr blueByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6492
        aMapOrNil isNil ifTrue:[
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6493
            ditherIds at:pix put:clr colorId.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6494
        ] ifFalse:[
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6495
            ditherIds at:pix put:(aMapOrNil at:pix).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6496
        ].
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6497
        index := index + 3.
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6498
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6499
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6500
    pseudoBits := ByteArray uninitializedNew:(width * height).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6501
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6502
    w := width + 2.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6503
    error := ByteArray uninitializedNew:w*(3*2).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6504
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6505
    w := width.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6506
    h := height.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6507
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6508
    failed := true.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6509
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6510
%{
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6511
    int __x, __y;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6512
    int __eR, __eG, __eB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6513
    unsigned char *srcP, *dstP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6514
    unsigned char *idP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6515
    unsigned char *dp;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6516
    unsigned char *__clrLookup;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6517
    short *errP, *eP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6518
    int __fR, __fG, __fB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6519
    int iR, iG, iB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6520
    int idx;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6521
    int __w = __intVal(w);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6522
    int __h = __intVal(h);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6523
    int __nColors = __intVal(lastColor);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6524
    int __wR = -1, __wG, __wB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6525
    static int __qScramble[16] = {
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6526
                    0x000 /* 2r000000000000    0 */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6527
                    0x004 /* 2r000000000100    1 */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6528
                    0x020 /* 2r000000100000    2 */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6529
                    0x024 /* 2r000000100100    3 */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6530
                    0x100 /* 2r000100000000    4 */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6531
                    0x104 /* 2r000100000100    5 */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6532
                    0x120 /* 2r000100100000    6 */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6533
                    0x124 /* 2r000100100100    7 */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6534
                    0x800 /* 2r100000000000    8 */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6535
                    0x804 /* 2r100000000100    9 */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6536
                    0x820 /* 2r100000100000    a */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6537
                    0x824 /* 2r100000100100    b */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6538
                    0x900 /* 2r100100000000    c */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6539
                    0x904 /* 2r100100000100    d */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6540
                    0x920 /* 2r100100100000    e */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6541
                    0x924 /* 2r100100100100    f */,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6542
                  };
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6543
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6544
    if (__isByteArrayLike(__INST(bytes))
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6545
     && __isByteArray(pseudoBits)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6546
     && __isByteArray(ditherRGBBytes)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6547
     && __isByteArray(ditherIds)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6548
     && __isByteArray(clrLookup)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6549
     && __isByteArray(error)) {
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6550
        failed = false;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6551
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6552
        srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6553
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6554
        idP = __ByteArrayInstPtr(ditherIds)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6555
        __clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6556
        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6557
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6558
        /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6559
         * clear error accumulator
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6560
         */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6561
        eP = errP;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6562
        bzero(eP, (__w+2) * 2 * 3);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6563
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6564
        for (__y=__h; __y>0; __y--) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6565
            __eR = __eG = __eB = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6566
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6567
            eP = &(errP[3]);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6568
            __eR = eP[0];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6569
            __eG = eP[1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6570
            __eB = eP[2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6571
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6572
            for (__x=__w; __x>0; __x--) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6573
                int __want;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6574
                int pix;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6575
                int __wantR, __wantG, __wantB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6576
                int idx;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6577
                int tR, tG, tB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6578
                int nR, nG, nB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6579
                int dR, dG, dB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6580
                int minDelta, bestIdx;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6581
                int cnt;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6582
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6583
                __wantR = *srcP++;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6584
                __wantG = *srcP++;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6585
                __wantB = *srcP++;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6586
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6587
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6588
                 * wR, wG and wB is the wanted r/g/b value;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6589
                 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6590
                __wantR = __wantR + __eR;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6591
                __wantG = __wantG + __eG;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6592
                __wantB = __wantB + __eB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6593
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6594
#define RED_SCALE 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6595
#define GREEN_SCALE 59
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6596
#define BLUE_SCALE 11
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6597
#define GOOD_DELTA 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6598
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6599
#define xRED_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6600
#define xGREEN_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6601
#define xBLUE_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6602
#define xGOOD_DELTA 3
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
#define FAST_LOOKUP
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6605
/* #define ONE_SHOT */
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6606
#define NPROBE 8
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6607
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6608
#ifndef FAST_LOOKUP
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6609
                if ((__wantR == __wR)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6610
                 && (__wantG == __wG)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6611
                 && (__wantB == __wB)) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6612
                    /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6613
                     * same color again - reuse last bestMatch
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6614
                     */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6615
                } else
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6616
#endif
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6617
                {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6618
                    __wR = __wantR;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6619
                    __wG = __wantG;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6620
                    __wB = __wantB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6621
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6622
#ifdef FAST_LOOKUP
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6623
                    if(__wR > 255) __wR = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6624
                    else if (__wR < 0) __wR = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6625
                    if(__wG > 255) __wG = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6626
                    else if (__wG < 0) __wG = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6627
                    if(__wB > 255) __wB = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6628
                    else if (__wB < 0) __wB = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6629
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6630
                    {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6631
                        int lookupIndex;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6632
                        int idx, idx0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6633
                        int d, delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6634
                        unsigned char *dp0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6635
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6636
                        dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6637
                        lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6638
                        lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6639
                        lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6640
                        idx = bestIdx =__clrLookup[lookupIndex];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6641
                        dp += (idx+idx+idx);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6642
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6643
                        /* try color at lookupIndex */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6644
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6645
                        d = dp[0];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6646
                        delta = (__wR - d) * RED_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6647
                        if (delta < 0) delta = -delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6648
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6649
                        d = dp[1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6650
                        if (__wG > d)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6651
                            delta += (__wG - d) * GREEN_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6652
                        else
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6653
                            delta += (d - __wG) * GREEN_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6654
                        d = dp[2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6655
                        if (__wB > d)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6656
                            delta += (__wB - d) * BLUE_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6657
                        else
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6658
                            delta += (d - __wB) * BLUE_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6659
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6660
                        if (delta <= GOOD_DELTA) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6661
                            goto foundBest;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6662
                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6663
                        minDelta = delta;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6664
# ifndef ONE_SHOT
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6665
                        idx0 = idx; dp0 = dp;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6666
                        cnt = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6667
                        while ((++cnt <= NPROBE) && (idx > 0)) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6668
                            /* try previous color(s) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6669
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6670
                            idx--; dp -= 3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6671
                            d = dp[0];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6672
                            delta = (__wR - d) * RED_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6673
                            if (delta < 0) delta = -delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6674
                            d = dp[1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6675
                            if (__wG > d)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6676
                                delta += (__wG - d) * GREEN_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6677
                            else
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6678
                                delta += (d - __wG) * GREEN_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6679
                            d = dp[2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6680
                            if (__wB > d)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6681
                                delta += (__wB - d) * BLUE_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6682
                            else
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6683
                                delta += (d - __wB) * BLUE_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6684
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6685
                            if (delta < minDelta) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6686
                                bestIdx = idx;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6687
                                if (delta <= GOOD_DELTA) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6688
                                    goto foundBest;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6689
                                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6690
                                minDelta = delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6691
                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6692
                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6693
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6694
                        idx = idx0; dp = dp0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6695
                        cnt = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6696
                        while ((++cnt <= NPROBE) && (++idx < __nColors)) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6697
                            /* try next color */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6698
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6699
                            dp += 3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6700
                            d = dp[0];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6701
                            delta = (__wR - d) * RED_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6702
                            if (delta < 0) delta = -delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6703
                            d = dp[1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6704
                            if (__wG > d)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6705
                                delta += (__wG - d) * GREEN_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6706
                            else
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6707
                                delta += (d - __wG) * GREEN_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6708
                            d = dp[2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6709
                            if (__wB > d)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6710
                                delta += (__wB - d) * BLUE_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6711
                            else
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6712
                                delta += (d - __wB) * BLUE_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6713
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6714
                            if (delta < minDelta) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6715
                                bestIdx = idx;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6716
                                if (delta <= GOOD_DELTA) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6717
                                    goto foundBest;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6718
                                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6719
                                minDelta = delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6720
                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6721
                        }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6722
# endif
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6723
                    }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6724
        foundBest: ;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6725
#else
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6726
/*
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6727
                    if(__wR > 255) __wR = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6728
                    else if (__wR < 0) __wR = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6729
                    if(__wG > 255) __wG = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6730
                    else if (__wG < 0) __wG = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6731
                    if(__wB > 255) __wB = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6732
                    else if (__wB < 0) __wB = 0;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6733
*/
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6734
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6735
                    /* find the best matching color */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6736
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6737
                    minDelta = 99999;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6738
                    bestIdx = -1;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6739
                    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6740
                    for (idx = 0; idx<__nColors; idx++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6741
                        int d, delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6742
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6743
                        d = dp[0];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6744
                        delta = (__wR - d) * RED_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6745
                        if (delta < 0) delta = -delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6746
                        if (delta < minDelta) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6747
                            d = dp[1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6748
                            if (__wG > d)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6749
                                delta += (__wG - d) * GREEN_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6750
                            else
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6751
                                delta += (d - __wG) * GREEN_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6752
                            if (delta < minDelta) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6753
                                d = dp[2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6754
                                if (__wB > d)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6755
                                    delta += (__wB - d) * BLUE_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6756
                                else
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6757
                                    delta += (d - __wB) * BLUE_SCALE;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6758
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6759
                                if (delta < minDelta) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6760
                                    bestIdx = idx;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6761
                                    if (delta <= GOOD_DELTA) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6762
                                        break;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6763
                                    }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6764
                                    minDelta = delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6765
                                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6766
                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6767
                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6768
                        dp += 3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6769
                    }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6770
#endif
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6771
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6772
                dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6773
                dp += bestIdx * 3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6774
                dR = dp[0];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6775
                dG = dp[1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6776
                dB = dp[2];
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6777
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6778
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  6779
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6780
                __wantR, __wantG, __wantB,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6781
                __wR, __wG, __wB,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6782
                dR, dG, dB);
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6783
*/
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6784
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6785
                 * store the corresponding dither colors colorId
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6786
                 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6787
                *dstP++ = idP[bestIdx];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6788
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6789
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6790
                 * the new error & distribute the error
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6791
                 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6792
                __eR = __wantR - dR;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6793
                if (__eR) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6794
                    tR = __eR >> 4;  /* 16th of error */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6795
                    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6796
                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6797
                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6798
                    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6799
                    __eR = nR;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6800
                } else {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6801
                    __eR = eP[3];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6802
                    eP[0] = eP[-3] = eP[3] = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6803
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6804
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6805
                __eG = __wantG - dG;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6806
                if (__eG) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6807
                    tG = __eG >> 4;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6808
                    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6809
                    eP[1] = tG*5;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6810
                    eP[-2] = tG*3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6811
                    eP[4] = __eG - (tG*15);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6812
                    __eG = nG;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6813
                } else {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6814
                    __eG = eP[4];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6815
                    eP[1] = eP[-2] = eP[4] = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6816
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6817
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6818
                __eB = __wantB - dB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6819
                if (__eB) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6820
                    tB = __eB >> 4;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6821
                    nB = eP[5] + (tB * 7);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6822
                    eP[2] = tB*5;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6823
                    eP[-1] = tB*3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6824
                    eP[5] = __eB - (tB*15);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6825
                    __eB = nB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6826
                } else {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6827
                    __eB = eP[5];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6828
                    eP[2] = eP[-1] = eP[5] = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6829
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6830
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6831
                eP += 3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6832
            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6833
        }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6834
    }
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6835
%}.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6836
    failed ifTrue:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6837
        self primitiveFailed.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6838
        ^ nil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6839
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6840
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6841
    ^ pseudoBits
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6842
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6843
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6844
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6845
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6846
     which must be a depth-8 image.
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6847
     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
  6848
     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
  6849
     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
  6850
     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
  6851
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6852
     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
  6853
     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
  6854
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6855
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6856
    |pseudoBits
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6857
     rgbBytes
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6858
     w       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6859
     h       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6860
     index   "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6861
     fixR    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6862
     fixG    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6863
     fixB    "{Class: SmallInteger }"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6864
     fixGfixB
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6865
     fixIds failed map lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6866
     rgbIDX  "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6867
     idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6868
     error clr|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6869
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6870
    self depth ~~ 8 ifTrue:[^ nil].
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6871
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6872
    fixR := nRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6873
    fixR == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6874
    fixG := nGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6875
    fixG == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6876
    fixB := nBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6877
    fixB == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6878
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6879
    "/ simple check
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6880
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6881
        self error:'invalid color array passed'.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6882
        ^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6883
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6884
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6885
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6886
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6887
    "/ collect color components as integer values (for integer arithmetic)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6888
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6889
    rgbBytes := ByteArray uninitializedNew:256 * 3.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6890
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6891
    index := 1.
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
    photometric == #palette ifTrue:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6894
        lastColor := colorMap size - 1
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6895
    ] ifFalse:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6896
        lastColor := 255.
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
    0 to:lastColor do:[:pix |
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6899
        clr := self colorFromValue:pix.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6900
        rgbBytes at:index put:(clr redByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6901
        rgbBytes at:index+1 put:(clr greenByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6902
        rgbBytes at:index+2 put:(clr blueByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6903
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6904
        index := index + 3.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6905
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6906
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6907
    pseudoBits := ByteArray uninitializedNew:(width * height).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6908
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6909
    w := width + 2.
1636
c30f6644666e dont use bcopy in #floydSteinbergDitheredDepth8BitsColors
Claus Gittinger <cg@exept.de>
parents: 1630
diff changeset
  6910
    error := ByteArray new:w*(3*2).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6911
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6912
    w := width.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6913
    h := height.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6914
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6915
    idxAndErrRBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6916
    idxAndErrGBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6917
    idxAndErrBBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6918
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6919
    fixGfixB := fixG * fixB.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6920
    index := 1.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6921
    0 to:255 do:[:i |
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6922
        rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded"
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6923
        idxAndErrRBytes at:index put:(rgbIDX * fixGfixB).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6924
        idxAndErrRBytes at:index+1 put:i - (rgbIDX * 255 // (fixR-1)) + 128.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6925
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6926
        rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded"
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6927
        idxAndErrGBytes at:index put:(rgbIDX * fixB).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6928
        idxAndErrGBytes at:index+1 put:i - (rgbIDX * 255 // (fixG-1)) + 128.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6929
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6930
        rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded"
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6931
        idxAndErrBBytes at:index put:(rgbIDX ).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6932
        idxAndErrBBytes at:index+1 put:i - (rgbIDX * 255 // (fixB-1)) + 128.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6933
        index := index + 2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6934
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6935
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6936
    failed := true.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6937
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6938
%{
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6939
    int __x, __y;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6940
    int __eR, __eG, __eB;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6941
    unsigned char *srcP, *dstP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6942
    unsigned char *rgbP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6943
    unsigned char *idP;
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  6944
    unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes;
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6945
    short *errP, *eP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6946
    int idx;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6947
    int __w = __intVal(w);
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6948
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6949
    if (__isByteArrayLike(__INST(bytes))
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6950
     && __isByteArray(pseudoBits)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6951
     && __isByteArray(rgbBytes)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6952
     && __isByteArray(fixIds)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6953
     && __isByteArray(error)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6954
     && __bothSmallInteger(fixR, fixG)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6955
     && __isSmallInteger(fixB)) {
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6956
        failed = false;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6957
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6958
        srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6959
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6960
        rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6961
        idP = __ByteArrayInstPtr(fixIds)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6962
        __idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6963
        __idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6964
        __idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6965
        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6966
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6967
        eP = errP;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6968
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6969
        for (__y=__intVal(h); __y>0; __y--) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6970
            __eR = __eG = __eB = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6971
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6972
            eP = &(errP[3]);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6973
            __eR = eP[0];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6974
            __eG = eP[1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6975
            __eB = eP[2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6976
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6977
            for (__x=__w; __x>0; __x--) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6978
                int __want;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6979
                int pix;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6980
                int idx;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6981
                int tR, tG, tB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6982
                int nR, nG, nB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6983
                int iRGB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6984
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6985
                pix = *srcP++;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6986
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6987
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6988
                 * wR, wG and wB is the wanted r/g/b value;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6989
                 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6990
                pix = pix+pix+pix;  /* pix * 3 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6991
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6992
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6993
                 * compute indexR/G/B and the new error:
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6994
                 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6995
                __want = rgbP[pix]   + __eR;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6996
                if (__want > 255) __want = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6997
                else if (__want < 0) __want = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6998
                __want += __want;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  6999
                idx = __idxAndErrRBytes[__want];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7000
                __eR = __idxAndErrRBytes[__want+1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7001
                __eR -= 128;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7002
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7003
                __want = rgbP[pix+1] + __eG;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7004
                if (__want > 255) __want = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7005
                else if (__want < 0) __want = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7006
                __want += __want;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7007
                idx += __idxAndErrGBytes[__want];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7008
                __eG = __idxAndErrGBytes[__want+1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7009
                __eG -= 128;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7010
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7011
                __want = rgbP[pix+2] + __eB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7012
                if (__want > 255) __want = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7013
                else if (__want < 0) __want = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7014
                __want += __want;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7015
                idx += __idxAndErrBBytes[__want];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7016
                __eB = __idxAndErrBBytes[__want+1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7017
                __eB -= 128;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7018
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7019
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7020
                 * store the corresponding dither colors colorId
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7021
                 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7022
                *dstP++ = idP[idx];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7023
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7024
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7025
                 * distribute the error
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7026
                 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7027
                if (__eR) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7028
                    tR = __eR >> 4;  /* 16th of error */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7029
                    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7030
                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7031
                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7032
                    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7033
                    __eR = nR;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7034
                } else {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7035
                    __eR = eP[3];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7036
                    eP[0] = eP[-3] = eP[3] = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7037
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7038
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7039
                if (__eG) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7040
                    tG = __eG >> 4;  /* 16th of error */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7041
                    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7042
                    eP[1] = tG*5;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7043
                    eP[-2] = tG*3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7044
                    eP[4] = __eG - (tG*15);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7045
                    __eG = nG;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7046
                } else {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7047
                    __eG = eP[4];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7048
                    eP[1] = eP[-2] = eP[4] = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7049
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7050
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7051
                if (__eB) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7052
                    tB = __eB >> 4;  /* 16th of error */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7053
                    nB = eP[5] + (tB * 7);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7054
                    eP[2] = tB*5;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7055
                    eP[-1] = tB*3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7056
                    eP[5] = __eB - (tB*15);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7057
                    __eB = nB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7058
                } else {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7059
                    __eB = eP[5];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7060
                    eP[2] = eP[-1] = eP[5] = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7061
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7062
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7063
                eP += 3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7064
            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7065
        }
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7066
    }
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7067
%}.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7068
    failed ifTrue:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7069
        self primitiveFailed.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7070
        ^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7071
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7072
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7073
    ^ pseudoBits
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7074
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7075
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7076
floydSteinbergDitheredGrayBitsDepth:depth
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7077
    "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
  7078
     Works for any source depths / photometric,
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7079
     but possibly slow since each pixel is processed individually.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7080
     Redefined by some subclasses for more performance (D8Image/D24Image)"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7081
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7082
    |dstIndex        "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7083
     nextDst         "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7084
     bytesPerOutRow  "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7085
     outBits greyValues greyErrors greyPixels greyLevels
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7086
     errorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7087
     nextErrorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7088
     t
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7089
     w               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7090
     h               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7091
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7092
     byte            "{Class: SmallInteger }"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7093
     grey
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7094
     eR eRB eB eLB |
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7095
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7096
    depth > 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7097
	self error:'unimplemented conversion'.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7098
	^ nil
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7099
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7100
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7101
    w := width.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7102
    h := height.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7103
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7104
    bytesPerOutRow := ((w * depth) + 7) // 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7105
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7106
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7107
    greyLevels := (1 bitShift:depth) - 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7108
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7109
    errorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7110
    nextErrorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7111
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7112
    nextErrorArray atAllPut:0.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7113
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7114
    dstIndex := 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7115
    bitCnt := 8.
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
    self depth <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7118
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7119
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7120
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7121
	greyValues := self greyMapForRange:(greyLevels).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7122
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7123
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7124
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7125
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7126
						   v truncated]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7127
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7128
	greyPixels := ByteArray withAll:greyPixels.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7129
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7130
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7131
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7132
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7133
						   ((v - v truncated) * 1024) truncated
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7134
					       ]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7135
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7136
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7137
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7138
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7139
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7140
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7141
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7142
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7143
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7144
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7145
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7146
	    self valuesAtY:y from:0 to:(w-1) do:[:x :value |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7147
		|e     "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7148
		 pixel "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7149
		 error "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7150
		 e16   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7151
		 xE    "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7152
		 xN    "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7153
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7154
		pixel := greyPixels at:(value + 1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7155
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7156
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7157
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7158
		error := (greyErrors at:(value + 1)) + (errorArray at:xE).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7159
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7160
		byte := byte bitShift:depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7161
		error > 512 "0.5" ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7162
		    pixel := pixel + 1.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7163
		    e := error - 1024 "1.0"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7164
		] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7165
		    e := error
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7166
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7167
		byte := byte bitOr:pixel.
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
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7170
		    e16 := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7171
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7172
		    eR  := e16 * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7173
		    eRB := e16 * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7174
		    eB  := e16 * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7175
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7176
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7177
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7178
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7179
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7180
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7181
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7182
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7183
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7184
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7185
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7186
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7187
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7188
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7189
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7190
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7191
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7192
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7193
		bitCnt := bitCnt - depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7194
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7195
		    outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7196
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7197
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7198
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7199
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7200
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7201
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7202
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7203
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7204
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7205
		bitCnt := 8.
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
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7208
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7209
	].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7210
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7211
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7212
	    nextDst := dstIndex + bytesPerOutRow.
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
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7215
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7216
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7217
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7218
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7219
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7220
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7221
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7222
		|e     "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7223
		 pixel "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7224
		 error "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7225
		 e16   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7226
		 xE    "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7227
		 xN    "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7228
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7229
		grey := (clr brightness * greyLevels).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7230
		pixel := grey truncated.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7231
		error := ((grey - pixel) * 1024) truncated.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7232
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7233
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7234
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7235
		error := error + (errorArray at:xE).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7236
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7237
		byte := byte bitShift:depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7238
		error > 512 "0.5" ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7239
		    pixel := pixel + 1.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7240
		    e := error - 1024 "1.0"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7241
		] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7242
		    e := error
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7243
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7244
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7245
		byte := byte bitOr:pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7246
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7247
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7248
		    e16 := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7249
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7250
		    eR  := e16 * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7251
		    eRB := e16 * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7252
		    eB  := e16 * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7253
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7254
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7255
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7256
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7257
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7258
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7259
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7260
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7261
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7262
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7263
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7264
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7265
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7266
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7267
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7268
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7269
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7270
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7271
		bitCnt := bitCnt - depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7272
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7273
		    outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7274
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7275
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7276
		    bitCnt := 8.
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
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7280
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7281
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7282
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7283
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7284
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7285
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7286
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7287
	].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7288
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7289
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7290
    ^ outBits
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7291
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7292
    "Created: 10.6.1996 / 13:28:22 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7293
    "Modified: 11.6.1996 / 00:13:38 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7294
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7295
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7296
floydSteinbergDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7297
    "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
  7298
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7299
     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
  7300
     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
  7301
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7302
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7303
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7304
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7305
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7306
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7307
     nextErrorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7308
     e eD t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7309
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7310
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7311
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7312
     byte            "{Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7313
     grey
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7314
     eR eRB eB eLB |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7315
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7316
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7317
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7318
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7319
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7320
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7321
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7322
    errorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7323
    nextErrorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7324
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7325
    nextErrorArray atAllPut:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7326
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7327
    dstIndex := 1.
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7328
    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7329
    byte := 0.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7330
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7331
    self depth <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7332
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7333
	"/ use table-value in loop
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
	greyValues := self greyMapForRange:(255 * 1024).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7336
	greyValues := greyValues collect:[:v | v rounded].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7337
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7338
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7339
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7340
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7341
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7342
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7343
	    nextErrorArray := t.
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
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7346
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7347
	    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
  7348
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7349
		int __grey, __e;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7350
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7351
		OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7352
		OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7353
		int __x = __intVal(x);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7354
		int __eR, __eB, __eRB, __eLB, __eI;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7355
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7356
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7357
		__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7358
		__grey += __intVal(__errorArray[__x+1]);
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7359
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7360
		__byte <<= 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7361
		if (__grey > 127*1024) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7362
		    __e = __grey - (255*1024);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7363
		    __byte |= 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7364
		} else {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7365
		    __e = __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7366
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7367
		if (__e) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7368
		    __eI = __e >> 4;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7369
		    __eR  = __eI * 7;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7370
		    __eRB = __eI * 1;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7371
		    __eB  = __eI * 5;
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7372
		    __eLB = __e - __eR - __eRB - __eB;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7373
		    __errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7374
		    __nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7375
		    __nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7376
		    __nextErrorArray[__x  ] = __MKSMALLINT(__intVal(__nextErrorArray[__x  ]) + __eLB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7377
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7378
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7379
		__bitCnt--;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7380
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7381
		    int __dstIndex = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7382
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7383
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7384
		    dstIndex = __MKSMALLINT(__dstIndex + 1);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7385
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7386
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7387
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7388
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7389
		bitCnt = __MKSMALLINT(__bitCnt);
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7390
%}.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7391
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7392
"/                |eI "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7393
"/                 xE "{ Class: SmallInteger }"
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  7394
"/                 xN "{ Class: SmallInteger }" |
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  7395
"/
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7396
"/                "/ get the colors grey value [0 .. 1]
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7397
"/                grey := greyValues at:(pixel + 1).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7398
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7399
"/                "/ adjust error
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7400
"/                xE := x + 2.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7401
"/                grey := (grey + (errorArray at:xE)).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7402
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7403
"/                byte := byte bitShift:1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7404
"/                grey > (127*1024) ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7405
"/                    byte := byte bitOr:1.      "/ white
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7406
"/                    e := grey - (255*1024)
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7407
"/                ] ifFalse:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7408
"/                    e := grey                  "/ black
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7409
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7410
"/                e ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7411
"/                    eD := e.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7412
"/                    eI := e // 16.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7413
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7414
"/                    eR  := eI * 7.              "/ 7/16 to right
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7415
"/                    eRB := eI * 1.              "/ 1/16 to right below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7416
"/                    eB  := eI * 5.              "/ 5/16 to below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7417
"/                    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7418
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7419
"/                    xN := xE + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7420
"/                    eR ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7421
"/                        errorArray     at:xN put:(errorArray at:xN) + eR.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7422
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7423
"/                    eRB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7424
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7425
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7426
"/                    eB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7427
"/                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7428
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7429
"/                    eLB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7430
"/                        xN := xE - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7431
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7432
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7433
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7434
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7435
"/                bitCnt := bitCnt - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7436
"/                bitCnt == 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7437
"/                    monoBits at:dstIndex put:byte.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7438
"/                    dstIndex := dstIndex + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7439
"/                    byte := 0.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7440
"/                    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7441
"/                ].
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7442
		  0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7443
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7444
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7445
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7446
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7447
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7448
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7449
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7450
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7451
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7452
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7453
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7454
	'Image [info]: slow floydSteinberg dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7455
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7456
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7457
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7458
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7459
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7460
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7461
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7462
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7463
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7464
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7465
	    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
  7466
		|eI "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7467
		 xE "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7468
		 xN "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7469
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7470
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7471
		grey := (clr brightness * 255).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7472
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7473
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7474
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7475
		grey := (grey + (errorArray at:xE)) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7476
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7477
		byte := byte bitShift:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7478
		grey > 127 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7479
		    byte := byte bitOr:1.      "/ white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7480
		    e := grey - 255
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7481
		] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7482
		    e := grey                  "/ black
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7483
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7484
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7485
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7486
		    eD := e.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7487
		    eI := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7488
		    eR  := eI * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7489
		    eRB := eI * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7490
		    eB  := eI * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7491
		    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7492
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7493
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7494
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7495
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7496
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7497
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7498
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7499
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7500
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7501
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7502
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7503
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7504
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7505
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7506
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7507
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7508
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7509
		bitCnt := bitCnt - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7510
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7511
		    monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7512
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7513
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7514
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7515
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7516
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7517
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7518
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7519
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7520
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7521
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7522
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7523
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7524
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7525
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7526
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7527
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7528
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7529
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7530
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7531
    "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
  7532
    "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
  7533
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7534
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7535
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7536
    "return a nearest paint bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7537
     which must be a depth-8 image.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7538
     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
  7539
     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
  7540
     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
  7541
     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
  7542
     Color class."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7543
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7544
    |pseudoBits
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7545
     fixR    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7546
     fixG    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7547
     fixB    "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7548
     fixGfixB
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7549
     r       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7550
     g       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7551
     b       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7552
     idx     "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7553
     idMap lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7554
     clr|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7555
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7556
    self depth ~~ 8 ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7557
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7558
    photometric == #palette ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7559
	lastColor := colorMap size - 1
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7560
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7561
	lastColor := 255.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7562
    ].
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7563
    idMap := ByteArray uninitializedNew:256.
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7564
3915
dd2dae91c068 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3914
diff changeset
  7565
    (nRed isNil or:[nGreen isNil or:[nBlue isNil]]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7566
	0 to:lastColor do:[:pix |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7567
	    |clr repClr|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7568
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7569
	    clr := self colorFromValue:pix.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7570
	    repClr := clr nearestIn:fixColors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7571
	    idMap at:(pix+1) put:(fixColors identityIndexOf:repClr)-1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7572
	].
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  7573
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7574
	fixR := nRed.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7575
	fixR == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7576
	fixG := nGreen.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7577
	fixG == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7578
	fixB := nBlue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7579
	fixB == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7580
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7581
	"/ simple check
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7582
	(fixR * fixG * fixB) ~~ fixColors size ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7583
	    self error:'invalid color array passed'.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7584
	    ^ nil
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7585
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7586
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7587
	"/
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7588
	"/ collect colorIds
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7589
	"/
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7590
	fixGfixB := fixG * fixB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7591
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7592
	0 to:lastColor do:[:pix |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7593
	    clr := self colorFromValue:pix.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7594
	    r := clr redByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7595
	    g := clr greenByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7596
	    b := clr blueByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7597
	    idx := ((r * (fixR-1) + 128) // 255) * fixGfixB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7598
	    idx := idx + (((g * (fixG-1) + 128) // 255) * fixB).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7599
	    idx := idx + ((b * (fixB-1) + 128) // 255).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7600
	    idMap at:(pix+1) put:(fixColors at:(idx+1)) colorId.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7601
	].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7602
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7603
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7604
    pseudoBits := ByteArray uninitializedNew:(width * height).
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7605
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7606
    "/ translate
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7607
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  7608
    self bits
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7609
	expandPixels:8         "xlate only"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7610
	width:width height:height
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7611
	into:pseudoBits
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7612
	mapping:idMap.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7613
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7614
    ^ pseudoBits
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7615
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  7616
    "Modified: 18.6.1996 / 09:18:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7617
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7618
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7619
nfloydSteinbergDitheredDepth8BitsColors:colors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7620
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7621
     which must be a depth-8 image.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7622
     This method expects an array of colors to be used for dithering
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7623
     (which need not be a colorCubes colors)."
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7624
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7625
    |pseudoBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7626
     rgbBytes
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7627
     ditherRGBBytes ditherColors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7628
     w       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7629
     h       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7630
     index   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7631
     numR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7632
     numG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7633
     numB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7634
     bitsR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7635
     bitsG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7636
     bitsB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7637
     maxBits  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7638
     maskR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7639
     maskG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7640
     maskB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7641
     shR      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7642
     shG      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7643
     shB      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7644
     ditherIds failed map lastColor colorsByDistance qScramble
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7645
     clrLookup lookupPos cube nCube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7646
     dR  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7647
     dG  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7648
     dB  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7649
     iR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7650
     iRG   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7651
     iRGB  "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7652
     clr
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7653
     rI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7654
     gI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7655
     bI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7656
     maxIDX  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7657
     subCubeColorCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7658
     error
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7659
     dl "{Class: SmallInteger }"|
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7660
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7661
    self depth ~~ 8 ifTrue:[^ nil].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7662
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7663
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7664
    "/ collect color components as integer values (for integer arithmetic)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7665
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7666
    rgbBytes := ByteArray uninitializedNew:256 * 3.
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
    photometric == #palette ifTrue:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7669
        lastColor := colorMap size - 1
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7670
    ] ifFalse:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7671
        lastColor := 255.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7672
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7673
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7674
    0 to:lastColor do:[:pix |
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7675
        clr := self colorFromValue:pix.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7676
        rgbBytes at:index put:(clr redByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7677
        rgbBytes at:index+1 put:(clr greenByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7678
        rgbBytes at:index+2 put:(clr blueByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7679
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7680
        index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7681
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7682
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7683
    "/ collect valid ditherColors ...
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7684
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7685
    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
  7686
    ditherColors := ditherColors select:[:clr | clr colorId notNil].
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7687
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7688
    "/ collect ditherColor components
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7689
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7690
    lastColor := ditherColors size.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7691
    ditherIds := ByteArray uninitializedNew:lastColor.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7692
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7693
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7694
    1 to:lastColor do:[:pix |
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7695
        clr := ditherColors at:pix.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7696
        ditherRGBBytes at:index put:(clr redByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7697
        ditherRGBBytes at:index+1 put:(clr greenByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7698
        ditherRGBBytes at:index+2 put:(clr blueByte).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7699
        ditherIds at:pix put:clr colorId.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7700
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7701
        index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7702
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7703
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7704
    "/ place the ditherColor positions into a color cube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7705
    bitsR := 5.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7706
    bitsG := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7707
    bitsB := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7708
    maxBits := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7709
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7710
"/    bitsR := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7711
"/    bitsG := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7712
"/    bitsB := 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7713
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7714
    numR := 1 bitShift:bitsR.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7715
    numG := 1 bitShift:bitsG.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7716
    numB := 1 bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7717
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7718
    maskR := (numR-1) bitShift:(bitsG + bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7719
    maskG := (numG-1) bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7720
    maskB := numB-1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7721
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7722
    shR := -16+bitsR+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7723
    shG := -16+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7724
    shB := -16+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7725
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7726
    maxIDX := numR*numG*numB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7727
    cube := Array new:maxIDX.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7728
    1 to:lastColor do:[:clrIdx |
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7729
        clr := ditherColors at:clrIdx.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7730
        rI := clr scaledRed. rI := (rI bitShift:shR) bitAnd:maskR.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7731
        gI := clr scaledGreen. gI := (gI bitShift:shG) bitAnd:maskG.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7732
        bI := clr scaledBlue. bI := (bI bitShift:shB) bitAnd:maskB.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7733
        index := rI + gI + bI + 1.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7734
        subCubeColorCollection := cube at:index.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7735
        subCubeColorCollection isNil ifTrue:[
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7736
            subCubeColorCollection := OrderedCollection new.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7737
            cube at:index put:subCubeColorCollection.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7738
        ].
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7739
        subCubeColorCollection add:(clrIdx - 1).
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7740
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7741
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7742
    shR := 1 bitShift:(bitsG+bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7743
    shG := 1 bitShift:(bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7744
    shB := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7745
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7746
    1 to:maxIDX do:[:i |
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7747
        subCubeColorCollection := cube at:i.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7748
        subCubeColorCollection notNil ifTrue:[
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7749
            cube at:i put:(subCubeColorCollection asByteArray)
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7750
        ]
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7751
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7752
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7753
"/    nCube := cube copy.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7754
"/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7755
"/    cube keysAndValuesDo:[:i :indices |
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7756
"/        indices notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7757
"/            nCube at:i put:(indices asByteArray)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7758
"/        ] ifFalse:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7759
"/            "/ find nearest color
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7760
"/
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7761
"/            dl := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7762
"/            [dl < maxBits] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7763
"/                dR := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7764
"/                [dR <= dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7765
"/                    iR := i + (dR * shR).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7766
"/                    (iR > 0 and:[iR < maxIDX]) ifTrue:[
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7767
"/                        dG := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7768
"/                        [dG < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7769
"/                            iRG := iR + (dG * shG).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7770
"/                            (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7771
"/                                dB := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7772
"/                                [dB < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7773
"/                                    iRGB := iRG + dB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7774
"/                                    (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7775
"/                                        (cube at:iRGB) notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7776
"/                                            nCube at:i put:(cube at:iRGB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7777
"/                                            dB := dG := dR := dl := 999.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7778
"/                                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7779
"/                                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7780
"/                                    dB := dB + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7781
"/                                ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7782
"/                            ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7783
"/                            dG := dG + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7784
"/                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7785
"/                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7786
"/                    dR := dR + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7787
"/                ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7788
"/                dl := dl + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7789
"/            ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7790
"/        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7791
"/    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7792
"/self halt.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7793
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7794
    "/ now, cube contains collections of colors which are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7795
    "/ positioned in a subCube; quickly accessed by a lookup
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7796
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7797
    pseudoBits := ByteArray uninitializedNew:(width * height).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7798
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7799
    w := width.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7800
    h := height.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7801
    error := ByteArray new:(w+2)*3*2.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7802
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7803
%{
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7804
#define BITSR   5
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7805
#define BITSG   6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7806
#define BITSB   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7807
#define MAXBITS 6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7808
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7809
#define xBITSR   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7810
#define xBITSG   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7811
#define xBITSB   3
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7812
#define xMAXBITS 4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7813
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7814
#define NR      32 /* (1<<BITSR) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7815
#define NG      64 /* (1<<BITSG) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7816
#define NB      16 /* (1<<BITSB) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7817
#define MAXRGB  64 /* (1<<MAXBITS) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7818
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7819
#define SHR     (BITSG+BITSB)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7820
#define SHG     BITSB
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7821
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7822
#define REMEMBER_SEARCH
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7823
#define xNO_FLOYD_STEINBERG
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7824
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7825
    int __x, __y;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7826
    int __eR, __eG, __eB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7827
    unsigned char *srcP, *dstP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7828
    unsigned char *rgbP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7829
    unsigned char *idP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7830
    short *errP, *eP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7831
    int __fR, __fG, __fB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7832
    int idx;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7833
    int __w = __intVal(w);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7834
    int __h = __intVal(h);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7835
    int __nColors = __intVal(lastColor);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7836
    int __wR = -1, __wG, __wB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7837
    OBJ *__cube;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7838
    int cubeIndex, cubeIndex2;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7839
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7840
    if (__isByteArrayLike(__INST(bytes))
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7841
     && __isByteArray(pseudoBits)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7842
     && __isByteArray(rgbBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7843
     && __isByteArray(ditherRGBBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7844
     && __isByteArray(ditherIds)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  7845
     && __isByteArray(error)) {
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7846
        failed = false;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7847
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7848
        srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7849
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7850
        rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7851
        idP = __ByteArrayInstPtr(ditherIds)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7852
        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7853
        __cube = __ArrayInstPtr(cube)->a_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7854
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7855
        eP = errP;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7856
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7857
        for (__y=__h; __y>0; __y--) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7858
            eP = &(errP[3]);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7859
            __eR = eP[0];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7860
            __eG = eP[1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7861
            __eB = eP[2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7862
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7863
            for (__x=__w; __x>0; __x--) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7864
                int __want;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7865
                int pix;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7866
                int __wantR, __wantG, __wantB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7867
                int idx;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7868
                int tR, tG, tB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7869
                int nR, nG, nB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7870
                int __dR, __dG, __dB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7871
                int minDelta, bestIdx;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7872
                int __iR, __iG, __iB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7873
                int cR, cG, cB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7874
                int delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7875
                OBJ subCubeColors;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7876
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7877
                pix = *srcP++;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7878
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7879
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7880
                 * wR, wG and wB is the wanted r/g/b value;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7881
                 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7882
                idx = pix+pix+pix;  /* pix * 3 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7883
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7884
                __wR = __wantR = rgbP[idx] + __eR;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7885
                __wG = __wantG = rgbP[idx+1] + __eG;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7886
                __wB = __wantB = rgbP[idx+2] + __eB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7887
                if(__wR > 255) __wR = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7888
                else if (__wR < 0) __wR = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7889
                if(__wG > 255) __wG = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7890
                else if (__wG < 0) __wG = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7891
                if(__wB > 255) __wB = 255;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7892
                else if (__wB < 0) __wB = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7893
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7894
                __iR = __wR >> (8-BITSR);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7895
                __iG = __wG >> (8-BITSG);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7896
                __iB = __wB >> (8-BITSB);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7897
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7898
                cubeIndex = (__iR<<SHR) + (__iG<<SHG) + __iB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7899
                subCubeColors = __cube[cubeIndex];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7900
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7901
                if (subCubeColors == nil) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7902
                    /* search around in spirals, for the first match */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7903
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7904
                    delta = 1;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7905
                    while (delta < MAXRGB) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7906
                        /* check plane above */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7907
                        cR = __iR + delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7908
                        if ((unsigned)cR < NR) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7909
                            for (cG=__iG-delta; cG<=__iG+delta; cG++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7910
                                if ((unsigned)cG < NG) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7911
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7912
                                        if ((unsigned)cB < NB) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7913
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7914
                                            subCubeColors = __cube[cubeIndex2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7915
                                            if (__isNonNilObject(subCubeColors)) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7916
                                                goto found;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7917
                                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7918
                                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7919
                                    }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7920
                                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7921
                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7922
                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7923
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7924
                        /* check plane below */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7925
                        cR = __iR - delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7926
                        if ((unsigned)cR < NR) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7927
                            for (cG=__iG-delta; cG<=__iG+delta; cG++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7928
                                if ((unsigned)cG < NG) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7929
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7930
                                        if ((unsigned)cB < NB) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7931
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7932
                                            subCubeColors = __cube[cubeIndex2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7933
                                            if (__isNonNilObject(subCubeColors)) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7934
                                                goto found;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7935
                                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7936
                                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7937
                                    }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7938
                                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7939
                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7940
                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7941
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7942
                        /* check plane to the right */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7943
                        cG = __iG + delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7944
                        if ((unsigned)cG < NG) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7945
                            for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7946
                                if ((unsigned)cR < NR) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7947
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7948
                                        if ((unsigned)cB < NB) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7949
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7950
                                            subCubeColors = __cube[cubeIndex2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7951
                                            if (__isNonNilObject(subCubeColors)) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7952
                                                goto found;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7953
                                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7954
                                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7955
                                    }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7956
                                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7957
                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7958
                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7959
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7960
                        /* check plane to the left */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7961
                        cG = __iG - delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7962
                        if ((unsigned)cG < NG) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7963
                            for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7964
                                if ((unsigned)cR < NR) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7965
                                    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7966
                                        if ((unsigned)cB < NB) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7967
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7968
                                            subCubeColors = __cube[cubeIndex2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7969
                                            if (__isNonNilObject(subCubeColors)) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7970
                                                goto found;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7971
                                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7972
                                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7973
                                    }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7974
                                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7975
                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7976
                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7977
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7978
                        /* check plane at back */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7979
                        cB = __iB + delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7980
                        if ((unsigned)cB < NB) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7981
                            for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7982
                                if ((unsigned)cR < NR) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7983
                                    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7984
                                        if ((unsigned)cG < NG) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7985
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7986
                                            subCubeColors = __cube[cubeIndex2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7987
                                            if (__isNonNilObject(subCubeColors)) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7988
                                                goto found;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7989
                                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7990
                                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7991
                                    }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7992
                                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7993
                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7994
                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7995
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7996
                        /* check plane at front */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7997
                        cB = __iB - delta;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7998
                        if ((unsigned)cB < NB) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7999
                            for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8000
                                if ((unsigned)cR < NR) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8001
                                    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8002
                                        if ((unsigned)cG < NG) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8003
                                            cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8004
                                            subCubeColors = __cube[cubeIndex2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8005
                                            if (__isNonNilObject(subCubeColors)) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8006
                                                goto found;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8007
                                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8008
                                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8009
                                    }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8010
                                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8011
                            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8012
                        }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8013
                        delta = delta + 1;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8014
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8015
                    }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8016
                    /* cannot happen - will lead to a segmentation violation ... */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8017
                    subCubeColors = nil;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8018
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8019
    found:
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8020
                    __iR = cR;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8021
                    __iG = cG;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8022
                    __iB = cB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8023
                    bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8024
#ifdef REMEMBER_SEARCH
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8025
                    __cube[cubeIndex] = __MKSMALLINT(bestIdx);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8026
#endif
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8027
                } else {
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8028
#ifdef REMEMBER_SEARCH
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8029
                    if (__isSmallInteger(subCubeColors)) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8030
                        bestIdx = __intVal(subCubeColors);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8031
                    } else
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8032
#endif
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8033
                    {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8034
                        bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8035
                    }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8036
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8037
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8038
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8039
                 * ok, now, we have found a collection of nearby
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8040
                 * colors in subCubeColors.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8041
                 *
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8042
                 * since the error is at most 1/16 (i.e. roughly 6%),
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8043
                 * dont care for searching the best - simply take the
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8044
                 * first color found there.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8045
                 * (statistic reduces the error to even a smaller value).
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8046
                 * There is no real problem due to that error, since
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8047
                 * it will be diffused anyway ...
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8048
                 */
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8049
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8050
#ifndef NO_FLOYD_STEINBERG
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8051
                {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8052
                    unsigned char *dp;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8053
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8054
                    /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8055
                     * fetch that colors r/g/b components
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8056
                     */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8057
                    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8058
                    dp += bestIdx * 3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8059
                    __dR = dp[0];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8060
                    __dG = dp[1];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8061
                    __dB = dp[2];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8062
                }
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8063
#endif
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8064
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8065
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  8066
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8067
                __wantR, __wantG, __wantB,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8068
                __wR, __wG, __wB,
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8069
                __dR, __dG, __dB);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8070
*/
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8071
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8072
                 * store the corresponding dither colors colorId
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8073
                 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8074
                *dstP++ = idP[bestIdx];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8075
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8076
#ifndef NO_FLOYD_STEINBERG
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8077
                /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8078
                 * the new error & distribute the error
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8079
                 */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8080
                __eR = __wantR - __dR;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8081
                if (__eR) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8082
                    tR = __eR >> 4;  /* 16th of error */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8083
                    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8084
                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8085
                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8086
                    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8087
                    __eR = nR;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8088
                } else {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8089
                    __eR = eP[3];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8090
                    eP[0] = eP[-3] = eP[3] = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8091
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8092
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8093
                __eG = __wantG - __dG;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8094
                if (__eG) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8095
                    tG = __eG >> 4;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8096
                    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8097
                    eP[1] = tG*5;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8098
                    eP[-2] = tG*3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8099
                    eP[4] = __eG - (tG*15);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8100
                    __eG = nG;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8101
                } else {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8102
                    __eG = eP[4];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8103
                    eP[1] = eP[-2] = eP[4] = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8104
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8105
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8106
                __eB = __wantB - __dB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8107
                if (__eB) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8108
                    tB = __eB >> 4;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8109
                    nB = eP[5] + (tB * 7);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8110
                    eP[2] = tB*5;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8111
                    eP[-1] = tB*3;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8112
                    eP[5] = __eB - (tB*15);
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8113
                    __eB = nB;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8114
                } else {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8115
                    __eB = eP[5];
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8116
                    eP[2] = eP[-1] = eP[5] = 0;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8117
                }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8118
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8119
                eP += 3;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8120
#endif
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8121
            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8122
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8123
            /*
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8124
             * allow for an interrupt after every row.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8125
             * but care to refetch C variables
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8126
             */
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8127
            if (InterruptPending) {
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8128
                int d_srcP = srcP - __ByteArrayInstPtr(_INST(bytes))->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8129
                int d_dstP = dstP - __ByteArrayInstPtr(pseudoBits)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8130
                int d_errP = errP - (short *) __ByteArrayInstPtr(error)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8131
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8132
                __interrupt__();
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8133
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8134
                srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element + d_srcP;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8135
                dstP = __ByteArrayInstPtr(pseudoBits)->ba_element + d_dstP;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8136
                rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8137
                idP = __ByteArrayInstPtr(ditherIds)->ba_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8138
                errP = (short *) __ByteArrayInstPtr(error)->ba_element + d_errP;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8139
                __cube = __ArrayInstPtr(cube)->a_element;
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8140
            }
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8141
        }
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8142
    }
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8143
%}.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8144
    failed ifTrue:[
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8145
        self primitiveFailed.
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8146
        ^ nil
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8147
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8148
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8149
    ^ pseudoBits
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8150
!
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8151
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8152
orderedDitheredGrayBitsDepth:depth
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8153
    "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
  8154
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8155
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8156
	orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8157
	ditherWidth:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8158
	depth:depth.
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8159
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8160
    "Created: 24.6.1997 / 22:20:12 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8161
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8162
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8163
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8164
    "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
  8165
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8166
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8167
     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
  8168
     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
  8169
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8170
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8171
     greyLevels greyValues greyPixels greyErrors
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8172
     dstIndex        "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8173
     nextDst
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8174
     bytesPerOutRow  "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8175
     pixelsPerByte   "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8176
     outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8177
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8178
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8179
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8180
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8181
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8182
    depth > 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8183
	'IMAGE: unimplemented orderedDither conversion' errorPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8184
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8185
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8186
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8187
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8188
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8189
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8190
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8191
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8192
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8193
    greyLevels := 1 bitShift:depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8194
    pixelsPerByte := 8 / depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8195
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8196
    bytesPerOutRow := (w * depth + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8197
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8198
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8199
    dstIndex := 1.
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
    self bitsPerPixel <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8202
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8203
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8204
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8205
	greyValues := self greyMapForRange:(greyLevels-1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8206
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8207
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8208
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8209
						   v truncated]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8210
	greyPixels := ByteArray withAll:greyPixels.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8211
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8212
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8213
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8214
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8215
						   ((v - v truncated) * nDither) rounded
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8216
					       ]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8217
	greyErrors := ByteArray withAll:greyErrors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8218
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8219
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8220
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8221
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8222
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8223
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8224
	    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
  8225
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8226
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8227
		int __byte = __intVal(byte);
4745
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8228
		/* 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
  8229
		int __val = __intVal(value);
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8230
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8231
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8232
		int __pixel, __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8233
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8234
		unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8235
		unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8236
4745
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8237
		__pixel = __greyPixels[__val];
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8238
		__grey = __greyErrors[__val];
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8239
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8240
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8241
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8242
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8243
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8244
		if (__grey > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8245
		    __pixel++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8246
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8247
		__byte = (__byte << __intVal(depth)) | __pixel;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8248
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8249
		__bitCnt = __bitCnt - __intVal(depth);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8250
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8251
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8252
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8253
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8254
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8255
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8256
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8257
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8258
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8259
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8260
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8261
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8262
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8263
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8264
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8265
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8266
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8267
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8268
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8269
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8270
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8271
	'Image [info]: slow ordered dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8272
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8273
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8274
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8275
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8276
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8277
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8278
	    "/ this is the representaion independent (but slow)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8279
	    "/ inner loop - it extracts colors from the receiver
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8280
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8281
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8282
		|dstClr grey dT pixel|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8283
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8284
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8285
		grey := clr brightness.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8286
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8287
		"/ remap into [0 .. greyLevels-1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8288
		grey := grey * (greyLevels-1).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8289
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8290
		"/ get threshold pixel [0 .. greyLevels-1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8291
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8292
		pixel := grey truncated.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8293
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8294
		"/ compute the error [0..1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8295
		grey := grey - pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8296
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8297
		"/ map into dither space [0 .. nDither]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8298
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8299
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8300
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8301
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8302
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8303
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8304
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8305
		int __pixel;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8306
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8307
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8308
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8309
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8310
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8311
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8312
		__pixel = __intVal(pixel);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8313
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8314
		if (__intVal(grey) > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8315
		    __pixel++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8316
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8317
		__byte = (__byte << __intVal(depth)) | __pixel;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8318
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8319
		__bitCnt = __bitCnt - __intVal(depth);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8320
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8321
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8322
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8323
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8324
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8325
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8326
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8327
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8328
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8329
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8330
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8331
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8332
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8333
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8334
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8335
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8336
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8337
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8338
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8339
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8340
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8341
    ^ outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8342
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8343
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8344
orderedDitheredMonochromeBits
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8345
    "return the bitmap for a dithered monochrome bitmap from the image;
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8346
     using a default ditherMatrix."
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8347
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8348
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8349
	orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8350
	ditherWidth:8
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8351
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8352
    "Created: 11.6.1996 / 16:48:57 / cg"
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8353
!
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8354
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8355
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8356
    "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
  8357
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8358
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8359
     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
  8360
     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
  8361
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8362
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8363
     greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8364
     dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8365
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8366
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8367
     monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8368
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8369
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8370
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8371
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8372
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8373
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8374
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8375
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8376
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8377
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8378
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8379
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8380
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8381
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8382
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8383
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8384
    self bitsPerPixel <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8385
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8386
	"/ use table-value in loop
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
	greyValues := self greyByteMapForRange:nDither.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8389
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8390
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8391
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8392
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8393
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8394
	    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
  8395
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8396
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8397
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8398
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8399
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8400
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8401
		int __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8402
		unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8403
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8404
		__grey = __greyValues[__intVal(value)];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8405
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8406
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8407
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8408
					 + (__intVal(y) % __intVal(dH)) * __dW];
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
		__byte = __byte << 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8411
		if (__grey > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8412
		    __byte = __byte | 1;            /* white */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8413
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8414
		__bitCnt = __bitCnt - 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8415
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8416
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8417
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8418
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8419
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8420
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8421
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8422
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8423
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8424
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8425
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8426
		0
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
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8429
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8430
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8431
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8432
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8433
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8434
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8435
	'Image [info]: slow ordered dither ..' infoPrintCR.
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
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8438
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8439
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8440
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8441
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8442
		|dstClr grey dT|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8443
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8444
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8445
		grey := clr brightness.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8446
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8447
		"/ map into dither space [0 .. nDither]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8448
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8449
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8450
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8451
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8452
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8453
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8454
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8455
		int __bitCnt = __intVal(bitCnt);
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
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8458
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8459
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8460
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8461
		__byte = __byte << 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8462
		if (__intVal(grey) > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8463
		    __byte = __byte | 1;            /* white */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8464
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8465
		__bitCnt = __bitCnt - 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8466
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8467
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8468
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8469
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8470
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8471
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8472
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8473
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8474
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8475
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8476
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8477
		0
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8478
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8479
"/                dT := ditherMatrix at:(x \\ dW) + (y \\ dH * dW) + 1.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8480
"/
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8481
"/                byte := byte bitShift:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8482
"/                grey < dT ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8483
"/                    byte := byte bitOr:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8484
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8485
"/                bitCnt := bitCnt - 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8486
"/                bitCnt == 0 ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8487
"/                    monoBits at:dstIndex put:byte.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8488
"/                    dstIndex := dstIndex + 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8489
"/                    byte := 0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8490
"/                    bitCnt := 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8491
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8492
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8493
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8494
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8495
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8496
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8497
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8498
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8499
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8500
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8501
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8502
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8503
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8504
stevensonArceDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8505
    "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
  8506
     Works for any source depths / photometric"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8507
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  8508
    |dstIndex        "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8509
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8510
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8511
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8512
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8513
     errorArray1 errorArray2 errorArray3
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8514
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8515
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8516
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8517
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8518
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  8519
     grey
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  8520
     xE              "{Class: SmallInteger }" |
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8521
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8522
    self depth > 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8523
	^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8524
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8525
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8526
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8527
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8528
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8529
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8530
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8531
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8532
    errorArray := Array new:(w+6).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8533
    errorArray1 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8534
    errorArray2 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8535
    errorArray3 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8536
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8537
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8538
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8539
    "/ 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
  8540
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8541
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8542
    greyValues := self greyMapForRange:(255 * 1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8543
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8544
    0 to:(h-1) do:[:y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8545
	nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8546
	byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8547
	bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8548
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8549
	t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8550
	errorArray := errorArray1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8551
	errorArray1 := errorArray2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8552
	errorArray2 := errorArray3.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8553
	errorArray3 := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8554
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8555
	errorArray3 atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8556
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8557
	self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8558
	    |eP eD|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8559
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8560
	    "/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8561
	    grey := greyValues at:(pixel + 1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8562
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8563
	    "/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8564
	    xE := x + 3 + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8565
	    grey := (grey + (errorArray at:xE)).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8566
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8567
	    byte := byte bitShift:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8568
	    grey > (127 * 1024) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8569
		byte := byte bitOr:1.      "/ white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8570
		e := grey - (255 * 1024)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8571
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8572
		e := grey                  "/ black
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8573
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8574
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8575
	    e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8576
		"/ distribute the error:
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8577
		"/                  XX    32
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8578
		"/         12    26    30    16
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8579
		"/            12    26    12
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8580
		"/          5    12    12     5
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8581
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8582
		eD := e.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8583
		e := e // 200.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8584
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8585
		eP := e * 32. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8586
		errorArray at:xE+2 put:(errorArray at:xE+2) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8587
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8588
		eP := e * 30. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8589
		errorArray1 at:xE+1 put:(errorArray1 at:xE+1) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8590
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8591
		eP := e * 16. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8592
		errorArray1 at:xE+3 put:(errorArray1 at:xE+3) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8593
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8594
		eP := e * 26. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8595
		errorArray1 at:xE-1 put:(errorArray1 at:xE-1) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8596
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8597
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8598
		errorArray2 at:xE put:(errorArray2 at:xE) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8599
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8600
		eP := e * 12. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8601
		errorArray1 at:xE-3 put:(errorArray1 at:xE-3) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8602
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8603
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8604
		errorArray2 at:xE-2 put:(errorArray2 at:xE-2) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8605
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8606
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8607
		errorArray2 at:xE+2 put:(errorArray2 at:xE+2) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8608
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8609
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8610
		errorArray3 at:xE-1 put:(errorArray3 at:xE-1) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8611
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8612
		eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8613
		errorArray3 at:xE+1 put:(errorArray3 at:xE+1) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8614
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8615
		eP := e * 5. eD := eD - eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8616
		errorArray3 at:xE-3 put:(errorArray3 at:xE-3) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8617
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8618
		eP := eD.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8619
		errorArray3 at:xE+3 put:(errorArray3 at:xE+3) + eP.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8620
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8621
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8622
	    bitCnt := bitCnt - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8623
	    bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8624
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8625
		dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8626
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8627
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8628
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8629
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8630
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8631
	bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8632
	    byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8633
	    monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8634
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8635
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8636
	dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8637
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8638
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8639
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8640
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8641
    "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
  8642
    "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
  8643
! !
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8644
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8645
!Image methodsFor:'drawing'!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8646
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8647
displayArcOrigin:origin corner:corner from:startAngle angle:angle withColor:aColor
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8648
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8649
     By using a tempForm, we assure that the same pixel algorithm is used as in a window"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8650
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8651
    self displayArcOrigin:origin corner:corner from:startAngle angle:angle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8652
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8653
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8654
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8655
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8656
     cm :=  Array with:Color white with:Color black with:Color red.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8657
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8658
     i := Depth8Image extent:300@400 depth:8 palette:cm.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8659
     i displayArcOrigin:100@100 corner:200@200 from:0 angle:90 withColor:Color red.    
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8660
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8661
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8662
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8663
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8664
displayArcOrigin:origin corner:corner from:startAngle angle:angle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8665
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8666
     By using a tempForm, we assure that the same pixel algorithm is used as in a window.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8667
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8668
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8669
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8670
    |tempForm wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8671
     hI "{ Class: SmallInteger }"|
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8672
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8673
    wI := self width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8674
    hI := self height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8675
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8676
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8677
    tempForm clear.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8678
    tempForm paint:(Color colorId:1).
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8679
    tempForm displayArcOrigin:origin corner:corner from:startAngle angle:angle.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8680
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8681
    0 to:hI-1 do:[:yRun|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8682
        0 to:wI-1 do:[:xRun|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8683
            (tempForm atX:xRun y:yRun) == 1 ifTrue:[
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8684
                self atImageAndMask:(xRun)@(yRun) putValue:aPixelValueOrNil.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8685
            ].
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8686
        ].
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8687
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8688
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8689
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8690
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8691
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8692
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8693
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8694
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8695
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8696
     i displayArcOrigin:100@100 corner:200@200 from:0 angle:90 withColor:Color red.    
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8697
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8698
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8699
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8700
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8701
drawEllipse:aRectangle withColor:aColor
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8702
    "draw a circle with some pixel value.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8703
     By using a tempForm, we assure that the same pixel algorithm is used as in a window"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8704
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8705
    self drawEllipse:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8706
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8707
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8708
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8709
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8710
     cm :=  Array with:Color white with:Color black with:Color red.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8711
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8712
     i := Depth8Image extent:300@400 depth:8 palette:cm.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8713
     i drawEllipse:(0@0 corner:80@100) withColor:Color red.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8714
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8715
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8716
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8717
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8718
drawEllipse:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8719
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8720
     By using a tempForm, we assure that the same pixel algorithm is used as in a window.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8721
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8722
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8723
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8724
    |tempForm xI "{ Class: SmallInteger }"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8725
     yI "{ Class: SmallInteger }"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8726
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8727
     hI "{ Class: SmallInteger }"|
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8728
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8729
    wI := aRectangle width.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8730
    hI := aRectangle height.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8731
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8732
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8733
    tempForm clear.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8734
    tempForm paint:(Color colorId:1).
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8735
    tempForm displayArcIn:(0@0 extent:wI@hI) from:0 angle:360.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8736
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8737
    xI := aRectangle left.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8738
    yI := aRectangle top.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8739
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8740
    0 to:hI-1 do:[:yRun|
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8741
        0 to:wI-1 do:[:xRun|
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8742
            (tempForm atX:xRun y:yRun) == 1 ifTrue:[
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8743
                self atImageAndMask: (xI+xRun)@(yI+yRun) putValue:aPixelValueOrNil.
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8744
            ].
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8745
        ].
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8746
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8747
    self release. "/ device-image is no longer valid
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8748
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8749
    "
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8750
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8751
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8752
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8753
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8754
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8755
     i drawEllipse:(0@0 corner:80@100) withColor:Color red.
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8756
     i inspect.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8757
    "
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8758
!
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  8759
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  8760
drawLineFrom:startPoint to:endPoint withColor:aColorOrPixelValue
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8761
    "draw a line with some pixel value.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8762
     This is in no way tuned, as normally, display-forms are used to draw.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8763
     The only use for this is when we have to generate images in a headless webService
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8764
     (such as the HumanReadableImageGenerator)"
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8765
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  8766
    |pixelValue|
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  8767
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  8768
    pixelValue := aColorOrPixelValue.
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  8769
    pixelValue isInteger ifFalse:[
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  8770
        pixelValue := self valueFromColor:aColorOrPixelValue
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  8771
    ].
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  8772
    self drawLineFrom:startPoint to:endPoint withValue:pixelValue
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8773
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8774
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8775
     |i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8776
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8777
     i := Depth1Image extent:100@100 depth:1 palette:nil.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8778
     i photometric:#blackIs0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8779
     i drawLineFrom:5@5 to:94@5 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8780
     i drawLineFrom:94@5 to:94@94 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8781
     i drawLineFrom:94@94 to:5@94 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8782
     i drawLineFrom:5@94 to:5@5 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8783
     i drawLineFrom:10@10 to:90@90 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8784
     i drawLineFrom:90@10 to:10@90 withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8785
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8786
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8787
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8788
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8789
drawLineFrom:startPoint to:endPoint withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8790
    "draw a line with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8791
     This is in no way tuned, as normally, display-forms are used to draw.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8792
     The only use for this is when we have to generate images in a headless webService
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8793
     (such as the HumanReadableImageGenerator).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8794
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8795
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8796
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8797
    |x0 x1 y0 y1 t steep deltax deltay error deltaerr ystep y|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8798
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8799
    x0 := startPoint x.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8800
    y0 := startPoint y.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8801
    x1 := endPoint x.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8802
    y1 := endPoint y.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8803
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8804
    steep := (y1 - y0) abs > (x1 - x0) abs.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8805
    steep ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8806
        t := x0. x0 := y0. y0 := t.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8807
        t := x1. x1 := y1. y1 := t.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8808
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8809
    x0 > x1 ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8810
        t := x0. x0 := x1. x1 := t.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8811
        t := y0. y0 := y1. y1 := t.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8812
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8813
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8814
    deltax := x1 - x0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8815
    deltay := (y1 - y0) abs.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8816
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8817
    deltax == 0 ifTrue:[
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8818
        y0 to: y1 do:[:y |
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8819
            self atImageAndMask:x0@y putValue:aPixelValueOrNil.
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8820
        ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8821
        ^ self.
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8822
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8823
    deltay == 0 ifTrue:[
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8824
        x0 to: x1 do:[:x |
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8825
            self atImageAndMask:x@y0 putValue:aPixelValueOrNil.
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8826
        ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8827
        ^ self.
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8828
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8829
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8830
    error := 0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8831
    deltaerr := deltay / deltax.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8832
    y := y0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8833
    y0 < y1 ifTrue:[ ystep := 1 ] ifFalse:[ ystep := -1 ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8834
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8835
    x0 to: x1 do:[:x |
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8836
        steep ifTrue:[
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8837
            self atImageAndMask:y@x putValue:aPixelValueOrNil.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8838
        ] ifFalse:[
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8839
            self atImageAndMask:x@y putValue:aPixelValueOrNil.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8840
        ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8841
        error := error + deltaerr.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8842
        error >= 0.5 ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8843
            y := y + ystep.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8844
            error := error - 1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8845
        ]
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8846
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8847
    self release. "/ device-image is no longer valid
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8848
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8849
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8850
     |i|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8851
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8852
     i := Depth1Image extent:100@100 depth:1 palette:nil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8853
     i photometric:#blackIs0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8854
     i drawLineFrom:5@5 to:94@5 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8855
     i drawLineFrom:94@5 to:94@94 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8856
     i drawLineFrom:94@94 to:5@94 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8857
     i drawLineFrom:5@94 to:5@5 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8858
     i drawLineFrom:10@10 to:90@90 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8859
     i drawLineFrom:90@10 to:10@90 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8860
     i inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8861
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8862
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8863
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8864
drawRectangle: aRectangle withColor:aColor
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8865
    "draw a rectangle with some pixel value.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8866
     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
  8867
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8868
    self drawRectangle:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8869
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8870
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8871
     |i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8872
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8873
     i := Depth1Image extent:100@100 depth:1 palette:nil.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8874
     i photometric:#blackIs0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8875
     i drawRectangle:(10@10 corner:90@90) withColor:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8876
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8877
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8878
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8879
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8880
drawRectangle: aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8881
    "draw a rectangle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8882
     By using #atImageAndMask:put: it also works on images with mono masks.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8883
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8884
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8885
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8886
    |xI "{ Class: SmallInteger }"
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8887
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8888
     wI "{ Class: SmallInteger }"
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8889
     hI "{ Class: SmallInteger }"|
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8890
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8891
    xI := aRectangle left.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8892
    yI := aRectangle top.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8893
    wI := aRectangle width.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8894
    hI := aRectangle height.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8895
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8896
    xI to:xI+wI-1 do:[:xRun|
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8897
        self atImageAndMask: xRun@yI put:aPixelValueOrNil.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8898
        self atImageAndMask: xRun@(yI+hI-1) put:aPixelValueOrNil
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8899
    ].
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8900
    yI+1 to:yI+hI-2 do:[:yRun|
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8901
        self atImageAndMask: xI@yRun put:aPixelValueOrNil.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  8902
        self atImageAndMask: xI+wI-1@yRun put:aPixelValueOrNil
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8903
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8904
    self release. "/ device-image is no longer valid
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8905
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8906
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8907
     |i|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8908
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8909
     i := Depth1Image extent:100@100 depth:1 palette:nil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8910
     i photometric:#blackIs0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8911
     i drawRectangle:(10@10 corner:90@90) withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8912
     i inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  8913
    "
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8914
!
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  8915
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8916
fillAntiAliasedArc:origin radius:r from:startAngle angle:angle withColor:aColor colorDictionary:colorDictionary blendStart:blendStart
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8917
    "draw a circle with some pixel value.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8918
     By using a tempForm, we assure that the same pixel algorithm is used as in a window"
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8919
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8920
    |tempForm wI "{ Class: SmallInteger }"
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8921
     hI "{ Class: SmallInteger }"
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8922
     colorValue|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8923
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8924
    wI := self width.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8925
    hI := self height.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8926
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8927
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8928
    tempForm clear.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8929
    tempForm paint:(Color colorId:1).
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8930
    tempForm fillArc:origin radius:r from:startAngle angle:angle.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8931
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8932
    colorValue := self valueFromColor:aColor.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8933
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8934
    0 to:hI-1 do:[:yRun|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8935
        0 to:wI-1 do:[:xRun|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8936
            (tempForm atX:xRun y:yRun) == 1 ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8937
                self atImageAndMask:(xRun)@(yRun) putValue:colorValue.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8938
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8939
                #(#left right) do:[:aHorizontal |
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8940
                    #(#top bottom) do:[:aVertical |
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8941
                        self vitualAntiAliasedAlongXvertical:aVertical horizontal:aHorizontal form:tempForm color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8942
                        self vitualAntiAliasedAlongYhorizontal:aHorizontal vertical:aVertical form:tempForm color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8943
                    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8944
                ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8945
            ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8946
        ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8947
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8948
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8949
    "
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8950
        |colorMap aaImgArray|
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8951
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8952
        colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8953
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8954
        aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8955
        aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8956
            colorDictionary:aaImgArray first 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8957
            blendStart:aaImgArray second.   
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8958
        aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8959
            colorDictionary:aaImgArray first 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8960
            blendStart:aaImgArray second. 
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8961
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  8962
        aaImgArray last inspect.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8963
    "
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8964
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8965
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  8966
fillArc:origin radius:r from:startAngle angle:angle withColor:aColorOrIndex 
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8967
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8968
     By using a tempForm, we assure that the same pixel algorithm is used as in a window"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8969
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8970
    |tempForm wI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8971
     hI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8972
     colorValue|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8973
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8974
    wI := self width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8975
    hI := self height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8976
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8977
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8978
    tempForm clear.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8979
    tempForm paint:(Color colorId:1).
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8980
    tempForm fillArc:origin radius:r from:startAngle angle:angle.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8981
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  8982
    aColorOrIndex isInteger ifTrue:[
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  8983
        colorValue := aColorOrIndex.
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  8984
    ] ifFalse:[
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  8985
        colorValue := self valueFromColor:aColorOrIndex.
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  8986
    ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8987
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8988
    0 to:hI-1 do:[:yRun|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8989
        0 to:wI-1 do:[:xRun|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8990
            (tempForm atX:xRun y:yRun) == 1 ifTrue:[
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8991
                self atImageAndMask:(xRun)@(yRun) putValue:colorValue.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8992
            ].
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8993
        ].
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8994
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  8995
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8997
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8998
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  8999
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9000
     cm :=  Array with:Color white with:Color black with:Color red with:Color blue.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9001
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9002
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9003
     i fillArc:205@195 radius:80 from:0 angle:90 withColor:Color red.    
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9004
     i fillArc:200@200 radius:80 from:90 angle:270 withColor:Color blue.    
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9005
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9006
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9007
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9008
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9009
fillEllipse:aRectangle withColor:aColor
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9010
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9011
     By using a tempForm, we assure that the same pixel algorithm is used as in a window"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9012
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9013
    self fillEllipse:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9014
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9015
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9016
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9017
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9018
     cm :=  Array with:Color white with:Color black with:Color red.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9019
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9020
     i := Depth8Image extent:300@400 depth:8 palette:cm.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9021
     i fillEllipse:(0@0 corner:80@100) withColor:Color red.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9022
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9023
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9024
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9025
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9026
fillEllipse:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9027
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9028
     By using a tempForm, we assure that the same pixel algorithm is used as in a window.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9029
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9030
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9031
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9032
    |tempForm xI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9033
     yI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9034
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9035
     hI "{ Class: SmallInteger }"|
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9036
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9037
    wI := aRectangle width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9038
    hI := aRectangle height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9039
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9040
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9041
    tempForm clear.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9042
    tempForm paint:(Color colorId:1).
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9043
    tempForm fillArcIn:(0@0 extent:wI@hI) from:0 angle:360.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9044
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9045
    xI := aRectangle left.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9046
    yI := aRectangle top.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9047
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9048
    0 to:hI-1 do:[:yRun|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9049
        0 to:wI-1 do:[:xRun|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9050
            (tempForm atX:xRun y:yRun) == 1 ifTrue:[
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9051
                self atImageAndMask:(xI+xRun)@(yI+yRun) putValue:aPixelValueOrNil.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9052
            ].
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9053
        ].
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9054
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9055
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9056
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9057
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9058
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9059
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9060
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9061
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9062
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9063
     i fillEllipse:(0@0 corner:80@100) withColor:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9064
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9065
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9066
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9067
4995
3a5cb7a57b0b changed #fillRectangle:aRectangle withColor:aColor
sr
parents: 4994
diff changeset
  9068
fillRectangle:aRectangle withColor:aColor
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
  9069
    self 
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9070
        fillRectangle:aRectangle 
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9071
        withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9072
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9073
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9074
fillRectangle:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9075
    "fill a rectangular area with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9076
     May be redefined in concrete subclasses for more performance, if req'd.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9077
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9078
     otherwise to 1. (used by the bitmap editor)"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9079
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9080
    self 
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
  9081
        fillRectangleX:aRectangle left y:aRectangle top 
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
  9082
        width:aRectangle width height:aRectangle height 
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9083
        withValue:aPixelValueOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9084
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9085
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9086
fillRectangleX:x y:y width:w height:h with:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9087
    "fill a rectangular area with a aColor"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9088
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9089
    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
  9090
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9091
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9092
fillRectangleX:x y:y width:w height:h withValue:aPixelValueOrNil
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9093
    "fill a rectangular area with some pixel value.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9094
     May be redefined in concrete subclasses for more performance, if req'd.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9095
     If aPixelValueOrNil is nil, the mask pixel will be set to 0 (transparent),
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9096
     otherwise to 1. (used by the bitmap editor)"
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9097
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9098
    |xI "{ Class: SmallInteger }"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9099
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9100
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9101
     hI "{ Class: SmallInteger }"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9102
     p|
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9103
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9104
    xI := x.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9105
    yI := y.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9106
    wI := w.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9107
    hI := h.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9108
    p := Point new.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9109
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9110
    yI to:yI+hI-1 do:[:yRun |
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9111
        xI to:xI+wI-1 do:[:xRun |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9112
            p x:xRun y:yRun.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9113
            self atImageAndMask:p putValue:aPixelValueOrNil.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9114
        ]
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9115
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9116
    self release. "/ device-image is no longer valid
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9117
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9118
    "Created: 22.4.1997 / 14:02:14 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9119
    "Modified: 24.4.1997 / 17:24:58 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9120
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9121
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9122
floodFillAt: aPoint withColor: aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9123
    "fill a area with aColor like a flood up to surrounded pixels having different colors.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9124
     By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9125
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9126
    self floodFillAt:aPoint withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9127
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9128
"/    |surroundingPixelsOfDo detectedPixel processPixelToFill
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9129
"/     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9130
"/     toDo idx pixel w h|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9131
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9132
"/    w := self width.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9133
"/    h := self height.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9134
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9135
"/    surroundingPixelsOfDo :=
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9136
"/        [:pX :pY :fn |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9137
"/            |nX nY|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9138
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9139
"/            nX := pX + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9140
"/            nY := pY + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9141
"/            (nY < h) ifTrue: [fn value:pX value:nY].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9142
"/            (pY > 0) ifTrue: [fn value:pX value:(pY - 1)].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9143
"/            (nX < w) ifTrue: [fn value:nX value:pY].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9144
"/            (pX > 0) ifTrue: [fn value:(pX - 1) value:pY].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9145
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9146
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9147
"/    enumerateDetectedPixelsAndDo :=
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9148
"/        [:detectedPixels :action |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9149
"/            |idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9150
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9151
"/            idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9152
"/            0 to:h-1 do:[:y |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9153
"/                0 to:w-1 do:[:x |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9154
"/                    (detectedPixels at:idx) ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9155
"/                        action value:x value:y
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9156
"/                    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9157
"/                    idx := idx + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9158
"/                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9159
"/            ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9160
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9161
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9162
"/    processPixelToFill := [:spX :spY |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9163
"/            |sp idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9164
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9165
"/            ((self pixelAtX:spX y:spY) == detectedPixel and: [mask isNil or:[(mask pixelAtX:spX y:spY) == 1]])
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9166
"/            ifTrue: [
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9167
"/                idx := 1 + spX + (spY * w).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9168
"/                (allDetectedPixelCoordinates at:idx) ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9169
"/                    allDetectedPixelCoordinates at:idx put:true.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9170
"/                    toDo add:spX @ spY.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9171
"/                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9172
"/            ]
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9173
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9174
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9175
"/    (mask notNil and: [(mask pixelAt:aPoint) == 0]) ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9176
"/        allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9177
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9178
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9179
"/                value:[:x :y | self atImageAndMask:(x@y) put: aColor].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9180
"/        ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9181
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9182
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9183
"/    detectedPixel := self pixelAt: aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9184
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9185
"/    allDetectedPixelCoordinates := BooleanArray new:(w * h).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9186
"/    toDo := OrderedCollection new:1000.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9187
"/    allDetectedPixelCoordinates at:(1 + aPoint x + (aPoint y * w)) put:true.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9188
"/    toDo add:aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9189
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9190
"/    [toDo notEmpty] whileTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9191
"/        |p|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9192
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9193
"/        p := toDo removeFirst.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9194
"/        surroundingPixelsOfDo value:p x value:p y value:processPixelToFill.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9195
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9196
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9197
"/    idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9198
"/    aColor redByte notNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9199
"/        pixel := self valueFromColor:aColor.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9200
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9201
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9202
"/    pixel isNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9203
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9204
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9205
"/                value:[:x :y | mask pixelAtX:x y:y put:0].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9206
"/    ] ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9207
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9208
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9209
"/                value:[:x :y | self pixelAtX:x y:y put:pixel].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9210
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9211
"/    ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9212
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9213
    "Modified: / 29.7.1998 / 03:09:16 / cg"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9214
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9215
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9216
floodFillAt:aPoint withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9217
    "fill a area with aColor like a flood up to surrounded pixels having different colors.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9218
     By using #atImageAndMask:put: it also works on images with mono masks."
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9219
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9220
    |surroundingPixelsOfDo detectedPixel detectedMask processPixelToFill
3861
e9cbd4ec6020 flood fill with mask fixed
Claus Gittinger <cg@exept.de>
parents: 3860
diff changeset
  9221
     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9222
     toDo w h drawAction|
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9223
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9224
    w := self width.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9225
    h := self height.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9226
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9227
    surroundingPixelsOfDo :=
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9228
        [:pX :pY :fn |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9229
            |nX nY|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9230
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9231
            nX := pX + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9232
            nY := pY + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9233
            (nY < h) ifTrue: [fn value:pX value:nY].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9234
            (pY > 0) ifTrue: [fn value:pX value:(pY - 1)].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9235
            (nX < w) ifTrue: [fn value:nX value:pY].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9236
            (pX > 0) ifTrue: [fn value:(pX - 1) value:pY].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9237
        ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9238
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9239
    enumerateDetectedPixelsAndDo :=
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9240
        [:detectedPixels :action |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9241
            |idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9242
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9243
            idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9244
            0 to:h-1 do:[:y |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9245
                0 to:w-1 do:[:x |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9246
                    (detectedPixels at:idx) ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9247
                        action value:x value:y
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9248
                    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9249
                    idx := idx + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9250
                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9251
            ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9252
        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9253
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9254
    processPixelToFill := 
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9255
        [:spX :spY |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9256
            |samePixel sp idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9257
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9258
            mask isNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9259
                samePixel := (self pixelAtX:spX y:spY) == detectedPixel   
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9260
            ] ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9261
                detectedMask == 0 ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9262
                    samePixel := (mask pixelAtX:spX y:spY) == 0
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9263
                ] ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9264
                    samePixel := ((self pixelAtX:spX y:spY) == detectedPixel)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9265
                                 and:[ (mask pixelAtX:spX y:spY) == detectedMask ]
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9266
                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9267
            ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9268
            samePixel ifTrue: [
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9269
                idx := 1 + spX + (spY * w).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9270
                (allDetectedPixelCoordinates at:idx) ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9271
                    allDetectedPixelCoordinates at:idx put:true.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9272
                    toDo add:spX @ spY.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9273
                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9274
            ]
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9275
        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9276
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9277
"/    (mask notNil and: [(mask pixelAt:aPoint) == 0]) ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9278
"/        allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9279
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9280
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9281
"/                value:[:x :y | self atImageAndMask:(x@y) putValue:aPixelValueOrNil].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9282
"/        ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9283
"/    ].
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9284
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9285
    detectedPixel := self pixelAt: aPoint.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9286
    mask isNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9287
        detectedMask := 1
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9288
    ] ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9289
        detectedMask := mask pixelAt: aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9290
    ].
4420
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  9291
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9292
    allDetectedPixelCoordinates := BooleanArray new:(w * h).
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9293
    toDo := OrderedCollection new:1000.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9294
    allDetectedPixelCoordinates at:((aPoint y * w) + aPoint x + 1) put:true.
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9295
    toDo add:aPoint.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9296
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9297
    [toDo notEmpty] whileTrue:[
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9298
        |p|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9299
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9300
        p := toDo removeLast.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9301
        surroundingPixelsOfDo value:p x value:p y value:processPixelToFill.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9302
    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9303
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9304
    aPixelValueOrNil isNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9305
        drawAction := [:x :y | 
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9306
                               mask pixelAtX:x y:y put:0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9307
                               self pixelAtX:x y:y put:0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9308
                      ].
3805
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  9309
    ] ifFalse:[
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9310
        drawAction := [:x :y | 
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9311
                                mask notNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9312
                                    mask pixelAtX:x y:y put:1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9313
                                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9314
                                self pixelAtX:x y:y put:aPixelValueOrNil].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9315
    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9316
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9317
    enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9318
        value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9319
        value:drawAction.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9320
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9321
    self release. "/ device-image is no longer valid
3805
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  9322
    ^ allDetectedPixelCoordinates
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9323
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9324
    "Modified: / 29.7.1998 / 03:09:16 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9325
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9326
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9327
rectangle: aRectangle withColor:aColor
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
  9328
    <resource: #obsolete>
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9329
    "draw a rectangle with some pixel value.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9330
    By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9331
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9332
    self obsoleteMethodWarning.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9333
    self drawRectangle: aRectangle withColor:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9334
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9335
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9336
! !
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9337
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9338
!Image methodsFor:'enumerating'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9339
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9340
atY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9341
    "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
  9342
     The block is passed the color at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9343
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9344
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9345
     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
  9346
     and also the color allocation)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9347
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  9348
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  9349
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9350
    self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9351
    self colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9352
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9353
    "Modified: 7.6.1996 / 19:13:30 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9354
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9355
5143
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9356
colorsAtX:x from:y1 to:y2 do:aBlock
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9357
    "perform aBlock for each pixel from y1 to y2 in col x.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9358
     The block is passed the color at each pixel.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9359
     The code here provides a generic and slow implementation, and
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9360
     should be redefined in concrete subclasses, to avoid some processing
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9361
     when going from pixel to pixel (i.e. the byte-index and mask computations
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9362
     and also the color allocation)."
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9363
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9364
    |yStart "{Class: SmallInteger }"
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9365
     yEnd   "{Class: SmallInteger }"|
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9366
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9367
    yStart := y1.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9368
    yEnd := y2.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9369
    yStart to:yEnd do:[:yRun |
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9370
        aBlock value:yRun value:(self colorAtX:x y:yRun)
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9371
    ]
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9372
!
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9373
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9374
colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9375
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9376
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9377
     The code here provides a generic and slow implementation, and
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9378
     should be redefined in concrete subclasses, to avoid some processing
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9379
     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
  9380
     and also the color allocation)."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9381
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9382
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9383
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9384
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9385
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9386
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9387
    xStart to:xEnd do:[:xRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9388
	aBlock value:xRun value:(self colorAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9389
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9390
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  9391
    "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
  9392
    "Modified: / 30.9.1998 / 22:14:16 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9393
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9394
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9395
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9396
    "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
  9397
     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
  9398
     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
  9399
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9400
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9401
     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
  9402
     and especially, the color allocations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9403
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9404
    |yS "{Class: SmallInteger }"
942
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  9405
     yE "{Class: SmallInteger }"
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  9406
     yR|
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  9407
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  9408
    yS := yStart.
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
  9409
    yE := yEnd.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9410
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9411
    yS to:yE do:[:yRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9412
	yR := yRun.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9413
	self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9414
	    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
  9415
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9416
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9417
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
  9418
    "Modified: 11.7.1996 / 19:50:47 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9419
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9420
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9421
valueAtY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9422
    "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
  9423
     Obsolete - remains for backward compatibility."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9424
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  9425
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  9426
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9427
    self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9428
    self valuesAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9429
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9430
    "Modified: 7.6.1996 / 19:11:06 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9431
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9432
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9433
valuesAtY:y from:x1 to:x2 do:aBlock
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9434
    "WARNING: for now, this enumerates pixel values
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9435
     (backward compatibility with ST/X)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9436
     In the future, this will enumerate colors
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9437
     Use #pixelAtT:from:to:do: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9438
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9439
     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
  9440
     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
  9441
     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
  9442
     (see also Image>>atY:from:to:do:).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9443
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9444
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9445
     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
  9446
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9447
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9448
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9449
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9450
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9451
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9452
    xStart to:xEnd do:[:xRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9453
	aBlock value:xRun value:(self pixelAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9454
    ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
  9455
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9456
    "Created: 7.6.1996 / 19:09:51 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9457
    "Modified: 24.4.1997 / 16:55:38 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9458
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9459
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9460
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9461
    "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
  9462
     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
  9463
     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
  9464
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9465
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9466
     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
  9467
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9468
    |xS "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9469
     xE "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9470
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9471
    xS := xStart.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9472
    xE := xEnd.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9473
    yStart to:yEnd do:[:yRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9474
	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
  9475
	    aBlock value:xRun value:yRun value:pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9476
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9477
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9478
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9479
    "Modified: 7.6.1996 / 19:09:29 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  9480
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  9481
3613
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9482
!Image methodsFor:'finalization'!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9483
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9484
finalizationLobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9485
    "answer the registry used for finalization.
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9486
     Images have their own Registry"
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9487
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9488
    ^ Lobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9489
!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9490
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9491
finalize
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9492
    "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
  9493
! !
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
  9494
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  9495
!Image methodsFor:'image manipulations'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  9496
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9497
applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  9498
    "helper for withPixelFunctionAppliedToValues:
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
  9499
     enumerate pixelValues and evaluate the block for each.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9500
     Could be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9501
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9502
    |w   "{Class: SmallInteger }"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9503
     h   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9504
     x0  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9505
     y0  "{Class: SmallInteger }"
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9506
     y   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9507
     newPixel newPixelRow pixelRow|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9508
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9509
    x0 := aRectangle left.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9510
    y0 := aRectangle top.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9511
    w := aRectangle width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9512
    h := aRectangle height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9513
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9514
    newPixelRow := Array new:w.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9515
    pixelRow := self pixelArraySpecies new:width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9516
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9517
    (x0 = 0 and:[w = self width]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9518
	"/ slightly faster
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9519
	y := y0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9520
	h timesRepeat:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9521
	    self rowAt:y into:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9522
	    1 to:w do:[:runCol |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9523
		newPixel := pixelFunctionBlock
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9524
				value:self
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9525
				value:(pixelRow at:runCol)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9526
				value:(runCol-1)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9527
				value:y.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9528
		newPixelRow at:runCol put:newPixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9529
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9530
	    newImage rowAt:y putAll:newPixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9531
	    y := y + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9532
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9533
	^ self.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9534
    ].
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9535
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9536
    y := y0.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9537
    h timesRepeat:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9538
	self rowAt:y into:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9539
	1 to:w do:[:runCol |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9540
	    newPixel := pixelFunctionBlock
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9541
			    value:self
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9542
			    value:(pixelRow at:runCol+x0)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9543
			    value:(runCol+x0-1)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9544
			    value:y.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9545
	    newPixelRow at:runCol put:newPixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9546
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9547
	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
  9548
	newImage rowAt:y putAll:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9549
	y := y + 1.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9550
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9551
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9552
    "Modified: 24.4.1997 / 16:18:31 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9553
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
  9554
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9555
applyPixelValuesTo:pixelFunctionBlock into:newImage
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9556
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9557
     enumerate pixelValues and evaluate the block for each."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9558
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9559
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9560
	applyPixelValuesTo:pixelFunctionBlock
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9561
	in:(0@0 corner:width@height)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9562
	into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9563
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
  9564
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9565
blendWith:aColor
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9566
    "return a new image which is blended with some color.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9567
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9568
     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
  9569
     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
  9570
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9571
     ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9572
	copyWithColorMapProcessing:[:clr | clr blendWith:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9573
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9574
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9575
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9576
     ((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
  9577
     ((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
  9578
     ((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
  9579
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9580
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9581
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9582
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9583
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9584
colorMapProcessing:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9585
    "a helper for all kinds of colormap manipulations.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9586
     The argument, aBlock is called for every colormap entry,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9587
     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
  9588
     This will fail for non-palette images.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9589
     See examples in Image>>copyWithColorMapProcessing:"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9590
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9591
    |nColors "{ Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9592
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9593
    colorMap isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9594
	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
  9595
	    self colorAtX:x y:y put:(aBlock value:clr)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9596
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9597
	^ self
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9598
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9599
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9600
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9601
    1 to:nColors do:[:index |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9602
	|clr|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9603
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9604
	clr := colorMap at:index.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9605
	clr notNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9606
	    colorMap at:index put:(aBlock value:clr)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9607
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9608
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9609
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  9610
    "Modified: 23.4.1996 / 11:13:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9611
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9612
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9613
copyWithColorMapProcessing:aBlock
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9614
    "a helper to create & return new images based on the receiver with
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9615
     some colorMap processing. The receiver is copied, and the copied images
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9616
     colormap is modified by replacing entries with the result of the processing block,
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9617
     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
  9618
     a color.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9619
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale)"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9620
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9621
    |newImage|
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9622
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  9623
    self colorMap isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9624
	^ self withPixelFunctionApplied:[:orig :clr :x :y | aBlock  value:clr]
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  9625
"/        self error:'no colormap in image'.
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  9626
"/        ^ nil
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9627
    ].
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9628
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9629
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9630
     the code below manipulates the colormap.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9631
     For non-palette images, special code is required
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9632
    "
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
  9633
    newImage := self copy.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9634
    newImage colorMapProcessing:aBlock.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9635
    ^ newImage
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9636
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9637
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9638
     leave red component only:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9639
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9640
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9641
	copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9642
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9643
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9644
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9645
     make it reddish:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9646
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9647
     (Image fromFile:'bitmaps/gifImages/claus.gif')
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9648
	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
  9649
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9650
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9651
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9652
     invert:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9653
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9654
     (Image fromFile:'bitmaps/gifImages/claus.gif')
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9655
	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
  9656
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9657
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9658
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9659
     lighter:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9660
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9661
     (Image fromFile:'bitmaps/gifImages/claus.gif')
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9662
	copyWithColorMapProcessing:[:clr | |r g b|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9663
						r := clr red.  g := clr green.  b := clr blue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9664
						Color red:(r + (100-r//2))
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9665
						      green:(g + (100-g//2))
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9666
						      blue:(b + (100-b//2))]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9667
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  9668
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9669
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9670
     darker:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9671
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9672
     (Image fromFile:'bitmaps/gifImages/claus.gif')
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9673
	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
  9674
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9675
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9676
    "Modified: 24.4.1997 / 18:28:05 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9677
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  9678
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  9679
createMask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  9680
    |maskArray bytesPerMaskRow|
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  9681
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  9682
    bytesPerMaskRow := (width+7) // 8.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  9683
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  9684
    maskArray := ByteArray new:(bytesPerMaskRow * height) withAll:2r11111111.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  9685
    mask := ImageMask width:width height:height fromArray:maskArray.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  9686
    ^ mask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  9687
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  9688
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9689
darkened
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9690
    "return a new image which is slightly darker than the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9691
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9692
     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
  9693
     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
  9694
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
  9695
     ^ self copyWithColorMapProcessing:[:clr | clr darkened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9696
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9697
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9698
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
  9699
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9700
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9701
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
  9702
    "Modified: / 24-11-2010 / 11:06:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9703
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9704
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9705
easyRotateBitsInto:destinationImage angle:degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9706
    "helper for rotation - does the actual pixel shuffling.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9707
     by degrees clockwise. Here, only 90, 180 and 270 degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9708
     are implemented. Hard angles are done in #hardRotate:.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9709
     The code here is depth-independent (but not too fast);
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9710
     can be redefined in subclasses for more performance"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9711
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9712
    |w  "{Class: SmallInteger }"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9713
     h  "{Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9714
     c2 r2 pixelArray|
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9715
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9716
    w := width - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9717
    h := height - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9718
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9719
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9720
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9721
    degrees = 90 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9722
	0 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9723
	    self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9724
	    c2 := h-row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9725
	    0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9726
		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
  9727
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9728
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9729
	^ self.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9730
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9731
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9732
    degrees = 180 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9733
	0 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9734
	    self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9735
	    r2 := h - row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9736
	    0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9737
		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
  9738
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9739
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9740
	^ self
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9741
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9742
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9743
    "/ degrees = 270
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9744
    0 to:h do:[:row |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9745
	self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9746
	0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9747
	    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
  9748
	]
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9749
    ]
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9750
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9751
    "Created: 23.4.1997 / 14:36:45 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9752
    "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
  9753
!
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
  9754
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9755
flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9756
    "destructively inplace horizontal flip"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9757
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9758
    |h  "{Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9759
     pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9760
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9761
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9762
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9763
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9764
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9765
    0 to:h do:[:row |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9766
	self rowAt:row into:pixelArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9767
	pixelArray reverse.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9768
	self rowAt:row putAll:pixelArray.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9769
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9770
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9771
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9772
	mask flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9773
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9774
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9775
    "/ flush device info
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9776
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9777
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9778
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9779
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipHorizontal inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9780
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9781
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9782
    "Modified: 24.4.1997 / 18:29:13 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9783
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9784
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9785
flipVertical
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9786
    "inplace vertical flip"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9787
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9788
    |h           "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9789
     bytesPerRow "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9790
     buffer
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9791
     indexLow    "{Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9792
     indexHi     "{Class: SmallInteger }"
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9793
     bytes|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9794
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9795
    bytes := self bits.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9796
    bytesPerRow := self bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9797
    buffer := ByteArray new:bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9798
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9799
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9800
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9801
    indexLow := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9802
    indexHi := bytesPerRow * h + 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9803
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9804
    0 to:(h // 2) do:[:row |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9805
	buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9806
	bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9807
	bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9808
	indexLow := indexLow + bytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9809
	indexHi := indexHi - bytesPerRow.
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9810
    ].
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9811
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9812
	mask flipVertical
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9813
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9814
    "flush device info"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  9815
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
  9816
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9817
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9818
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipVertical inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9819
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9820
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9821
    "Modified: 24.4.1997 / 18:29:36 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9822
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9823
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9824
hardAntiAliasedMagnifiedBy:scalePoint
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9825
    "return a new image magnified and antiAliased by scalePoint, aPoint.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9826
     This converts into a depth24Image before doing the antiAlias-magnify.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9827
     It is definitely slower than the non antiAliasing/integral magnification methods."
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9828
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9829
    ^ (Depth24Image fromImage:self)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9830
	hardAntiAliasedMagnifiedBy:scalePoint
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9831
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9832
    "Modified: 2.6.1997 / 13:19:57 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9833
    "Created: 2.6.1997 / 15:53:34 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9834
!
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
  9835
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9836
hardMagnifiedBy:scalePoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9837
    "return a new image magnified by scalePoint, aPoint.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9838
     This is the general magnification method, handling non-integral values.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9839
     It is slower than the integral magnification method."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9840
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9841
    |mX
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9842
     mY
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9843
     newWidth  "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9844
     newHeight "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9845
     w         "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9846
     h         "{ Class: SmallInteger }"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9847
     newImage newBits bitsPerPixel newBytesPerRow newMask
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9848
     value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9849
     srcRow pixelArray|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9850
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9851
    mX := scalePoint x.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9852
    mY := scalePoint y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9853
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9854
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9855
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9856
    newWidth := (width * mX) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9857
    newHeight := (height * mY) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9858
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9859
    bitsPerPixel := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9860
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9861
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9862
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9863
    mask notNil ifTrue:[
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9864
        newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9865
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  9866
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9867
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9868
    newImage
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9869
        width:newWidth
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9870
        height:newHeight
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9871
        photometric:photometric
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9872
        samplesPerPixel:samplesPerPixel
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9873
        bitsPerSample:bitsPerSample
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9874
        colorMap:colorMap copy
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9875
        bits:newBits
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9876
        mask:newMask.
905
228d503775d9 everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
  9877
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9878
    "walk over destination image fetching pixels from source image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9879
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9880
    w := newWidth - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9881
    h := newHeight - 1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9882
    pixelArray := newImage pixelArraySpecies new:newWidth.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9883
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9884
    0 to:h do:[:row |
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9885
        srcRow := (row // mY).
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9886
        0 to:w do:[:col |
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9887
            value := self pixelAtX:(col // mX) y:srcRow.
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9888
            pixelArray at:(col+1) put:value.
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9889
        ].
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9890
        newImage rowAt:row putAll:pixelArray.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9891
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9892
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9893
    ^ newImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9894
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9895
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9896
     |i|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  9897
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9898
     Time millisecondsToRun:[
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  9899
         i := i hardMagnifiedBy:0.5@0.5
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9900
     ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9901
     i
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9902
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9903
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
  9904
    "Modified: 24.4.1997 / 18:30:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9905
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9906
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9907
hardRotated:degrees
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9908
    "return a new image from the old one, by rotating the image
4953
b5017336aa26 comment
Claus Gittinger <cg@exept.de>
parents: 4952
diff changeset
  9909
     degrees clockwise (around its center).
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9910
     Warning: the returned image will be larger than the original image."
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9911
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9912
    |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
  9913
     newImage
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9914
     newWidth  "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9915
     newHeight "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9916
     newBytesPerRow newBits
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9917
     blackPixel halfW halfH radians m t bad
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9918
     bytesPerRow myDepth maskBits
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9919
     pX pY srcX srcY pix nX nY
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9920
     sinRot cosRot sinPY cosPY|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
  9921
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9922
    radians := degrees degreesToRadians.
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9923
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9924
    "/ placing the image at the origin,
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9925
    "/ compute the diagonal and angle.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9926
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9927
    p := (width - 1 / 2) @ (height - 1 / 2).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9928
    r := p r.
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9929
    a := p theta.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9930
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9931
    "/ add the rotation
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9932
    "/ (sight - subtract, we defined things clockwise ...
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9933
    "/  ... in contrast to point which thinks counter-clockwise)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9934
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9935
    aN := a - radians.
1638
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
    "/ compute new corner points
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9938
    p1 := Point r:r theta:aN.         "/ rotated topRight
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
  9939
    p2 := Point r:r theta:aN-a-a.     "/ rotated bottomRight
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9940
    p3 := p1 * -1.                    "/ rotated bottomLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9941
    p4 := p2 * -1.                    "/ rotated topLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9942
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9943
    "/ compute the boundary of the new image
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9944
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9945
    maxX := minX := p1 x.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9946
    (t := p2 x) > maxX ifTrue:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9947
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9948
    ] ifFalse:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9949
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9950
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9951
    (t := p3 x) > maxX ifTrue:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9952
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9953
    ] ifFalse:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9954
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9955
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9956
    (t := p4 x) > maxX ifTrue:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9957
        maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9958
    ] ifFalse:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9959
        t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9960
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9961
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9962
    maxY := minY := p1 y.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9963
    (t := p2 y) > maxY ifTrue:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9964
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9965
    ] ifFalse:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9966
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9967
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9968
    (t := p3 y) > maxY ifTrue:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9969
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9970
    ] ifFalse:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9971
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9972
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9973
    (t := p4 y) > maxY ifTrue:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9974
        maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9975
    ] ifFalse:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9976
        t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9977
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9978
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9979
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9980
    newWidth := (maxX - minX) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9981
    newHeight := (maxY - minY) rounded + 1.
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 := self species new.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9984
    newImage width:newWidth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9985
    newImage height:newHeight.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9986
    newBytesPerRow := newImage bytesPerRow.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  9987
    newImage createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  9988
    newBits := newImage bits.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9989
    newImage photometric:photometric.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9990
    newImage samplesPerPixel:samplesPerPixel.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9991
    newImage bitsPerSample:bitsPerSample.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9992
    newImage colorMap:colorMap copy.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9993
    newImage maskedPixelsAre0:maskedPixelsAre0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9994
    mask notNil ifTrue:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9995
        newImage mask:(mask rotated:degrees)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
  9996
    ] ifFalse:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9997
        self isMask ifFalse:[
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9998
            self depth ~~ 1 ifTrue:[
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
  9999
                m := ImageMask width:width height:height.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10000
                m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10001
                maskBits atAllPut:16rFF.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10002
                newImage mask:(m rotated:degrees)
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10003
            ]
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10004
        ]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10005
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10006
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10007
    myDepth := self depth.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10008
    myDepth == 1 ifTrue:[
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10009
        blackPixel := 0.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10010
    ] ifFalse:[
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10011
        maskedPixelsAre0 ifTrue:[
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10012
            blackPixel := 0.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10013
        ] ifFalse:[
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10014
            blackPixel := self valueFromColor:Color black.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10015
            blackPixel isNil ifTrue:[
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10016
                blackPixel := self valueFromColor:Color white.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10017
                blackPixel isNil ifTrue:[
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10018
                    blackPixel := 0.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10019
                ]
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10020
            ]
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10021
        ].
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10022
        self isMask ifTrue:[
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10023
            blackPixel := 0.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10024
        ].
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10025
    ].
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10026
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10027
    newBits atAllPut:0.
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
    "/ now, walk over destination pixels,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10030
    "/ fetching from source.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10031
    "/ (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
 10032
    "/  in the destination image ...)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10033
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10034
    halfW := (width - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10035
    halfH := (height - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10036
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10037
    bytesPerRow := self bytesPerRow.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10038
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10039
%{
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10040
    int __newHeight = __intVal(newHeight);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10041
    int __newWidth = __intVal(newWidth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10042
    int __height = __intVal(__INST(height));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10043
    int __width = __intVal(__INST(width));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10044
    double __minX, __minY, __radians;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10045
    double __halfW, __halfH;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10046
    int __dstX, __dstY;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10047
    int __depth = __intVal(myDepth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10048
    unsigned char *__srcBytes, *__dstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10049
    unsigned char *__dstPtr, *__dstRowPtr, *__dstEndPtr;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10050
    int __nSrcBytes, __nDstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10051
    int __srcBytesPerRow = __intVal(bytesPerRow);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10052
    int __dstBytesPerRow = __intVal(newBytesPerRow);
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10053
    int __dstMask, __blackPixel;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10054
    double __sin, __cos;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10055
    double sin(), cos();
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10056
#   define Float_PI 3.14159
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10057
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10058
    bad = true;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10059
    if (1
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10060
     && __isFloat(minX)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10061
     && __isFloat(minY)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10062
     && __isFloat(radians)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10063
     && __isFloat(halfW)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10064
     && __isFloat(halfH)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10065
     && __isByteArray(newBits)
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 10066
     && __isByteArrayLike(__INST(bytes))) {
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10067
        __srcBytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10068
        __dstBytes = __ByteArrayInstPtr(newBits)->ba_element;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10069
        __nSrcBytes = __byteArraySize(__INST(bytes));
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10070
        __nDstBytes = __byteArraySize(newBits);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10071
        __blackPixel = __intVal(blackPixel);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10072
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10073
        __radians = __floatVal(radians);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10074
        __radians = -__radians; /* sigh: clock-wise */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10075
        __sin = sin(__radians);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10076
        __cos = cos(__radians);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10077
        __minX = __floatVal(minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10078
        __minY = __floatVal(minY);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10079
        __halfW = __floatVal(halfW);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10080
        __halfH = __floatVal(halfH);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10081
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10082
        __dstRowPtr = __dstBytes;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10083
        __dstEndPtr = __dstBytes + __nDstBytes;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10084
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10085
#       define EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10086
#       define FAST_ADVANCE 5
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10087
#       define FAST_ADVANCE2
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10088
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10089
        switch (__depth) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10090
            case 8:
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10091
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10092
                    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10093
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10094
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10095
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10096
                    __pY = (double)(__dstY + __minY);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10097
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10098
                    __sinPY = __sin * __pY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10099
                    __cosPY = __cos * __pY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10100
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10101
                    __dstPtr = __dstRowPtr;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10102
                    __dstRowPtr += __dstBytesPerRow;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10103
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10104
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10105
                        double __pX, __nX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10106
                        unsigned __pix;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10107
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10108
                        /* translate X in destination (center to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10109
                        __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10110
                        /* rotate X */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10111
                        __nX = (__cos * __pX) - __sinPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10112
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10113
                        /* translate X in source (origin to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10114
                        __nX = __nX + __halfW + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10115
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10116
                        /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10117
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10118
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10119
                            if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10120
                                break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10121
                            }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10122
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10123
#ifdef FAST_ADVANCE
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10124
                            if (__blackPixel == 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10125
                                do {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10126
                                    /* try advance by FAST_ADVANCE pixels ... */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10127
                                    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10128
                                    if (__dstX >= __newWidth) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10129
                                        break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10130
                                    }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10131
                                    __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10132
                                    __nX = (__cos * __pX) - __sinPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10133
                                    __nX = __nX + __halfW + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10134
                                } while (__nX < 0);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10135
                                __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10136
                            }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10137
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10138
                            __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10139
                        } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10140
                            int __srcX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10141
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10142
                            __srcX = (int)__nX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10143
                            /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10144
                            if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10145
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10146
                                if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10147
                                    break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10148
                                }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10149
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10150
#ifdef FAST_ADVANCE2
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10151
                                if (__blackPixel == 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10152
                                    do {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10153
                                        /* try advance by FAST_ADVANCE pixels ... */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10154
                                        __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10155
                                        if (__dstX >= __newWidth) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10156
                                            break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10157
                                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10158
                                        __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10159
                                        __nX = (__cos * __pX) - __sinPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10160
                                        __nX = __nX + __halfW + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10161
                                        __srcX = (int)__nX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10162
                                    } while (__srcX >= __width);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10163
                                    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10164
                                }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10165
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10166
                                __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10167
                            } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10168
                                double __nY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10169
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10170
                                /* rotate Y */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10171
                                __nY = (__sin * __pX) + __cosPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10172
                                /* translate Y in source (origin to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10173
                                __nY = __nY + __halfH + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10174
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10175
                                /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10176
                                if (__nY < 0) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10177
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10178
                                    if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10179
                                        break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10180
                                    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10181
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10182
#ifdef FAST_ADVANCE2
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10183
                                    if (__blackPixel == 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10184
                                        do {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10185
                                            /* try advance by FAST_ADVANCE pixels ... */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10186
                                            __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10187
                                            if (__dstX >= __newWidth) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10188
                                                break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10189
                                            }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10190
                                            __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10191
                                            __nY = (__sin * __pX) + __cosPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10192
                                            __nY = __nY + __halfH + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10193
                                        } while (__nY < 0);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10194
                                        __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10195
                                    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10196
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10197
                                    __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10198
                                } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10199
                                    int __srcY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10200
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10201
                                    __srcY = (int)__nY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10202
                                    /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10203
                                    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10204
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10205
                                        if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10206
                                            break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10207
                                        }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10208
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10209
#ifdef FAST_ADVANCE
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10210
                                        if (__blackPixel == 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10211
                                            do {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10212
                                                /* try advance by FAST_ADVANCE pixels ... */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10213
                                                __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10214
                                                if (__dstX >= __newWidth) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10215
                                                    break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10216
                                                }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10217
                                                __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10218
                                                __nY = (__sin * __pX) + __cosPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10219
                                                __nY = __nY + __halfH + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10220
                                                __srcY = (int)__nY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10221
                                            } while (__srcY >= __height);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10222
                                            __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10223
                                        }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10224
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10225
                                        __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10226
                                    } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10227
                                        /* fetch source pixel */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10228
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10229
                                        int idx;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10230
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10231
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10232
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10233
                                        idx = __srcY * __srcBytesPerRow + __srcX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10234
                                        if ((unsigned)idx < __nSrcBytes) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10235
                                            __pix = __srcBytes[idx];
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10236
                                        } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10237
                                            __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10238
                                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10239
                                    }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10240
                                }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10241
                            }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10242
                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10243
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10244
                        if (__pix != 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10245
                            *__dstPtr = __pix;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10246
                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10247
                        __dstPtr++;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10248
                    }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10249
                }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10250
                break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10251
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10252
            case 1:
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10253
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10254
                    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10255
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10256
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10257
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10258
                    __pY = (double)(__dstY + __minY);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10259
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10260
                    __sinPY = __sin * __pY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10261
                    __cosPY = __cos * __pY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10262
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10263
                    __dstPtr = __dstRowPtr;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10264
                    __dstMask = 0x80;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10265
                    __dstRowPtr += __dstBytesPerRow;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10266
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10267
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10268
                        double __pX, __nX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10269
                        int __pix;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10270
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10271
                        /* translate X in destination (center to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10272
                        __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10273
                        /* rotate X */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10274
                        __nX = (__cos * __pX) - __sinPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10275
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10276
                        /* translate X in source (origin to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10277
                        __nX = __nX + __halfW + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10278
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10279
                        /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10280
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10281
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10282
                            if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10283
                                break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10284
                            }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10285
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10286
#ifdef FAST_ADVANCE
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10287
                            if (__blackPixel == 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10288
                                do {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10289
                                    /* try advance by 8 pixels ... */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10290
                                    __dstX += 8; __dstPtr ++;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10291
                                    if (__dstX >= __newWidth) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10292
                                        break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10293
                                    }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10294
                                    __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10295
                                    __nX = (__cos * __pX) - __sinPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10296
                                    __nX = __nX + __halfW + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10297
                                } while (__nX < 0);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10298
                                __dstX -= 8; __dstPtr--;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10299
                            }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10300
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10301
                            __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10302
                        } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10303
                            int __srcX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10304
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10305
                            __srcX = (int)__nX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10306
                            /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10307
                            if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10308
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10309
                                if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10310
                                    break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10311
                                }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10312
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10313
#ifdef FAST_ADVANCE2
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10314
                                if (__blackPixel == 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10315
                                    do {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10316
                                        /* try advance by 8 pixels ... */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10317
                                        __dstX += 8; __dstPtr++;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10318
                                        if (__dstX >= __newWidth) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10319
                                            break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10320
                                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10321
                                        __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10322
                                        __nX = (__cos * __pX) - __sinPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10323
                                        __nX = __nX + __halfW + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10324
                                        __srcX = (int)__nX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10325
                                    } while (__srcX >= __width);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10326
                                    __dstX -= 8; __dstPtr--;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10327
                                }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10328
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10329
                                __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10330
                            } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10331
                                double __nY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10332
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10333
                                /* rotate Y */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10334
                                __nY = (__sin * __pX) + __cosPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10335
                                /* translate Y in source (origin to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10336
                                __nY = __nY + __halfH + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10337
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10338
                                /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10339
                                if (__nY < 0) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10340
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10341
                                    if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10342
                                        break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10343
                                    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10344
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10345
#ifdef FAST_ADVANCE2
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10346
                                    if (__blackPixel == 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10347
                                        do {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10348
                                            /* try advance by 8 pixels ... */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10349
                                            __dstX += 8; __dstPtr++;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10350
                                            if (__dstX >= __newWidth) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10351
                                                break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10352
                                            }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10353
                                            __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10354
                                            __nY = (__sin * __pX) + __cosPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10355
                                            __nY = __nY + __halfH + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10356
                                        } while (__nY < 0);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10357
                                        __dstX -= 8; __dstPtr--;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10358
                                    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10359
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10360
                                    __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10361
                                } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10362
                                    int __srcY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10363
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10364
                                    __srcY = (int)__nY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10365
                                    /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10366
                                    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10367
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10368
                                        if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10369
                                            break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10370
                                        }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10371
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10372
#ifdef FAST_ADVANCE
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10373
                                        if (__blackPixel == 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10374
                                            do {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10375
                                                /* try advance by 8 pixels ... */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10376
                                                __dstX += 8; __dstPtr++;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10377
                                                if (__dstX >= __newWidth) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10378
                                                    break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10379
                                                }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10380
                                                __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10381
                                                __nY = (__sin * __pX) + __cosPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10382
                                                __nY = __nY + __halfH + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10383
                                                __srcY = (int)__nY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10384
                                            } while (__srcY >= __height);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10385
                                            __dstX -= 8; __dstPtr--;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10386
                                        }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10387
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10388
                                        __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10389
                                    } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10390
                                        /* fetch source pixel */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10391
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10392
                                        int idx, pV;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10393
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10394
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10395
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10396
                                        idx = __srcY * __srcBytesPerRow + (__srcX >> 3);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10397
                                        if ((unsigned)idx < __nSrcBytes) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10398
                                            pV = __srcBytes[idx];
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10399
                                            __pix = (pV & (0x80 >> (__srcX & 7))) ? 1 : 0;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10400
                                        } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10401
                                            __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10402
                                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10403
                                    }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10404
                                }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10405
                            }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10406
                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10407
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10408
                        /* store pixel */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10409
                        if (__pix != 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10410
                            *__dstPtr |= __dstMask;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10411
                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10412
                        __dstMask >>= 1;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10413
                        if (__dstMask == 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10414
                            __dstMask = 0x80;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10415
                            __dstPtr++;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10416
                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10417
                    }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10418
                }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10419
                break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10420
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10421
            case 24:
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10422
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10423
                    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10424
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10425
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10426
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10427
                    __pY = (double)(__dstY + __minY);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10428
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10429
                    __sinPY = __sin * __pY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10430
                    __cosPY = __cos * __pY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10431
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10432
                    __dstPtr = __dstRowPtr;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10433
                    __dstRowPtr += __dstBytesPerRow;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10434
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10435
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10436
                        double __pX, __nX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10437
                        unsigned __pix;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10438
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10439
                        /* translate X in destination (center to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10440
                        __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10441
                        /* rotate X */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10442
                        __nX = (__cos * __pX) - __sinPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10443
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10444
                        /* translate X in source (origin to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10445
                        __nX = __nX + __halfW + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10446
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10447
                        /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10448
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10449
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10450
                            if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10451
                                break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10452
                            }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10453
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10454
                            __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10455
                        } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10456
                            int __srcX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10457
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10458
                            __srcX = (int)__nX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10459
                            /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10460
                            if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10461
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10462
                                if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10463
                                    break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10464
                                }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10465
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10466
                                __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10467
                            } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10468
                                double __nY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10469
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10470
                                /* rotate Y */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10471
                                __nY = (__sin * __pX) + __cosPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10472
                                /* translate Y in source (origin to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10473
                                __nY = __nY + __halfH + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10474
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10475
                                /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10476
                                if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10477
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10478
                                    if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10479
                                        break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10480
                                    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10481
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10482
                                    __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10483
                                } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10484
                                    int __srcY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10485
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10486
                                    __srcY = (int)__nY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10487
                                    /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10488
                                    if (__srcY >= __height) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10489
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10490
                                        if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10491
                                            break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10492
                                        }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10493
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10494
                                        __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10495
                                    } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10496
                                        /* fetch source pixel */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10497
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10498
                                        int idx;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10499
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10500
                                        didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10501
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10502
                                        idx = __srcY * __srcBytesPerRow + __srcX + __srcX + __srcX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10503
                                        if ((unsigned)idx < __nSrcBytes) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10504
                                            __pix = __srcBytes[idx];
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10505
                                            __pix = (__pix<<8) | __srcBytes[idx+1];
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10506
                                            __pix = (__pix<<8) | __srcBytes[idx+2];
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10507
                                        } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10508
                                            __pix = __blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10509
                                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10510
                                    }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10511
                                }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10512
                            }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10513
                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10514
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10515
                        /* store pixel */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10516
                        if (__pix != 0) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10517
                            __dstPtr[0] = (__pix >> 16 & 0xFF);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10518
                            __dstPtr[1] = (__pix >> 8) & 0xFF;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10519
                            __dstPtr[2] = __pix & 0xFF;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10520
                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10521
                        __dstPtr += 3;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10522
                    }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10523
                }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10524
                break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10525
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10526
            default:
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10527
                for (__dstY = 0; __dstY < __newHeight; __dstY++) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10528
                    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10529
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10530
                    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10531
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10532
                    __pY = (double)(__dstY + __minY);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10533
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10534
                    __sinPY = __sin * __pY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10535
                    __cosPY = __cos * __pY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10536
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10537
                    __dstPtr = __dstRowPtr;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10538
                    __dstMask = 0x80;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10539
                    __dstRowPtr += __dstBytesPerRow;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10540
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10541
                    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10542
                        double __pX, __nX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10543
                        OBJ __pix;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10544
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10545
                        /* translate X in destination (center to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10546
                        __pX = (double)(__dstX + __minX);
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10547
                        /* rotate X */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10548
                        __nX = (__cos * __pX) - __sinPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10549
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10550
                        /* translate X in source (origin to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10551
                        __nX = __nX + __halfW + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10552
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10553
                        /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10554
                        if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10555
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10556
                            if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10557
                                break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10558
                            }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10559
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10560
                            __pix = blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10561
                        } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10562
                            int __srcX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10563
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10564
                            __srcX = (int)__nX;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10565
                            /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10566
                            if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10567
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10568
                                if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10569
                                    break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10570
                                }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10571
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10572
                                __pix = blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10573
                            } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10574
                                double __nY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10575
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10576
                                /* rotate Y */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10577
                                __nY = (__sin * __pX) + __cosPY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10578
                                /* translate Y in source (origin to 0/0) */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10579
                                __nY = __nY + __halfH + 0.5;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10580
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10581
                                /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10582
                                if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10583
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10584
                                    if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10585
                                        break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10586
                                    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10587
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10588
                                    __pix = blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10589
                                } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10590
                                    int __srcY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10591
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10592
                                    __srcY = (int)__nY;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10593
                                    /* inside ? */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10594
                                    if (__srcY >= __height) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10595
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10596
                                        if (didFetchInRow) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10597
                                            break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10598
                                        }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10599
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10600
                                        __pix = blackPixel;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10601
                                    } else {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10602
                                        /* fetch source pixel */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10603
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10604
                                        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
 10605
#ifdef EARLY_OUT
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10606
                                        didFetchInRow = 1;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10607
#endif
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10608
                                        __pix = (*valAt.ilc_func)(self,
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10609
                                                              @symbol(pixelAtX:y:),
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10610
                                                              nil, &valAt,
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10611
                                                              __MKSMALLINT(__srcX),
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10612
                                                              __MKSMALLINT(__srcY));
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10613
                                    }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10614
                                }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10615
                            }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10616
                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10617
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10618
                        /* store pixel */
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10619
                        {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10620
                            static struct inlineCache atPutVal = _ILC3;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10621
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10622
                            if (__pix != __MKSMALLINT(0)) {
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10623
                                (*atPutVal.ilc_func)(newImage,
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10624
                                                      @symbol(pixelAtX:y:put:),
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10625
                                                      nil, &atPutVal,
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10626
                                                      __MKSMALLINT(__dstX),
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10627
                                                      __MKSMALLINT(__dstY),
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10628
                                                      __pix
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10629
                                                     );
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10630
                            }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10631
                        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10632
                    }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10633
                }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10634
                break;
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10635
        }
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10636
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10637
        bad = false;
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10638
    }
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10639
%}.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10640
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10641
    bad ifTrue:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10642
        "/ should not happen
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10643
        self primitiveFailed
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10644
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10645
"/        sinRot := radians negated sin.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10646
"/        cosRot := radians negated cos.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10647
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10648
"/        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
 10649
"/            pY := (dstY + minY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10650
"/            sinPY := (sinRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10651
"/            cosPY := (cosRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10652
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10653
"/            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
 10654
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10655
"/                "/ translate center to origin
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10656
"/                pX := (dstX + minX).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10657
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10658
"/                nX := (cosRot * pX) - sinPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10659
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10660
"/                "/ translate in source
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10661
"/                srcX := nX + halfW.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10662
"/                srcX := srcX rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10663
"/                "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10664
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10665
"/                (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
 10666
"/                    nY := (sinRot * pX) + cosPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10667
"/                    srcY := nY + halfH.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10668
"/                    srcY := srcY rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10669
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10670
"/                    "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10671
"/                    (srcY >= 0 and:[srcY < height]) ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10672
"/                        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
 10673
"/                    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10674
"/                        pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10675
"/                    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10676
"/                ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10677
"/                    pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10678
"/                ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10679
"/                pix ~~ blackPixel ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10680
"/                    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
 10681
"/                ]
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10682
"/            ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10683
"/        ].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10684
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10685
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10686
    ^ newImage
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10687
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10688
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10689
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10690
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10691
     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
 10692
     i inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10693
     (i rotated:45) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10694
     (i rotated:90) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10695
     (i rotated:91) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10696
     (i rotated:95) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10697
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10698
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10699
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10700
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10701
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10702
     i := Depth24Image fromImage:i.
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10703
     (i rotated:200) inspect
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10704
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10705
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10706
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10707
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10708
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10709
     Transcript showCR:(
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10710
        Time millisecondsToRun:[
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10711
           i rotated:45.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10712
        ]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10713
     ).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10714
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10715
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10716
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10717
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10718
     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
 10719
     v := View new extent:(i width max:100)@(i height max:100).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10720
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10721
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10722
     [true] whileTrue:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10723
        rI := i rotated:rot.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10724
        rI := rI onDevice:v device.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10725
        v clear.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10726
        v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10727
        rot := rot + 5.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10728
        rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10729
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10730
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10731
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10732
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10733
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10734
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10735
     v := View new extent:400@400.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10736
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10737
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10738
     [true] whileTrue:[
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10739
        rI := i rotated:rot.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10740
        rI := rI onDevice:v device.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10741
        v clear.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10742
        v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10743
        rot := rot + 5.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10744
        rI close.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10745
     ]
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10746
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10747
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10748
     |v i rI rot|
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10749
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10750
     i := Form width:200 height:100 onDevice:Screen current.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10751
     i clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10752
     i displayLineFrom:(0@0) to:(199@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10753
     i displayLineFrom:(199@0) to:(199@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10754
     i displayLineFrom:(199@99) to:(0@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10755
     i displayLineFrom:(0@99) to:(0@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10756
     i displayLineFrom:(0@0) to:(199@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10757
     i displayLineFrom:(199@0) to:(0@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10758
     i := Image fromForm:i.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10759
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10760
     v := View new extent:400@400.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10761
     v openAndWait.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10762
     rot := 0.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10763
     [true] whileTrue:[
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10764
        rI := i rotated:rot.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10765
        rI := rI onDevice:v device.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10766
        v clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10767
        v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10768
        rot := rot + 5.
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10769
        rI close.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10770
        Delay waitForSeconds:0.1.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10771
     ]
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10772
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10773
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10774
     |v i rI rot|
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10775
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10776
     i := Form width:200 height:100 onDevice:Screen current.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10777
     i clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10778
     i displayLineFrom:(0@0) to:(199@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10779
     i displayLineFrom:(199@0) to:(199@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10780
     i displayLineFrom:(199@99) to:(0@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10781
     i displayLineFrom:(0@99) to:(0@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10782
     i displayLineFrom:(0@0) to:(199@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10783
     i displayLineFrom:(199@0) to:(0@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10784
     i := Image fromForm:i.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10785
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10786
     v := View new extent:400@400.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10787
     v openAndWait.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10788
     rot := 0.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10789
     [true] whileTrue:[
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10790
        rI := i rotated:rot.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10791
        rI := rI onDevice:v device.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10792
        v clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10793
        v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10794
        rot := rot + 30.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10795
        rI close.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 10796
        Delay waitForSeconds:0.3.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10797
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10798
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10799
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10800
    "Modified: 22.4.1997 / 17:36:37 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10801
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10802
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 10803
lightened
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10804
    "return a new image which is slightly brighter than the receiver.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10805
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10806
     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
 10807
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 10808
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 10809
    ^ self copyWithColorMapProcessing:[:clr | clr lightened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10810
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10811
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10812
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10813
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10814
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10815
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10816
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10817
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 10818
    "Modified: / 24-11-2010 / 11:17:55 / cg"
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 10819
!
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 10820
134
claus
parents: 132
diff changeset
 10821
magnifiedBy:scale
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10822
    "return a new image magnified by scalePoint, aPoint.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 10823
     If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:'
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 10824
     while simple (integral) magnifications are handled here."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10825
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10826
    |scalePoint mX mY
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10827
     magX      "{ Class: SmallInteger }"   "new version of stc can find this out itself..."
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10828
     magY      "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10829
     srcOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10830
     dstOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10831
     w         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10832
     h         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10833
     first
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10834
     newWidth newHeight newImage newBits newMask
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10835
     bitsPerPixel newBytesPerRow oldBytesPerRow
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10836
     bytes|
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10837
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10838
    scalePoint := scale asPoint.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 10839
    mX := scalePoint x.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 10840
    mY := scalePoint y.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10841
    ((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10842
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
48194c26a46c Initial revision
claus
parents:
diff changeset
 10843
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 10844
    ((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10845
	^ self hardMagnifiedBy:scalePoint
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10846
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10847
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10848
    bytes := self bits.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 10849
    bitsPerPixel := self depth.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10850
    oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 10851
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10852
    w := width.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10853
    h := height.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10854
    magX := mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10855
    magY := mY.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 10856
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 10857
    newWidth := w * magX.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 10858
    newHeight := h * magY.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10859
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 10860
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
48194c26a46c Initial revision
claus
parents:
diff changeset
 10861
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10862
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10863
	newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10864
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10865
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10866
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10867
    newImage
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10868
	width:newWidth
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10869
	height:newHeight
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10870
	photometric:photometric
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10871
	samplesPerPixel:samplesPerPixel
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10872
	bitsPerSample:bitsPerSample
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10873
	colorMap:colorMap copy
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10874
	bits:newBits
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10875
	mask:newMask.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10876
48194c26a46c Initial revision
claus
parents:
diff changeset
 10877
    mX = 1 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10878
	"expand rows only"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10879
	srcOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10880
	dstOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10881
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10882
	1 to:h do:[:row |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10883
	    1 to:magY do:[:i |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10884
		newBits replaceFrom:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10885
			to:(dstOffset + oldBytesPerRow - 1)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10886
			with:bytes
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10887
			startingAt:srcOffset.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10888
		dstOffset := dstOffset + newBytesPerRow
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10889
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10890
	    srcOffset := srcOffset + oldBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10891
	].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10892
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10893
	"expand cols"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10894
	(mX > 1) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10895
	    dstOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10896
	    srcOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10897
	    1 to:h do:[:row |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10898
		self magnifyRowFrom:bytes
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10899
		     offset:srcOffset
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10900
		     into:newBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10901
		     offset:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10902
		     factor:mX.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10903
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10904
		first := dstOffset.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10905
		dstOffset := dstOffset + newBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10906
		" and copy for row expansion "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10907
		2 to:magY do:[:i |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10908
		    newBits replaceFrom:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10909
			    to:(dstOffset + newBytesPerRow - 1)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10910
			    with:newBits
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10911
			    startingAt:first.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10912
		    dstOffset := dstOffset + newBytesPerRow
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10913
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10914
		srcOffset := srcOffset + oldBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10915
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10916
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10917
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
 10918
    ^ newImage
48194c26a46c Initial revision
claus
parents:
diff changeset
 10919
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10920
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10921
     ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') magnifiedBy:1@2)
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10922
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10923
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10924
    "Modified: 24.4.1997 / 18:32:04 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 10925
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 10926
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10927
magnifiedPreservingRatioTo:anExtent
154
claus
parents: 153
diff changeset
 10928
    "return a new image magnified to fit into anExtent,
claus
parents: 153
diff changeset
 10929
     preserving the receivers width/height ratio.
claus
parents: 153
diff changeset
 10930
     (i.e. not distorting the image).
claus
parents: 153
diff changeset
 10931
     See also #magnifiedTo: and #magnifiedBy:"
claus
parents: 153
diff changeset
 10932
claus
parents: 153
diff changeset
 10933
    |rX rY|
claus
parents: 153
diff changeset
 10934
claus
parents: 153
diff changeset
 10935
    rX := anExtent x / self width.
claus
parents: 153
diff changeset
 10936
    rY := anExtent y / self height.
claus
parents: 153
diff changeset
 10937
    ^ self magnifiedBy:(rX min:rY)
claus
parents: 153
diff changeset
 10938
claus
parents: 153
diff changeset
 10939
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10940
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
154
claus
parents: 153
diff changeset
 10941
claus
parents: 153
diff changeset
 10942
    in contrast to:
claus
parents: 153
diff changeset
 10943
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10944
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 10945
    "
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 10946
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 10947
    "Modified: 22.4.1997 / 12:33:46 / cg"
154
claus
parents: 153
diff changeset
 10948
!
claus
parents: 153
diff changeset
 10949
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10950
magnifiedTo:anExtent
154
claus
parents: 153
diff changeset
 10951
    "return a new image magnified to have the size specified by extent.
claus
parents: 153
diff changeset
 10952
     This may distort the image if the arguments ratio is not the images ratio.
claus
parents: 153
diff changeset
 10953
     See also #magnifiedPreservingRatioTo: and #magnifiedBy:"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10954
134
claus
parents: 132
diff changeset
 10955
    ^ self magnifiedBy:(anExtent / self extent)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10956
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10957
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 10958
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
154
claus
parents: 153
diff changeset
 10959
claus
parents: 153
diff changeset
 10960
    in contrast to:
claus
parents: 153
diff changeset
 10961
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 10962
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10963
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10964
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10965
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10966
mixed:amount with:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10967
    "return a new image which is blended with some color;
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10968
     amount determines how much of the blending color is applied (0..)
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10969
     where 0 means: blending color pure.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10970
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10971
     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
 10972
     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
 10973
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10974
     ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10975
	copyWithColorMapProcessing:[:clr | clr mixed:amount with:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10976
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10977
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10978
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10979
     ((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
 10980
     ((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
 10981
     ((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
 10982
     ((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
 10983
     ((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
 10984
     ((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
 10985
     ((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
 10986
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10987
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10988
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10989
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10990
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10991
negative
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10992
    "return a new image which is a negative of the receiver.
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10993
     The receiver must be a palette image (currently)."
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 10994
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10995
    |newImage|
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10996
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 10997
    colorMap isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10998
	photometric == #blackIs0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 10999
	    newImage := self copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11000
	    newImage photometric:#whiteIs0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11001
	    ^ newImage
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11002
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11003
	photometric == #whiteIs0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11004
	    newImage := self copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11005
	    newImage photometric:#blackIs0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11006
	    ^ newImage
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11007
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11008
	^ nil
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11009
    ].
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11010
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11011
     ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11012
	copyWithColorMapProcessing:[:clr |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11013
		|newColor|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11014
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11015
		newColor := Color
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11016
				redByte:(255 - clr redByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11017
				greenByte:(255 - clr greenByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11018
				blueByte:(255 - clr blueByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11019
	]
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11020
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11021
    "
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11022
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11023
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') negative inspect
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11024
    "
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11025
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11026
    "Created: 20.6.1997 / 13:13:41 / cg"
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11027
    "Modified: 20.6.1997 / 13:17:50 / cg"
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11028
!
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11029
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11030
rotated:degrees
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11031
    "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
 11032
     degrees clockwise.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11033
     Notice, that the resulting image has a different extent.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11034
     If rotation is heavily used, the workHorse methods
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11035
     (#easyRotateBitsInto:angle: and #hardRotateBitsInto:angle) may
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11036
     be redefined in concrete image subclasses."
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11037
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11038
    |nW nH newImage d|
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11039
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11040
    d := degrees.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11041
    [d < 0] whileTrue:[d := d + 360].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11042
    d >= 360 ifTrue:[d := d \\ 360].
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11043
    d := d truncated.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11044
    d = 0 ifTrue:[^ self].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11045
    ((d ~= 90) and:[(d ~= 270) and:[d ~= 180]]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11046
	^ self hardRotated:d
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11047
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11048
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11049
    d = 180 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11050
	nW := width.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11051
	nH := height.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11052
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11053
	nW := height.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11054
	nH := width.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11055
    ].
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11056
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11057
    newImage := self species new.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11058
    newImage width:nW.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11059
    newImage height:nH.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11060
    newImage createPixelStore.
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11061
    newImage photometric:photometric.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11062
    newImage samplesPerPixel:samplesPerPixel.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11063
    newImage bitsPerSample:bitsPerSample.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11064
    newImage colorMap:colorMap copy.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11065
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11066
	newImage mask:(mask rotated:degrees)
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11067
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11068
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11069
    self easyRotateBitsInto:newImage angle:d.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11070
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11071
    ^ newImage
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11072
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11073
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11074
     |i|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11075
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11076
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11077
     i inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11078
     (i rotated:45) inspect.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11079
     (i rotated:90) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11080
     (i rotated:180) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11081
     (i rotated:270) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11082
    "
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11083
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11084
     |i|
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11085
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11086
     i := Image fromFile:'goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11087
     i inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11088
     (i rotated:90) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11089
     (i rotated:180) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11090
     (i rotated:270) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11091
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11092
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11093
    "Modified: 24.4.1997 / 18:33:42 / cg"
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11094
!
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11095
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11096
threeDProjected:fraction1 and:fraction2
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11097
    "return a 3D-projected version"
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11098
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11099
    |dx1 dx2 newImage newBytesPerRow newBits
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11100
     blackPixel halfW halfH m myDepth maskBits pix fr fl ml mr dm fractX my fy dstY o1 o2 df|
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11101
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11102
    newImage := self species new.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11103
    newImage width:width.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11104
    newImage height:height.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11105
    newBytesPerRow := newImage bytesPerRow.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11106
    newImage createPixelStore.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11107
    newBits := newImage bits.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11108
    newImage photometric:photometric.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11109
    newImage samplesPerPixel:samplesPerPixel.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11110
    newImage bitsPerSample:bitsPerSample.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11111
    newImage colorMap:colorMap copy.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11112
    newImage maskedPixelsAre0:maskedPixelsAre0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11113
    mask notNil ifTrue:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11114
        newImage mask:(mask threeDProjected:fraction1 and:fraction2)
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11115
    ] ifFalse:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11116
        self isMask ifFalse:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11117
            self depth ~~ 1 ifTrue:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11118
                m := ImageMask width:width height:height.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11119
                m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11120
                maskBits atAllPut:16rFF.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11121
                newImage mask:(m threeDProjected:fraction1 and:fraction2)
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11122
            ]
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11123
        ]
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11124
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11125
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11126
    myDepth := self depth.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11127
    myDepth == 1 ifTrue:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11128
        blackPixel := 0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11129
    ] ifFalse:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11130
        maskedPixelsAre0 ifTrue:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11131
            blackPixel := 0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11132
        ] ifFalse:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11133
            blackPixel := self valueFromColor:Color black.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11134
            blackPixel isNil ifTrue:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11135
                blackPixel := self valueFromColor:Color white.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11136
                blackPixel isNil ifTrue:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11137
                    blackPixel := 0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11138
                ]
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11139
            ]
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11140
        ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11141
        self isMask ifTrue:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11142
            blackPixel := 0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11143
        ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11144
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11145
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11146
    newBits atAllPut:0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11147
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11148
    "/ now, walk over destination pixels,
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11149
    "/ fetching from source.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11150
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11151
    halfW := (width - 1) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11152
    halfH := (height - 1) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11153
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11154
    "/  --------------------------------------------------------------
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11155
    "/  |**************                                              |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11156
    "/  |              ************                                  | dx1
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11157
    "/  |                          *************                     |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11158
    "/  |                                       **********           |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11159
    "/  |fl                          fy                   ***********| 
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11160
    "/  |                                                            | fr
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11161
    "/  |                                                            | Mr  (!!= Ml)      |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11162
    "/  |Ml                          my                              | fr               | dm (=Mr-Ml)
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11163
    "/  |                                                     *******|                  |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11164
    "/  |                            fy              *********       |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11165
    "/  |fl                                 *********                | 
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11166
    "/  |                          *********                         | dx2
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11167
    "/  |                 *********                                  | 
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11168
    "/  |        *********                                           |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11169
    "/  |********                                                    |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11170
    "/  --------------------------------------------------------------
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11171
    dx1 := height * fraction1.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11172
    dx2 := height * fraction2.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11173
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11174
    fr := (height - dx1 - dx2) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11175
    fl := (height) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11176
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11177
    ml := height / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11178
    mr := dx1+fr.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11179
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11180
    dm := mr-ml.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11181
    df := fr-fl.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11182
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11183
    0 to:width-1 do:[:srcX |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11184
        fractX := srcX / width.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11185
        my := ml + (dm * fractX).
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11186
        fy := fl + (df * fractX).
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11187
        o1 := dx1 * fractX.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11188
        o2 := dx2 * fractX.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11189
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11190
        0 to:height-1 do:[:srcY |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11191
            srcY < halfH ifTrue:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11192
                dstY := o1 + (fy * (srcY / halfH)).
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11193
            ] ifFalse:[
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11194
                dstY := my + (fy * ((srcY-halfH) / halfH)).
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11195
            ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11196
            pix := self pixelAtX:srcX y:srcY.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11197
            dstY < 0 
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11198
                ifTrue:[dstY := 0]
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11199
                ifFalse:[ dstY >= height ifTrue:[dstY := height-1]].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11200
            newImage pixelAtX:srcX y:dstY truncated put:pix.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11201
        ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11202
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11203
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11204
    ^ newImage
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11205
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11206
    "
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11207
     |i|
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11208
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11209
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11210
     i := Depth24Image fromImage:i.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11211
     (i threeDProjected:0.1 and:0.3) inspect
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11212
     (i threeDProjected:0.1 and:0.1) inspect
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11213
    "
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11214
!
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11215
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11216
withColorResolutionReducedBy:numBits
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11217
    "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
 11218
     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
 11219
     If anything fails, return nil."
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11220
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11221
    |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
 11222
     newColors newColorArray newImage extMask extBits newPixelValue|
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11223
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11224
    numBits > 7 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11225
	^ nil
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11226
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11227
    mask := (16rFF bitShift:numBits) bitAnd:16rFF.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11228
    extMask := (1 bitShift:numBits).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11229
    extBits := extMask - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11230
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11231
    anyChange := false.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11232
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11233
    newColors := Set new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11234
    newColorArray := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11235
    map := Array new:256.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11236
    revMap := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11237
4317
a24172a52a76 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
 11238
    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
 11239
    newImage photometric:photometric.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11240
    newImage colorMap:(self colorMap copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11241
    newImage bits:(self bits copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11242
    newImage mask:(self mask copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11243
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11244
    xMax := width - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11245
    yMax := height - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11246
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11247
    newPixelValue :=
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11248
	[:image :pixelValue |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11249
	    |r g b nR nG nB|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11250
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11251
	    r := image redBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11252
	    g := image greenBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11253
	    b := image blueBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11254
	    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
 11255
	    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
 11256
	    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
 11257
	    image valueFromRedBits:nR greenBits:nG blueBits:nB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11258
	].
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11259
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11260
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11261
    photometric == #palette ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11262
	"/ direct manipulation of the pixels
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11263
	0 to:yMax do:[:y |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11264
	    0 to:xMax do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11265
		pix := self pixelAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11266
		n_pix := newPixelValue value:self value:pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11267
		n_pix ~= pix ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11268
		    newImage pixelAtX:x y:y put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11269
		    anyChange := true.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11270
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11271
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11272
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11273
	anyChange ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11274
	    ^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11275
	].
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11276
    ] ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11277
	"/ manipulate the colormap
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11278
	0 to:yMax do:[:y |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11279
	    0 to:xMax do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11280
		pix := self pixelAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11281
		(n_pix := map at:pix+1) isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11282
		    clr := self colorAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11283
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11284
		    r := clr redByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11285
		    g := clr greenByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11286
		    b := clr blueByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11287
		    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
 11288
		    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
 11289
		    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
 11290
		    n_clr := Color redByte:nR greenByte:nG blueByte:nB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11291
		    (newColors includes:n_clr) ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11292
			newColors add:n_clr.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11293
			newColorArray add:n_clr.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11294
			revMap add:pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11295
			map at:pix+1 put:(n_pix := revMap size - 1).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11296
		    ] ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11297
			"/ mhmh - multiple pixels mapped to the same color
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11298
			n_pix := (newColorArray indexOf:n_clr) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11299
			map at:pix+1 put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11300
		    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11301
		].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11302
		newImage pixelAtX:x y:y put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11303
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11304
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11305
	revMap size == self colorMap size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11306
	    revMap = (0 to:revMap size-1) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11307
		^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11308
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11309
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11310
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11311
	newImage colorMap:(MappedPalette withColors:newColorArray).
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11312
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11313
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11314
    ^ newImage
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11315
!
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11316
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11317
withPixelFunctionApplied:pixelFunctionBlock
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11318
    "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
 11319
     on the pixel colors.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11320
     Notice: this method is very slow - either apply pixel values
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11321
     (#withPixelFunctionAppliedToPixels:) or redefine this method in
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11322
     a concrete subclass.
3860
571f1cd259f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3855
diff changeset
 11323
     (read `Beyond photography, by Gerard J. Holzmann;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11324
	   ISBM 0-13-074410-7)
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11325
     See blurred / oilPointed as examples ...)"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11326
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11327
    |w  "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11328
     h  "{Class: SmallInteger }"
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 11329
     newImage "newBits newBytesPerRow"|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11330
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11331
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11332
    newImage depth:self depth.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11333
    newImage width:width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11334
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11335
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11336
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11337
    newImage createPixelStore. "/ bits:newBits.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11338
    newImage photometric:photometric.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11339
    newImage samplesPerPixel:samplesPerPixel.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11340
    newImage bitsPerSample:bitsPerSample.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11341
    newImage colorMap:colorMap copy.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11342
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11343
    w := width - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11344
    h := height - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11345
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11346
    0 to:h do:[:y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11347
	0 to:w do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11348
	    newImage colorAtX:x y:y put:(pixelFunctionBlock
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11349
						value:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11350
						value:(self colorAtX:x y:y)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11351
						value:x
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11352
						value:y)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11353
	]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11354
    ].
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11355
    ^ newImage
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11356
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11357
    "black out everything except for some rectangle:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11358
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 11359
     |i black|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11360
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11361
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11362
     i inspect.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 11363
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 11364
     black := Color black.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 11365
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11366
			((x between:100 and:200)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11367
			and:[y between:100 and:200]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11368
			    oldColor
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11369
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11370
			    black.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11371
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11372
		     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11373
    "
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11374
    "brighten a frame:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11375
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11376
     |i black w h|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11377
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11378
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11379
     i inspect.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11380
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11381
     w := i width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11382
     h := i height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11383
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11384
			((x between:0 and:10)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11385
			or:[(y between:0 and:10)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11386
			or:[(x between:w-10 and:w)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11387
			or:[y between:h-10 and:h]]]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11388
			    oldColor lightened nearestIn:i colorMap
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11389
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11390
			    oldColor.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11391
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11392
		     ]) inspect.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11393
    "
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11394
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11395
    "Modified: 24.4.1997 / 18:36:59 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11396
!
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11397
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11398
withPixelFunctionAppliedToPixels:pixelFunctionBlock
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11399
    "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
 11400
     on the pixel values.
4296
240f73781089 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4226
diff changeset
 11401
     (read `Beyond photography, by Gerard J. Holzmann;
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11402
	   ISBM 0-13-074410-7)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11403
     See blurred / oilPointed as examples ...)"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11404
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11405
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11406
	withPixelFunctionAppliedToPixels:pixelFunctionBlock
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11407
	in:(0@0 corner:width@height)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11408
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11409
    "oil painting effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11410
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11411
     |i w h|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11412
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11413
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11414
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11415
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11416
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11417
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11418
			|b p max xMin xMax yMin yMax|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11419
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11420
			b := Bag identityNew:10.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11421
			xMin := x-3 max:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11422
			xMax := x+3 min:w.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11423
			yMin := y-3 max:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11424
			yMax := y+3 min:h.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11425
			xMin to:xMax do:[:tx|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11426
			  yMin to:yMax do:[:ty|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11427
			    b add:(oldImage pixelAtX:tx y:ty)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11428
			  ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11429
			].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11430
			max := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11431
			b contents keysAndValuesDo:[:pixel :n |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11432
			    n > max ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11433
				p := pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11434
				max := n
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11435
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11436
			].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11437
			p
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11438
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11439
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11440
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11441
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11442
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11443
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11444
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11445
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11446
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11447
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11448
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11449
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11450
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11451
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11452
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11453
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11454
			|p r a nR nP nX nY|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11455
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11456
			p := (x-w2)@(y-h2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11457
			r := p r.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11458
			a := p theta.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11459
			nR := r * r / R.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11460
			nP := Point r:nR theta:a.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11461
			nX := ((nP x+w2) rounded max:0) min:w.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11462
			nY := ((nP y+h2) rounded max:0) min:h.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11463
			(nX > w or:[nX < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11464
			    white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11465
			] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11466
			    (nY > h or:[nY < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11467
				white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11468
			    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11469
				oldImage pixelAtX:nX y:nY
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11470
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11471
			]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11472
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11473
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11474
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11475
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11476
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11477
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11478
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11479
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11480
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11481
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11482
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11483
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11484
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11485
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11486
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11487
			|p r a nR nP nX nY|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11488
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11489
			p := (x-w2)@(y-h2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11490
			r := p r.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11491
			a := p theta.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11492
			nR := r * r / R.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11493
			nP := Point r:nR theta:a.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11494
			nX := (nP x+w2) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11495
			nY := (nP y+h2) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11496
			(nX > w or:[nX < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11497
			    white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11498
			] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11499
			    (nY > h or:[nY < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11500
				white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11501
			    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11502
				oldImage pixelAtX:nX y:nY
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11503
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11504
			]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11505
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11506
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11507
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11508
    "Created: 24.4.1997 / 18:37:17 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11509
    "Modified: 24.4.1997 / 18:40:02 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11510
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11511
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11512
withPixelFunctionAppliedToPixels:pixelFunctionBlock in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11513
    "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
 11514
     on the pixel values.
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 11515
     (read `Beyond photography, by Gerard J. Holzmann;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11516
	   ISBM 0-13-074410-7)
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11517
     See blurred / oilPointed as examples ...)"
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11518
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 11519
    |newImage "newBits newBytesPerRow"|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11520
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11521
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11522
    newImage depth:self depth.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11523
    newImage width:width.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11524
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11525
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11526
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11527
    newImage createPixelStore. "/ bits:newBits
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11528
    newImage photometric:photometric.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11529
    newImage samplesPerPixel:samplesPerPixel.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11530
    newImage bitsPerSample:bitsPerSample.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11531
    newImage colorMap:colorMap copy.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11532
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11533
    self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11534
    ^ newImage
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11535
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11536
    "oil painting effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11537
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11538
     |i w h|
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11539
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11540
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11541
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11542
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11543
     h := i height - 1.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11544
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11545
			|b p max xMin xMax yMin yMax|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11546
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11547
			b := Bag identityNew:10.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11548
			xMin := x-3 max:0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11549
			xMax := x+3 min:w.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11550
			yMin := y-3 max:0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11551
			yMax := y+3 min:h.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11552
			xMin to:xMax do:[:tx|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11553
			  yMin to:yMax do:[:ty|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11554
			    b add:(oldImage pixelAtX:tx y:ty)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11555
			  ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11556
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11557
			max := 0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11558
			b contents keysAndValuesDo:[:pixel :n |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11559
			    n > max ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11560
				p := pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11561
				max := n
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11562
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11563
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11564
			p
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11565
		     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11566
    "
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11567
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11568
    "fisheye effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11569
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 11570
     |i w h w2 h2 R white|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11571
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11572
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11573
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11574
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11575
     h := i height - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11576
     w2 := w // 2.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11577
     h2 := h // 2.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11578
     R := w2.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 11579
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11580
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11581
			|p r a nR nP nX nY|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11582
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11583
			p := (x-w2)@(y-h2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11584
			r := p r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11585
			a := p theta.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11586
			nR := r * r / R.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11587
			nP := Point r:nR theta:a.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11588
			nX := ((nP x+w2) rounded max:0) min:w.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11589
			nY := ((nP y+h2) rounded max:0) min:h.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11590
			(nX > w or:[nX < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11591
			    white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11592
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11593
			    (nY > h or:[nY < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11594
				white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11595
			    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11596
				oldImage pixelAtX:nX y:nY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11597
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11598
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11599
		     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 11600
    "
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11601
    "fisheye effect:
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11602
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11603
     |i w h w2 h2 R white|
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11604
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11605
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11606
     i inspect.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11607
     w := i width - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11608
     h := i height - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11609
     w2 := w // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11610
     h2 := h // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11611
     R := w2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 11612
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11613
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11614
			|p r a nR nP nX nY|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11615
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11616
			p := (x-w2)@(y-h2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11617
			r := p r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11618
			a := p theta.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11619
			nR := r * r / R.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11620
			nP := Point r:nR theta:a.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11621
			nX := (nP x+w2) rounded.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11622
			nY := (nP y+h2) rounded.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11623
			(nX > w or:[nX < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11624
			    white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11625
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11626
			    (nY > h or:[nY < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11627
				white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11628
			    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11629
				oldImage pixelAtX:nX y:nY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11630
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11631
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11632
		     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11633
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11634
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11635
    "Created: 24.4.1997 / 18:37:17 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11636
    "Modified: 24.4.1997 / 18:40:02 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11637
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11638
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 11639
!Image methodsFor:'initialization'!
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 11640
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11641
createPixelStore
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11642
    |bytesPerRow|
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11643
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11644
    bytesPerRow := self bytesPerRow.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 11645
    self bits:(ByteArray new:(bytesPerRow * self height)).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 11646
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 11647
    "Modified: / 02-11-2010 / 20:57:11 / cg"
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11648
!
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11649
3871
a7867fb8d880 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
 11650
initialize
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 11651
    self photometric:(self class defaultPhotometric)
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 11652
! !
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 11653
5037
2e515c9ee849 changed #valueFromColor:
Claus Gittinger <cg@exept.de>
parents: 4998
diff changeset
 11654
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11655
!Image methodsFor:'instance release'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11656
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11657
close
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11658
    "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
 11659
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11660
    deviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11661
	deviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11662
	deviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11663
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11664
    monoDeviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11665
	monoDeviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11666
	monoDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11667
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11668
    fullColorDeviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11669
	fullColorDeviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11670
	fullColorDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11671
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11672
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11673
    device := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11674
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11675
	mask close.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11676
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11677
    Lobby unregister:self.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11678
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11679
    "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
 11680
    "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
 11681
!
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11682
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11683
release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11684
    "release device resources"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11685
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11686
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11687
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11688
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11689
    fullColorDeviceForm := nil.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 11690
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11691
	mask release.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 11692
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 11693
    Lobby unregister:self.
1746
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 11694
    super release.
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 11695
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 11696
    "Modified: 11.6.1997 / 13:20:04 / cg"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11697
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11698
4226
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11699
releaseFromDevice
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11700
    "release device resources"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11701
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11702
    device := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11703
    deviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11704
    monoDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11705
    fullColorDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11706
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11707
    "Modified: 16.1.1997 / 19:33:01 / cg"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11708
!
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 11709
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11710
restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11711
    "flush device specifics after a snapin or binary restore"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11712
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11713
    self release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11714
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11715
2227
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 11716
!Image methodsFor:'misc'!
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 11717
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 11718
edit
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 11719
    "open an image editor on the receiver"
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 11720
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 11721
    ImageEditor openOnImage:self.
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 11722
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 11723
    "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
 11724
! !
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 11725
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11726
!Image methodsFor:'obsolete'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11727
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11728
applyPixelValuesTo:pixelFunctionBlock into:newImage in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11729
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11730
     enumerate pixelValues and evaluate the block for each.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11731
     To be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11732
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11733
    ^ self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11734
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 11735
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11736
magnifyBy:scale
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
 11737
    <resource: #obsolete>
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11738
    "obsolete: has been renamed to magnifiedBy: for ST-80 compatibility
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11739
     and name consistency ..."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11740
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11741
    self obsoleteMethodWarning.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11742
    ^ self magnifiedBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11743
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11744
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11745
!Image methodsFor:'pixel copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11746
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11747
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
 11748
    "replace a rectangular area by pixels from another image.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 11749
     The sources colors must be present in the destinations
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 11750
     colorMap - otherwise, an error will be reported.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11751
     Any mask is copied from the source.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 11752
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11753
     WARNING:
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 11754
       This implementation is a very slow fallback general algorithm
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 11755
       (the loop over the source pixels is very slow).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11756
       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
 11757
       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
 11758
       with the same depth & palette.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11759
       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
 11760
       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
 11761
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11762
    |dX dY|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11763
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11764
    dX := srcX-dstX.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11765
    dY := srcY-dstY.
1248
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
 11766
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11767
    ((photometric == anImage photometric)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11768
     and:[self bitsPerPixel == anImage bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11769
     and:[colorMap = anImage colorMap]]) ifTrue:[
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11770
        "/ can loop over values
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11771
        anImage valuesFromX:srcX  y:srcY
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11772
                        toX:srcX+w-1 y:srcY+h-1
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11773
                         do:[:x :y :pixelValue |
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11774
            self pixelAtX:x-dX y:y-dY put:pixelValue.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11775
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11776
    ] ifFalse:[
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11777
        "/ must loop over colors - horribly slow
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11778
        anImage colorsFromX:srcX  y:srcY
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11779
                        toX:srcX+w-1 y:srcY+h-1
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11780
                         do:[:x :y :clr |
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11781
            self colorAtX:x-dX y:y-dY put:clr.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11782
        ]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11783
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11784
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11785
    (mask isNil and:[anImage mask notNil]) ifTrue:[
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11786
        "/ I have no mask; copied image has
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11787
        self createMask.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11788
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11789
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11790
    mask notNil ifTrue:[
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11791
        anImage mask notNil ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11792
            "/ both have a mask
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11793
            mask copyFrom:anImage mask x:srcX y:srcY toX:dstX y:dstY width:w height:h
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11794
        ] ifFalse:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11795
            "/ I have a mask - copied image has not
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11796
            mask fillRectangleX:dstX y:dstY width:w height:h withValue:1
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11797
        ]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11798
"/    ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11799
"/        anImage mask notNil ifTrue:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11800
"/            "/ I have no mask; copied image has (already handled)
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11801
"/        ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11802
"/            "/ none has a mask - nothing to do.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11803
"/        ]
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11804
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 11805
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11806
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11807
     |i1 i8 i4|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11808
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11809
     i8 := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11810
     i8 inspect.
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11811
     i1 := Image fromFile:'libtool/bitmaps/SBrowser.xbm'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11812
     i1 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11813
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11814
     i4 := Depth4Image fromImage:i8.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 11815
     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
 11816
     i4 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11817
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11818
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11819
    "Created: 20.9.1995 / 10:14:01 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11820
    "Modified: 20.9.1995 / 10:25:31 / claus"
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 11821
    "Modified: 21.6.1997 / 13:15:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11822
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11823
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11824
copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h masked:maskedCopy
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11825
    "replace a rectangular area by pixels from another image.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11826
     The sources colors must be present in the destinations
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11827
     colorMap - otherwise, an error will be reported.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11828
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11829
     WARNING:
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11830
       This implementation is a very slow fallback general algorithm
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11831
       (the loop over the source pixels is very slow).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11832
       If this method is used heavily, you may want to redefine it in
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11833
       concrete subclasses for the common case of of copying from an Image
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11834
       with the same depth & palette.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11835
       If you do heavy image processing, specialized versions are even req'd
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11836
       for other cases, rewriting the inner loops as inline C-code."
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11837
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11838
    maskedCopy ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11839
        self
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11840
            copyMaskedFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h 
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11841
    ] ifFalse:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11842
        self
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11843
            copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h 
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11844
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11845
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11846
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11847
     |i1 i8 i4|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11848
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11849
     i8 := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11850
     i8 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11851
     i1 := Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm'.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11852
     i1 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11853
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11854
     i4 := Depth4Image fromImage:i8.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11855
     i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:20 height:20.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11856
     i4 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11857
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11858
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11859
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11860
copyMaskedFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11861
    "replace a rectangular area by pixels from another image.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11862
     The sources colors must be present in the destinations
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11863
     colorMap - otherwise, an error will be reported.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11864
     Only unmasked pixels are copied from the source.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11865
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11866
     WARNING:
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11867
       This implementation is a very slow fallback general algorithm
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11868
       (the loop over the source pixels is very slow).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11869
       If this method is used heavily, you may want to redefine it in
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11870
       concrete subclasses for the common case of of copying from an Image
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11871
       with the same depth & palette.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11872
       If you do heavy image processing, specialized versions are even req'd
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11873
       for other cases, rewriting the inner loops as inline C-code."
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11874
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11875
    |dX dY|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11876
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11877
    dX := srcX-dstX.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11878
    dY := srcY-dstY.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11879
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11880
    ((photometric == anImage photometric)
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11881
     and:[self bitsPerPixel == anImage bitsPerPixel
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11882
     and:[colorMap = anImage colorMap]]) ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11883
        "/ can loop over values
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11884
        anImage valuesFromX:srcX  y:srcY
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11885
                        toX:srcX+w-1 y:srcY+h-1
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11886
                         do:[:x :y :pixelValue |
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11887
            (anImage maskAtX:x y:y) ~~ 0 ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11888
                self pixelAtX:x-dX y:y-dY put:pixelValue.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11889
            ]
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11890
        ]
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11891
    ] ifFalse:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11892
        "/ must loop over colors - horribly slow
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11893
        anImage colorsFromX:srcX  y:srcY
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11894
                        toX:srcX+w-1 y:srcY+h-1
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11895
                         do:[:x :y :clr |
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11896
            (anImage maskAtX:x y:y) ~~ 0 ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11897
                self colorAtX:x-dX y:y-dY put:clr.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11898
            ]
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11899
        ]
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11900
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11901
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 11902
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11903
subImageIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11904
    "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
 11905
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11906
    ^ self class fromSubImage:self in:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11907
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11908
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11909
     |i|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11910
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11911
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11912
     i inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11913
     (i subImageIn:(300@160 corner:340@200)) inspect
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11914
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11915
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11916
    "Created: 20.9.1995 / 01:24:20 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11917
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11918
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11919
!Image methodsFor:'printing & storing'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11920
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11921
storeOn:aStream
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11922
    "append a printed representation of the receiver to aStream,
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11923
     from which a copy of it can be reconstructed."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11924
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 11925
    |colors usedValues colorMapArray|
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 11926
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11927
    aStream nextPutAll:'(' , self class name , ' new)'.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11928
    aStream nextPutAll:' width: '. width storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11929
    aStream nextPutAll:'; height: '. height storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11930
    aStream nextPutAll:'; photometric:('. photometric storeOn:aStream.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11931
    aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11932
    aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream.
5533
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11933
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11934
    "/ assert that all bits are there...
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11935
    "/ self assert:(self bits size) >= (self bytesPerRow * height).
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11936
    "/ self bits:((ByteArray new:self bytesPerRow * height) replaceFrom:1 with:self bits).
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11937
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11938
    aStream nextPutAll:'); bits:(ByteArray fromPackedString:'. self bits asPackedString storeOn:aStream. 
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11939
    aStream nextPutAll:') '.
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 11940
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 11941
    colorMap notNil ifTrue:[
5533
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11942
        self depth <= 8 ifTrue:[
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11943
            "/ cut off unused colors ...
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11944
            usedValues := self usedValues.
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11945
            colors := colorMap copyFrom:1 to:((usedValues max+1) min:colorMap size).
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11946
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11947
            colorMapArray := OrderedCollection new.
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11948
            colors do:[:clr| colorMapArray add:(clr redByte); add:(clr greenByte); add:(clr blueByte)].
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11949
            aStream nextPutAll:'; colorMapFromArray:'.
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11950
            colorMapArray asByteArray storeOn:aStream.
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11951
        ] ifFalse:[
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11952
            aStream nextPutAll:'; colorMap:('.
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11953
            colorMap storeOn:aStream.
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11954
            aStream nextPutAll:')'
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11955
        ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11956
    ].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 11957
    mask notNil ifTrue:[
5533
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11958
        aStream nextPutAll:'; mask:('.
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11959
        mask storeOn:aStream.
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 11960
        aStream nextPutAll:')'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11961
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 11962
    aStream nextPutAll:'; yourself'
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
 11963
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
 11964
    "Modified: / 22.8.1998 / 12:55:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11965
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 11966
48194c26a46c Initial revision
claus
parents:
diff changeset
 11967
!Image methodsFor:'private'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 11968
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11969
bestSupportedImageFormatFor:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11970
    "scan through the image formats as supported by aDevice,
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11971
     and return the best to use when the receiver is to be represented
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11972
     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
 11973
     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
 11974
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 11975
    |bestDeviceDepth
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 11976
     bestDeviceBitsPerPixel "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11977
     "maxDepth"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11978
     bestInfo maxInfo
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 11979
     myDepth                "{ Class: SmallInteger }"
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 11980
     maxBitsPerPixel        "{ Class: SmallInteger }"|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11981
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11982
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11983
    maxBitsPerPixel := 0.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11984
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 11985
    aDevice supportedImageFormats do:[:entry |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11986
	|deviceImageDepth        "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11987
	 deviceImageBitsPerPixel "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11988
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11989
	deviceImageDepth := entry at:#depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11990
	deviceImageBitsPerPixel := entry at:#bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11991
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11992
	"/ 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
 11993
	"/ devices depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11994
	"/ (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
 11995
	"/ 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
 11996
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11997
	((deviceImageDepth == 1) or:[deviceImageDepth == aDevice depth]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11998
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11999
	    deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12000
		maxInfo := entry.
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12001
    "/            maxBitsPerPixel := deviceImageBitsPerPixel.
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12002
    "/            maxDepth := deviceImageDepth.
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12003
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12004
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12005
	    deviceImageDepth >= myDepth ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12006
		deviceImageDepth == myDepth ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12007
		    "/ take the better one ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12008
		    (bestDeviceDepth isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12009
		     or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12010
			and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12011
			bestInfo := entry.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12012
			bestDeviceDepth := deviceImageDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12013
			bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12014
		    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12015
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12016
		    "/ take the next-larger depth
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12017
		    (bestDeviceDepth isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12018
		     or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12019
			bestInfo := entry.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12020
			bestDeviceDepth := deviceImageDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12021
			bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12022
		    ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12023
		]
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12024
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12025
	].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12026
    ].
851
c9511f8945ce fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents: 841
diff changeset
 12027
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12028
    bestDeviceDepth isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12029
	maxBitsPerPixel == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12030
	    "/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12031
	    "/ oops - nothing appropriate
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12032
	    "/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12033
	    maxInfo notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12034
		^ maxInfo
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12035
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12036
	    bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12037
	    bestInfo := IdentityDictionary new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12038
	    bestInfo at:#depth put:bestDeviceDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12039
	    bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12040
	    bestInfo at:#padding put:32.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12041
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12042
	    bestInfo := maxInfo.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12043
	]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12044
    ].
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 12045
    ^ bestInfo
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 12046
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12047
    "Modified: / 7.2.1998 / 11:23:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12048
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12049
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12050
colormapFromImage:anImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12051
    "setup the receivers colormap from another image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12052
     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
 12053
     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
 12054
     for fromImage:/fromSubImake:"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12055
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12056
    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
 12057
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12058
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12059
colormapFromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12060
    "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
 12061
     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
 12062
     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
 12063
     for fromImage:/fromSubImake:"
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12064
2447
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 12065
    |usedColors|
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 12066
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12067
    samplesPerPixel == 3 ifTrue:[
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12068
        photometric := photometricOrNil ? #rgb
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12069
    ] ifFalse:[
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12070
        photometricOrNil isNil ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12071
            photometric := anImage photometric.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12072
        ] ifFalse:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12073
            photometric := photometricOrNil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12074
        ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12075
        photometric == #palette ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12076
            self setColorMap:(anImage colorMap copy).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12077
            "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12078
             must generate/compress the colormap, if source image has higher depth
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12079
             than myself.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12080
            "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12081
            (colorMap isNil
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12082
            or:[anImage bitsPerPixel > self bitsPerPixel]) ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12083
                "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12084
                 get used colors are extracted into our colorMap
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12085
                 (the at-put below will set the pixelValue according the
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12086
                 new colorIndex
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12087
                "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12088
                self setColorMap:(anImage usedColors asArray).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12089
                colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12090
                    'Image [warning]: possibly too many colors in image' errorPrintCR
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12091
                ]
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12092
            ]
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12093
        ] ifFalse:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12094
            (photometric == #blackIs0
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12095
            or:[ photometric == #whiteIs0 ]) ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12096
            ] ifFalse:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12097
                usedColors := anImage usedColors asArray.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12098
                usedColors size > (1 bitShift:self bitsPerPixel) ifTrue:[
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12099
                    'Image [warning]: possibly too many colors in image' errorPrintCR.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12100
                    usedColors := usedColors copyTo:(1 bitShift:self bitsPerPixel).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12101
                ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12102
                self setColorMap:usedColors.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12103
                photometric := #palette
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12104
            ]
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12105
        ]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12106
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12107
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12108
    "Created: 20.9.1995 / 00:58:42 / claus"
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 12109
    "Modified: 10.1.1997 / 17:52:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12110
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12111
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12112
greyByteMapForRange:range
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12113
    "return a collection to map from pixelValues to greyLevels
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12114
     in the range 0..range.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12115
     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
 12116
     The values are rounded towards the nearest pixel."
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12117
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12118
    |d clr val greyMap r
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12119
     n "{ Class: SmallInteger }"|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12120
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12121
    r := range.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12122
    r == 256 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12123
	r := 255
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12124
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12125
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12126
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12127
	n := colorMap size.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12128
	greyMap := ByteArray new:n.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12129
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12130
	1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12131
	    (clr := colorMap at:i) isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12132
		"/ an unused color
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12133
		val := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12134
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12135
		val := (r * clr brightness) rounded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12136
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12137
	    greyMap at:i put:val
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12138
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12139
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12140
	d := self bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12141
	n := 1 bitShift:d.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12142
	n >= 4096 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12143
	    self error:'size not supported - too large'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12144
	    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12145
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12146
	greyMap := ByteArray new:n.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12147
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12148
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12149
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12150
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12151
		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
 12152
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12153
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12154
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12155
		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
 12156
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12157
	    photometric == #blackIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12158
		"/ we are done
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12159
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12160
		photometric == #whiteIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12161
		    greyMap reverse
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12162
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12163
		    self error:'invalid format'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12164
		    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12165
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12166
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12167
	].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12168
    ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12169
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12170
    ^ greyMap
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12171
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12172
    "
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12173
     Depth8Image new greyByteMapForRange:256
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12174
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12175
     Depth8Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12176
     Depth4Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12177
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12178
     Depth4Image new greyByteMapForRange:1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12179
    "
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12180
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12181
    "Created: 8.6.1996 / 08:34:14 / cg"
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12182
    "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
 12183
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12184
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12185
greyMapForRange:range
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12186
    "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
 12187
     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
 12188
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12189
    |d r clr val
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12190
     n "{Class: SmallInteger }"
1927
d1bbdf03e5a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1919
diff changeset
 12191
     n2 "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12192
     greyArray|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12193
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12194
    d := self bitsPerPixel.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12195
    n := 1 bitShift:d.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12196
    n >= 4096 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12197
	self error:'size not supported - too large'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12198
	^ nil
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12199
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12200
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12201
    greyArray := Array new:n.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12202
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12203
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12204
	n2 := colorMap size.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12205
	1 to:n2 do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12206
	    (clr := colorMap at:i) isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12207
		"/ an unused color
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12208
		val := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12209
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12210
		val := range * clr brightness
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12211
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12212
	    greyArray at:i put:val
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12213
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12214
	n2 < n ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12215
	    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
 12216
	]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12217
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12218
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12219
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12220
		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
 12221
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12222
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12223
	    r := range asFloat.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12224
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12225
		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
 12226
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12227
	    photometric == #blackIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12228
		"/ we are done
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12229
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12230
		photometric == #whiteIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12231
		    greyArray reverse
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12232
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12233
		    self error:'invalid format'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12234
		    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12235
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12236
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12237
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12238
    ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12239
    ^ greyArray
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12240
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12241
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12242
     Depth8Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12243
     Depth4Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12244
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12245
     Depth16Image new greyMapForRange:1
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12246
     Depth4Image new greyMapForRange:1
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12247
     Depth2Image new greyMapForRange:1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12248
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12249
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12250
    "Modified: 1.3.1997 / 15:48:49 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12251
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12252
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12253
magnifyRowFrom:srcBytes offset:srcStart
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12254
	  into:dstBytes offset:dstStart factor:mX
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12255
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12256
    "magnify a single pixel row - can only magnify by integer factors,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12257
     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
 12258
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12259
    ^ self subclassResponsibility
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12260
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12261
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12262
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12263
    "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
 12264
     pixels interpreted as greyValues, 0 is black,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12265
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12266
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12267
    |f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12268
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12269
    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
 12270
    f isNil ifTrue:[^ nil].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12271
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12272
    f bits:bits.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12273
    f initGC.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12274
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12275
    (aDevice blackpixel ~~ 0) ifTrue:[
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12276
        "/ have to invert bits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12277
        f function:#copyInverted
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12278
    ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12279
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12280
        drawBits:bits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12281
        depth:depth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12282
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12283
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12284
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12285
        into:(f id)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12286
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12287
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12288
        with:(f gcId).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12289
    ^ f
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12290
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12291
    "Created: 10.6.1996 / 20:10:31 / cg"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12292
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12293
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12294
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12295
    "given the bits of a monochrome bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12296
     0-bits as black, create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12297
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 12298
"/    monoBits invert.
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
 12299
    ^ (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
 12300
        colorMap:(Array with:Color black with:Color white).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12301
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12302
    "Created: 10.6.1996 / 20:18:09 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 12303
    "Modified: 17.4.1997 / 01:07:38 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12304
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12305
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12306
makeDevicePixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12307
    "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
 12308
     pixels interpreted as in the devices colormap,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12309
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12310
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12311
    |f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12312
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12313
    f := Form width:width height:height depth:depth onDevice:aDevice.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12314
    f isNil ifTrue:[^ nil].
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12315
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12316
    f bits:bits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12317
    f initGC.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12318
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12319
    aDevice
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12320
        drawBits:bits
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12321
        depth:depth
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12322
        padding:8
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12323
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12324
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12325
        into:(f id)
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12326
        x:0 y:0
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12327
        width:width height:height
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 12328
        with:(f gcId).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12329
    ^ f
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12330
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 12331
    "Created: 10.6.1996 / 17:56:08 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 12332
    "Modified: 10.6.1996 / 20:11:27 / cg"
5237
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 12333
!
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 12334
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 12335
repairPhotometric
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 12336
    "/ kludge: repair a 'should not happen' situation...
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 12337
    photometric isNil ifTrue:[
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 12338
        (depth == 24 and:[ bitsPerSample size == 3 ]) ifTrue:[
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 12339
            photometric := #rgb
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 12340
        ].
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 12341
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 12342
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 12343
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12344
!Image methodsFor:'queries'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12345
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12346
alphaBitsOf:pixel
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12347
    "if the receiver is an rgb-image:
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12348
     return the alpha component of a pixelValue as integer 0..maxAlphaValue.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12349
     MaxAlphaValue is of course the largest integer representable by the number
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12350
     of alpha bits i.e. (1 bitShift:bitsAlpha)-1.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12351
     This has to be redefined by subclasses."
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12352
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12353
    |redBits greenBits blueBits alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12354
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12355
    samplesPerPixel >= 4 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12356
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12357
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12358
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12359
	alphaBits := bitsPerSample at:4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12360
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12361
	^ (pixel bitShift:(redBits + greenBits + blueBits) negated)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12362
	   bitAnd:(1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12363
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12364
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12365
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12366
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12367
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12368
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12369
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12370
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12371
alphaMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12372
    "return the mask used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12373
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12374
    |alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12375
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12376
    samplesPerPixel >= 4 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12377
	alphaBits := bitsPerSample at:4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12378
	^ (1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12379
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12380
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12381
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12382
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12383
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12384
alphaShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12385
    "return the shift amount used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12386
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12387
    |redBits greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12388
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12389
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12390
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12391
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12392
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12393
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12394
	^ (greenBits + blueBits + redBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12395
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12396
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12397
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12398
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12399
3813
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 12400
ascentOn:aGC
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 12401
    "I will not draw myself above the baseline"
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 12402
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 12403
    ^ 0
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 12404
!
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 12405
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12406
averageColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12407
    "return the average color of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12408
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12409
     (i.e. to compute shadow & light colors for viewBackgrounds).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12410
     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
 12411
     a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12412
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12413
    ^ self averageColorIn:(0@0 corner:(width-1)@(height-1))
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12414
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12415
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12416
averageColorIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12417
    "return the images average color in an area.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12418
     The implementation below is slow - so you may want to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12419
     create tuned versions for DepthXImage if you plan to do
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12420
     heavy image processing ...
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12421
     (also, creating tuned versions of the enumeration messages helps a lot)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12422
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12423
    |x0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12424
     y0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12425
     x1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12426
     y1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12427
     sumRed sumGreen sumBlue n|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12428
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12429
    sumRed := sumGreen := sumBlue := 0.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12430
    y0 := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12431
    y1 := aRectangle bottom.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12432
    x0 := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12433
    x1 := aRectangle right.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12434
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12435
    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
 12436
    mask isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12437
	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
 12438
	    sumRed := sumRed + colorAtXY red.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12439
	    sumGreen := sumGreen + colorAtXY green.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12440
	    sumBlue := sumBlue + colorAtXY blue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12441
	].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 12442
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12443
	"/ masked pixels are not counted.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12444
	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
 12445
	    (mask pixelAtX:x y:y) == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12446
		n := n - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12447
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12448
		sumRed := sumRed + colorAtXY red.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12449
		sumGreen := sumGreen + colorAtXY green.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12450
		sumBlue := sumBlue + colorAtXY blue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12451
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12452
	].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 12453
    ].
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 12454
    n == 0 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12455
	"/ all masked
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12456
	^ Color black
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 12457
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12458
    ^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12459
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12460
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12461
bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12462
    "return the number of bits per pixel"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12463
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12464
    ^ (bitsPerSample inject:0 into:[:sum :i | sum + i])
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12465
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12466
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12467
bitsPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12468
    "return the number of bits in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12469
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
 12470
    ^ width * (self bitsPerPixel).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12471
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12472
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12473
blackComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12474
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12475
     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
 12476
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12477
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12478
	"/ 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
 12479
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12480
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12481
	    ^ 100.0 / 255 * (pixel bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12482
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12483
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12484
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12485
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12486
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12487
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12488
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12489
blueBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12490
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12491
     return the blue bits of a pixelValue as integer 0..maxBlueValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12492
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12493
     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
 12494
     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
 12495
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12496
    |blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12497
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12498
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12499
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12500
	^ 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
 12501
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12502
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12503
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12504
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12505
    "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
 12506
    "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
 12507
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12508
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12509
blueComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12510
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12511
     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
 12512
     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
 12513
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12514
    |blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12515
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12516
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12517
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12518
	"/ 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
 12519
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12520
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12521
	blueBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12522
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12523
	s := (1 bitShift:blueBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12524
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12525
	^ 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
 12526
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12527
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12528
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12529
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12530
    "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
 12531
    "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
 12532
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12533
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12534
blueMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12535
    "return the mask used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12536
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12537
    |blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12538
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12539
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12540
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12541
	^ (1 bitShift:blueBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12542
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12543
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12544
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12545
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12546
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12547
blueShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12548
    "return the shift amount used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12549
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12550
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12551
	^ 0
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12552
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12553
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12554
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12555
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12556
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 12557
bounds
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 12558
    "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
 12559
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 12560
    ^ 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
 12561
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 12562
    "Created: 13.5.1996 / 10:27:06 / cg"
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 12563
!
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 12564
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12565
brightness
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12566
    "return the (average) brightness of the image.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12567
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12568
     (i.e. to compute shadow & light colors for viewBackgrounds).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12569
     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
 12570
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12571
    ^ (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
 12572
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12573
    "Modified: 8.6.1996 / 08:46:46 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12574
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12575
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12576
bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12577
    "return the number of bytes in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12578
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12579
    |bitsPerRow bytesPerRow|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12580
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12581
    bitsPerRow := width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12582
    bytesPerRow := bitsPerRow // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12583
    ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12584
	bytesPerRow := bytesPerRow + 1
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12585
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12586
    ^ bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12587
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12588
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 12589
bytesPerRowPaddedTo:padding
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 12590
    "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
 12591
     if scanlines are to be padded to padding-bits."
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 12592
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
 12593
    ^ self class
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12594
	bytesPerRowForWidth:width depth:(self bitsPerPixel) padding:padding
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 12595
!
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 12596
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 12597
center
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 12598
    "for compatibility with GC protocol - return the centerPoint"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 12599
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 12600
    ^ (width // 2) @ (height // 2)
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 12601
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 12602
    "Created: 22.10.1997 / 23:52:40 / cg"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 12603
!
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 12604
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12605
colorFromValue:pixelValue
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12606
    "given a pixel value, return the corresponding color.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12607
     Pixel values start with 0.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12608
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 12609
     - 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
 12610
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12611
    |p maxPixel clr r g b c m y k a
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12612
     numRedBits numGreenBits numBlueBits numAlphaBits|
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 12613
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 12614
    p := photometric.
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 12615
    p isNil ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12616
        colorMap notNil ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12617
            p := #palette
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12618
        ] ifFalse:[
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 12619
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12620
            p := #blackIs0
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12621
        ]
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 12622
    ].
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 12623
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 12624
    p == #blackIs0 ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12625
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12626
        ^ Color gray:(pixelValue * (100 / maxPixel)).
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12627
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12628
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 12629
    p == #whiteIs0 ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12630
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12631
        ^ 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
 12632
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12633
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 12634
    p == #palette ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12635
        pixelValue >= colorMap size ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12636
            ^ Color black
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12637
        ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12638
        clr := colorMap at:(pixelValue + 1).
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12639
        clr isNil ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12640
            ^ Color black.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12641
        ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12642
        ^ clr.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12643
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12644
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 12645
    p == #rgb ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12646
        r := self redBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12647
        g := self greenBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12648
        b := self blueBitsOf:pixelValue.
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12649
        "/ must scale...
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12650
        numRedBits := bitsPerSample at:1.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12651
        numGreenBits := bitsPerSample at:2.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12652
        numBlueBits := bitsPerSample at:3.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12653
        ^ Color redPercent:(100 / ((1 bitShift:numRedBits)-1) * r)
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12654
                greenPercent:(100 / ((1 bitShift:numGreenBits)-1) * g)
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12655
                bluePercent:(100 / ((1 bitShift:numBlueBits)-1) * b)
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12656
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12657
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12658
    p == #rgba ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12659
        r := self redBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12660
        g := self greenBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12661
        b := self blueBitsOf:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12662
        a := self alphaBitsOf:pixelValue.
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12663
        "/ must scale...
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12664
        numRedBits := bitsPerSample at:1.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12665
        numGreenBits := bitsPerSample at:2.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12666
        numBlueBits := bitsPerSample at:3.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12667
        numAlphaBits := bitsPerSample at:4.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12668
        "/ must scale...
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12669
        ^ Color redPercent:(100 / ((1 bitShift:numRedBits)-1) * r)
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12670
                greenPercent:(100 / ((1 bitShift:numGreenBits)-1) * g)
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12671
                bluePercent:(100 / ((1 bitShift:numBlueBits)-1) * b)
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12672
                alphaPercent:(100 / ((1 bitShift:numAlphaBits)-1) * a)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12673
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12674
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12675
    p == #cmyk ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12676
        c := self cyanComponentOfCMYK:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12677
        m := self magentaComponentOfCMYK:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12678
        y := self yellowComponentOfCMYK:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12679
        k := self blackComponentOfCMYK:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12680
        ^ 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
 12681
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12682
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12683
    p == #cmy ifTrue:[
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12684
        c := self cyanComponentOfCMY:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12685
        m := self magentaComponentOfCMY:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12686
        y := self yellowComponentOfCMY:pixelValue.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12687
        ^ Color cyan:c magenta:m yellow:y.
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12688
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12689
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12690
    self error:'invalid (unsupported) photometric'
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12691
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12692
    "Created: / 08-06-1996 / 08:46:18 / cg"
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 12693
    "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
 12694
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12695
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12696
cyanComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12697
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12698
     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
 12699
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12700
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12701
	"/ 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
 12702
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12703
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12704
	    ^ 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
 12705
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12706
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12707
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12708
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12709
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12710
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12711
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12712
cyanComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12713
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12714
     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
 12715
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12716
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12717
	"/ 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
 12718
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12719
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12720
	    ^ 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
 12721
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12722
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12723
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12724
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12725
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12726
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12727
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12728
greenBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12729
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12730
     return the green bits of a pixelValue as integer 0..maxGreenValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12731
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12732
     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
 12733
     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
 12734
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12735
    |blueBits greenBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12736
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12737
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12738
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12739
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12740
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12741
	^ (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
 12742
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12743
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12744
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12745
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12746
    "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
 12747
    "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
 12748
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12749
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12750
greenComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12751
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12752
     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
 12753
     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
 12754
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12755
    |greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12756
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12757
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12758
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12759
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12760
	"/ 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
 12761
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12762
	greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12763
	greenBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12764
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12765
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12766
	s := (1 bitShift:greenBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12767
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12768
	^ 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
 12769
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12770
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12771
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12772
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12773
    "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
 12774
    "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
 12775
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12776
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12777
greenMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12778
    "return the mask used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12779
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12780
    |greenBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12781
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12782
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12783
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 12784
	^ (1 bitShift:greenBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12785
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12786
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12787
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12788
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12789
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12790
greenShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12791
    "return the shift amount used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12792
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12793
    |greenBits|
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12794
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12795
    samplesPerPixel >= 3 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12796
	greenBits := bitsPerSample at:3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12797
	^ greenBits negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12798
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12799
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12800
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12801
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 12802
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12803
heightOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12804
    "return my height, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12805
     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
 12806
     return the pixel-height"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12807
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 12808
    ^ height
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12809
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12810
    "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
 12811
    "Modified: 13.5.1996 / 10:26:36 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12812
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 12813
3700
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 12814
isDithered
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 12815
    "for compatibility with color protocol"
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 12816
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 12817
    ^ false
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 12818
!
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 12819
3507
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 12820
isGrayscaleImage
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 12821
    ^ (photometric ~= #palette)
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 12822
      and:[photometric ~= #rgb]
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 12823
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 12824
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 12825
    "Created: 22.4.1997 / 14:12:02 / cg"
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 12826
!
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 12827
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12828
isImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12829
    "return true, if the receiver is some kind of image;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12830
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12831
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12832
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12833
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12834
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12835
isImageOrForm
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12836
    "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
 12837
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12838
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12839
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12840
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12841
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 12842
isMask
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 12843
    ^ false
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 12844
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 12845
    "Created: 22.4.1997 / 14:12:02 / cg"
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 12846
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 12847
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12848
magentaComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12849
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12850
     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
 12851
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12852
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12853
	"/ 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
 12854
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12855
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12856
	    ^ 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
 12857
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12858
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12859
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12860
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12861
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12862
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12863
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12864
magentaComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12865
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12866
     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
 12867
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12868
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12869
	"/ 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
 12870
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12871
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12872
	    ^ 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
 12873
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12874
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12875
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12876
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12877
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12878
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 12879
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 12880
pixelArraySpecies
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 12881
    "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
 12882
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 12883
    self depth > 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12884
	^ Array
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 12885
    ].
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 12886
    ^ ByteArray
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 12887
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 12888
    "Created: 6.3.1997 / 15:24:05 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 12889
    "Modified: 24.4.1997 / 15:34:34 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 12890
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 12891
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12892
realColorMap
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12893
    "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
 12894
     For palette images, this is the internal colormap;
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12895
     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
 12896
     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
 12897
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12898
    |d nEntries "{ Class: SmallInteger }"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12899
     colorArray|
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12900
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12901
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12902
	^ colorMap asArray
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12903
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12904
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12905
    d := self depth.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12906
    d > 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12907
	self error:'deep palette images not supported'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12908
	^ nil.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12909
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12910
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12911
    nEntries := 1 bitShift:d.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12912
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12913
    colorArray := Array new:nEntries.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12914
    1 to:nEntries do:[:idx |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12915
	colorArray at:idx put:(self colorFromValue:(idx-1)).
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12916
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12917
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12918
    ^ colorArray
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12919
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12920
    "Created: 11.7.1996 / 20:20:35 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12921
    "Modified: 11.7.1996 / 20:49:21 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12922
!
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 12923
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12924
realUsedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 12925
    "return a collection of colors which are really used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 12926
     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
 12927
     (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
 12928
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12929
    |values|
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12930
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12931
    values := self realUsedValues asArray.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12932
    ^ values collect:[:pixel | self colorFromValue:pixel]
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12933
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12934
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12935
realUsedValues
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12936
    "return a collection of color values used in the receiver.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12937
     Notice, that the interpretation of the pixels depends on the photometric
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12938
     of the image.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12939
     This is a general and therefore slow implementation; subclasses
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 12940
     may want to redefine this method for more performance.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 12941
     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
 12942
     (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
 12943
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12944
    |set last|
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12945
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12946
    set := IdentitySet new.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12947
    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
 12948
	pixel ~~ last ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12949
	    set add:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12950
	    last := pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12951
	]
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12952
    ].
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12953
    ^ set
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12954
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12955
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12956
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12957
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedValues
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12958
    "
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12959
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12960
    "Modified: / 29.7.1998 / 21:29:44 / cg"
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12961
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 12962
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12963
redBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12964
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12965
     return the red component of a pixelValue as integer 0..maxRedValue.
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12966
     MaxRedValue is the largest integer representable by the number
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12967
     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
 12968
     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
 12969
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12970
    |redBits greenBits blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12971
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12972
    samplesPerPixel >= 3 ifTrue:[
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12973
        redBits := bitsPerSample at:1.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12974
        greenBits := bitsPerSample at:2.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12975
        blueBits := bitsPerSample at:3.
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12976
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12977
        ^ (pixel bitShift:(greenBits + blueBits) negated)
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 12978
           bitAnd:(1 bitShift:redBits)-1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12979
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12980
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12981
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12982
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12983
    "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
 12984
    "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
 12985
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12986
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12987
redComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12988
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12989
     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
 12990
     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
 12991
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12992
    |redBits   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12993
     greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12994
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 12995
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12996
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12997
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12998
	"/ 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
 12999
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13000
	redBits := bitsPerSample at:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13001
	redBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13002
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13003
	greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13004
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13005
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13006
	s := (1 bitShift:redBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13007
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13008
	^ 100.0 / s *
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13009
	  ((pixel bitShift:(greenBits + blueBits) negated)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13010
	   bitAnd:(1 bitShift:redBits)-1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13011
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13012
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13013
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13014
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13015
    "Created: 8.6.1996 / 08:45:30 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13016
    "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
 13017
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13018
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13019
redMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13020
    "return the mask used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13021
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13022
    |redBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13023
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13024
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13025
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13026
	^ (1 bitShift:redBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13027
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13028
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13029
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13030
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13031
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13032
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13033
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13034
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13035
redShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13036
    "return the shift amount used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13037
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13038
    |greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13039
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13040
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13041
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13042
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13043
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13044
	^ (greenBits + blueBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13045
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13046
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13047
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13048
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13049
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13050
rgbFromValue:pixelValue
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13051
    "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13052
     Pixel value is in 0..2^depth - 1.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13053
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13054
     - this method is typically redefined in subclasses."
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13055
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13056
    |p maxPixel clr r g b c m y k|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13057
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13058
    p := photometric.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13059
    p isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13060
	colorMap notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13061
	    p := #palette
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13062
	] ifFalse:[
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13063
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13064
	    p := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13065
	]
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13066
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13067
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13068
    p == #blackIs0 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13069
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13070
	b := pixelValue * 255 // maxPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13071
	^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13072
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13073
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13074
    p == #whiteIs0 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13075
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13076
	b := 255 - (pixelValue * 255 // maxPixel).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13077
	^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13078
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13079
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13080
    p == #palette ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13081
	pixelValue >= colorMap size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13082
	    ^ 0 "/ black
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13083
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13084
	clr := colorMap at:(pixelValue + 1).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13085
	clr isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13086
	    ^ 0 "/ black
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13087
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13088
	^ clr rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13089
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13090
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13091
    p == #rgb ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13092
	r := self redBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13093
	g := self greenBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13094
	b := self blueBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13095
	"/ must scale to byte value...
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13096
	r := r bitShift:(8 - (bitsPerSample at:1)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13097
	g := g bitShift:(8 - (bitsPerSample at:2)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13098
	b := b bitShift:(8 - (bitsPerSample at:3)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13099
	^ (((r bitShift:8) bitOr:g) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13100
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13101
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13102
    p == #cmyk ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13103
	c := self cyanComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13104
	m := self magentaComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13105
	y := self yellowComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13106
	k := self blackComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13107
	^ (Color cyan:c magenta:m yellow:y black:k) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13108
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13109
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13110
    p == #cmy ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13111
	c := self cyanComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13112
	m := self magentaComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13113
	y := self yellowComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13114
	^ (Color cyan:c magenta:m yellow:y) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13115
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13116
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13117
    self error:'invalid (unsupported) photometric'
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13118
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13119
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13120
usedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13121
    "return a collection of colors used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13122
     This looks at the colorMap only if present.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13123
     (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
 13124
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13125
    |colors|
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13126
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13127
    colors := self usedColorsMax:4096.
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13128
    colors isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13129
	self error:'too many colors in image'.
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13130
    ].
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13131
    ^ colors
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13132
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13133
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13134
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13135
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13136
    "
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13137
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13138
    "Modified: / 7.9.1998 / 17:56:12 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13139
!
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13140
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13141
usedColorsMax:nMax
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13142
    "return a collection of colors used in the receiver;
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13143
     This looks at the colorMap only if present
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13144
     (as opposed to #realUsedColors, which goes through the pixels if the bitmap).
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13145
     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
 13146
     (useful when searching rgb images)."
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13147
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 13148
    |usedValues max colors|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13149
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13150
    photometric == #rgb ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13151
	usedValues := IdentitySet new.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13152
	self valuesFromX:0 y:0 toX:(width-1) y:(height-1)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13153
	  do:[:x :y :pixel |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13154
	    usedValues add:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13155
	    usedValues size > nMax ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13156
		"/ too many to be returned here (think of the mass of
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13157
		"/ data to be returned by a 24bit image ... ;-)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13158
		^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13159
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13160
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13161
	"/ code below is slightly faster ...
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13162
	"/ colors := usedValues collect:[:pixel | self colorFromValue:pixel].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13163
	colors := usedValues collect:[:pixel | |r g b|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13164
					r := self redBitsOf:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13165
					g := self greenBitsOf:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13166
					b := self blueBitsOf:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13167
					"/ must scale to byte value...
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13168
					r := r bitShift:(8 - (bitsPerSample at:1)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13169
					g := g bitShift:(8 - (bitsPerSample at:2)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13170
					b := b bitShift:(8 - (bitsPerSample at:3)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13171
					Color redByte:r greenByte:g blueByte:b
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13172
				     ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13173
	^ colors.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13174
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13175
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13176
    usedValues := self usedValues asArray.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13177
    photometric == #palette ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13178
	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
 13179
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13180
	"/ (photometric == #blackIs0 or:[photometric == #whiteIs0])
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13181
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13182
	max := (1 bitShift:self depth) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13183
	colors :=  usedValues collect:[:val | (Color gray:(100 * val / max ))].
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 13184
    ].
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 13185
    ^ colors asSet
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13186
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13187
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13188
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13189
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13190
    "
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
 13191
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13192
    "Created: / 7.9.1998 / 17:54:17 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13193
    "Modified: / 7.9.1998 / 17:56:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13194
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13195
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13196
usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13197
    "return a collection of color values used in the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13198
     Notice, that the interpretation of the pixels depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13199
     of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13200
     This is a general and therefore slow implementation; subclasses
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13201
     may want to redefine this method for more performance."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13202
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13203
    ^ self realUsedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13204
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13205
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13206
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13207
     (Image fromFile:'lib tool/bitmaps/SBrowser.xbm') usedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13208
    "
2206
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 13209
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 13210
    "Modified: / 29.7.1998 / 21:29:44 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13211
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13212
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13213
valueFromColor:color
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13214
    "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
 13215
     Non-representable colors return nil."
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13216
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13217
    |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
 13218
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 13219
    color colorId notNil ifTrue:[
5200
6bbd49ec84a1 care for mask color
Claus Gittinger <cg@exept.de>
parents: 5161
diff changeset
 13220
        color == Color noColor ifTrue:[
6bbd49ec84a1 care for mask color
Claus Gittinger <cg@exept.de>
parents: 5161
diff changeset
 13221
            ^ nil "/ mask
6bbd49ec84a1 care for mask color
Claus Gittinger <cg@exept.de>
parents: 5161
diff changeset
 13222
        ].
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 13223
        color device isNil ifTrue:[
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 13224
            ^ color colorId
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 13225
        ]
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 13226
    ].
5037
2e515c9ee849 changed #valueFromColor:
Claus Gittinger <cg@exept.de>
parents: 4998
diff changeset
 13227
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13228
    photometric == #whiteIs0 ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13229
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13230
        ^ maxPixel - (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13231
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13232
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13233
    photometric == #blackIs0 ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13234
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13235
        ^ (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13236
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13237
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13238
    photometric == #palette ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13239
        colorMap isNil ifTrue:[ 
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13240
            "/ same as blackIs0
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13241
            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13242
            ^ (color brightness * maxPixel) rounded.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13243
        ].
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13244
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13245
        pixel := colorMap indexOf:color.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13246
        pixel == 0 ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13247
            "
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13248
             the color is not in the images colormap
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13249
            "
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13250
            ^ nil
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13251
        ].
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13252
        ^ pixel - 1
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13253
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13254
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13255
    photometric == #rgb ifTrue:[
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13256
        samplesPerPixel >= 3 ifTrue:[
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13257
            redBits := bitsPerSample at:1.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13258
            greenBits := bitsPerSample at:2.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13259
            blueBits := bitsPerSample at:3.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13260
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13261
            "/ map r/g/b to 0..255
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13262
            r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13263
            g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13264
            b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13265
            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13266
            ^ pixel
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
 13267
        ]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13268
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13269
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13270
    photometric == #rgba ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13271
        samplesPerPixel >= 4 ifTrue:[
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13272
            redBits := bitsPerSample at:1.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13273
            greenBits := bitsPerSample at:2.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13274
            blueBits := bitsPerSample at:3.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13275
            alphaBits := bitsPerSample at:4.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13276
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13277
            "/ map r/g/b/a to 0..255
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13278
            r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13279
            g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13280
            b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13281
            a := (color alpha * ((1 bitShift:alphaBits)-1)) rounded.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13282
            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13283
            ^ pixel
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13284
        ]
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13285
    ].
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 13286
    ImageErrorSignal raiseErrorString:'format not supported'.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13287
    ^ nil
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13288
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13289
    "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
 13290
!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13291
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13292
valueFromRGB:rgb
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13293
    "given a color, return the corresponding pixel value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13294
     Non-representable colors return nil."
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13295
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13296
    |pixel redBits greenBits blueBits alphaBits r g b a|
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13297
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13298
    r := rgb bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13299
    g := (rgb bitShift:-8) bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13300
    b := (rgb bitShift:-16) bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13301
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13302
"/    photometric == #whiteIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13303
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13304
"/        ^ maxPixel - (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13305
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13306
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13307
"/    photometric == #blackIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13308
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13309
"/        ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13310
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13311
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13312
"/    photometric == #palette ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13313
"/        colorMap isNil ifTrue:[ 
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13314
"/            "/ same as blackIs0
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13315
"/            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13316
"/            ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13317
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13318
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13319
"/        pixel := colorMap indexOf:color.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13320
"/        pixel == 0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13321
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13322
"/             the color is not in the images colormap
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13323
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13324
"/            ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13325
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13326
"/        ^ pixel - 1
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13327
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13328
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13329
    photometric == #rgb ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13330
        samplesPerPixel >= 3 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13331
            redBits := bitsPerSample at:1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13332
            greenBits := bitsPerSample at:2.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13333
            blueBits := bitsPerSample at:3.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13334
            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13335
            ^ pixel
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13336
        ]
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13337
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13338
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13339
    photometric == #rgba ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13340
        samplesPerPixel >= 4 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13341
            redBits := bitsPerSample at:1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13342
            greenBits := bitsPerSample at:2.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13343
            blueBits := bitsPerSample at:3.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13344
            alphaBits := bitsPerSample at:4.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13345
            a := 255.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13346
            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13347
            ^ pixel
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13348
        ]
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13349
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13350
    ImageErrorSignal raiseErrorString:'format not supported'.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13351
    ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13352
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13353
    "Created: / 15-01-2008 / 15:55:08 / cg"
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13354
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 13355
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13356
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13357
    "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
 13358
     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
 13359
     For now, only useful with RGB images"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13360
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13361
    |pixel numGreenBits numBlueBits|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13362
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13363
    photometric == #rgb ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13364
	samplesPerPixel >= 3 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13365
	    numGreenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13366
	    numBlueBits := bitsPerSample at:3.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13367
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13368
	    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
 13369
	    ^ pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13370
	]
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13371
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13372
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13373
    ImageErrorSignal raiseErrorString:'format not supported'.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13374
    ^ nil
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13375
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13376
    "Modified: / 30.9.1998 / 22:03:50 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13377
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13378
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13379
widthOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13380
    "return my width, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13381
     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
 13382
     return the pixel-width"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13383
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13384
    ^ width
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13385
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13386
    "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
 13387
    "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
 13388
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13389
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13390
yellowComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13391
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13392
     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
 13393
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13394
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13395
	"/ 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
 13396
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13397
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13398
	    ^ 100.0 / 255 * (pixel bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13399
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13400
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13401
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13402
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13403
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13404
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13405
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13406
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13407
yellowComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13408
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13409
     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
 13410
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13411
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13412
	"/ 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
 13413
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13414
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13415
	    ^ 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
 13416
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13417
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13418
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13419
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13420
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13421
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13422
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13423
!Image methodsFor:'saving on file'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13424
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13425
saveOn:aFileName
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13426
    "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
 13427
     Currently, not all formats may be supported
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 13428
     (see ImageReader subclasses implementing save:onFile:).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 13429
     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
 13430
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13431
    |suffix readerClass|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13432
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13433
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13434
    "/ from the extension, get the imageReader class
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13435
    "/ (which should know how to write images as well)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13436
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13437
    suffix := aFileName asFilename suffix.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 13438
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13439
    readerClass notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13440
	^ self saveOn:aFileName using:readerClass
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13441
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13442
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13443
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13444
    "/ no known extension - could ask user for the format here.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13445
    "/ currently default to tiff format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13446
    "/
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 13447
    '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
 13448
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13449
    ^ self saveOn:aFileName using:TIFFReader
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 13450
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 13451
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 13452
     |image|
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 13453
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13454
     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
 13455
     image saveOn:'myImage.tiff'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 13456
     image saveOn:'myImage.xbm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 13457
     image saveOn:'myImage.xpm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 13458
     image saveOn:'myImage.xwd'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 13459
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 13460
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 13461
    "Modified: 30.6.1997 / 22:06:34 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 13462
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 13463
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13464
saveOn:aFileName using:readerClass
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13465
    "save the receiver using the representation class
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13466
     (which is usually a concrete subclasses of ImageReader).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 13467
     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
 13468
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 13469
    ^ readerClass save:self onFile:aFileName
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13470
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13471
    "
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 13472
     |anImage|
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 13473
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13474
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 13475
     anImage saveOn:'myImage.tiff' using:TIFFReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13476
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13477
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13478
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13479
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13480
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13481
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 13482
     anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13483
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13484
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13485
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13486
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13487
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13488
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13489
     Image cannotRepresentImageSignal handle:[:ex |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13490
	self warn:'cannot save the image in this format'
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13491
     ] do:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13492
	anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13493
     ]
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13494
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13495
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13496
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13497
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13498
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13499
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 13500
     anImage saveOn:'myImage.xpm' using:XPMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13501
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13502
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13503
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13504
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13505
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13506
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 13507
     anImage saveOn:'myImage.gif' using:GIFReader.
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 13508
    "
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 13509
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 13510
    "Modified: 10.4.1997 / 17:49:26 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 13511
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13512
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13513
!Image methodsFor:'screen capture'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13514
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13515
from:aDrawable in:aRectangle
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13516
    "read an image from aDrawable.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13517
     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
 13518
     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
 13519
     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
 13520
     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
 13521
     and to read hardcopy images from the screen."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13522
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13523
    | visType
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13524
     x        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13525
     y        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13526
     w        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13527
     h        "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13528
     dstIndex "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13529
     srcIndex "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13530
     srcRow   "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13531
     dstRow   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13532
     inData tmpData usedPixels mapSize
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13533
     map bytesPerLine
2534
35d91dcc4604 removed unused local
Claus Gittinger <cg@exept.de>
parents: 2533
diff changeset
 13534
     bitOrder spaceBitsPerPixel
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13535
     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
 13536
     bitsR "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 13537
     bitsG "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 13538
     bitsB "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13539
     maskR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13540
     maskG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13541
     maskB "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13542
     shR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13543
     shG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13544
     shB "{ Class: SmallInteger }"
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 13545
     shR2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 13546
     shG2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 13547
     shB2 "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13548
     r "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13549
     g "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13550
     b "{ Class: SmallInteger }"
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 13551
     word "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13552
     lword
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 13553
     device ddepth isMSB|
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 13554
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 13555
    depth := self depth.
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 13556
    bitsPerPixel := self bitsPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13557
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
 13558
    device := aDrawable graphicsDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13559
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13560
    (aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13561
	"/ a monochrome bitmap ?
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13562
	visType := #StaticGray.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13563
	ddepth := 1.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13564
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13565
	(aDrawable isForm) ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13566
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13567
	     get some attributes of the display device
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13568
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13569
	    visType := device visualType.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13570
	    ddepth := device depth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13571
	] ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13572
	    ddepth := aDrawable depth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13573
	    visType := aDrawable photometric
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13574
	].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13575
    ].
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13576
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13577
    "/ kludge for 15bit XFree server
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 13578
    ddepth == 15 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13579
	ddepth := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13580
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13581
4421
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 13582
    aDrawable isForm ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13583
	photometric := aDrawable photometric.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13584
	samplesPerPixel := ddepth == 24 ifTrue:3 ifFalse:1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13585
	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
 13586
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13587
	(visType == #StaticGray) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13588
	    (device blackpixel == 0) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13589
		photometric := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13590
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13591
		photometric := #whiteIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13592
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13593
	    samplesPerPixel := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13594
	    bitsPerPixel := ddepth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13595
	    bitsPerSample := ByteArray with:bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13596
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13597
	    ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13598
		photometric := #palette.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13599
		samplesPerPixel := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13600
		bitsPerPixel := ddepth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13601
		bitsPerSample := ByteArray with:bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13602
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13603
		((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13604
		    photometric := #rgb.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13605
		    samplesPerPixel := 3.
4421
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 13606
    "/                bitsPerPixel := depth.
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 13607
    "/                bitsPerSample := ByteArray with:device bitsRed
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 13608
    "/                                       with:device bitsGreen
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 13609
    "/                                       with:device bitsBlue
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13610
		    bitsPerPixel := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13611
		    bitsPerSample := #(8 8 8).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13612
		] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13613
		    self error:'screen visual not supported'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13614
		    ^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13615
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13616
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13617
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13618
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13619
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13620
    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13621
     dont know yet, how the display pads; assume worst case,
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13622
     offering enough space for 32 bit padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13623
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13624
    w := width := aRectangle width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13625
    h := height := aRectangle height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13626
    x := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13627
    y := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13628
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13629
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13630
     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
 13631
     (its too late when info is present ...)
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13632
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13633
    spaceBitsPerPixel := bitsPerPixel.
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13634
    (bitsPerPixel > 8) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13635
	spaceBitsPerPixel := 16.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13636
	(bitsPerPixel > 16) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13637
	    spaceBitsPerPixel := 32.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13638
	    (bitsPerPixel > 32) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13639
		spaceBitsPerPixel := bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13640
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13641
	]
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13642
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13643
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13644
    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
 13645
    "/ 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
 13646
    inData := ByteArray new:(bytesPerLine * height).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13647
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13648
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13649
     get the pixels
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13650
    "
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 13651
    aDrawable isForm ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13652
	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
 13653
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13654
	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
 13655
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13656
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13657
    bitsPerPixelIn := info at:#bitsPerPixel.
2533
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 13658
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 13659
    isMSB := ((info at:#byteOrder) == #msbFirst).
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 13660
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 13661
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 13662
    "/ check if bitorder is what I like (msbFirst)
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 13663
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 13664
    "/ mhmh - thats not needed
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 13665
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 13666
    bitsPerPixelIn < 8 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13667
	bitOrder := info at:#bitOrder.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13668
	bitOrder ~~ #msbFirst ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13669
	    inData
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13670
		expandPixels:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13671
		width:(inData size)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13672
		height:1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13673
		into:inData
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13674
		mapping:(ImageReader reverseBits "TODO: reverseBitsForDepth:bitsPerPixelIn").
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13675
	].
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 13676
    ].
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 13677
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 13678
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13679
     check, if the devices padding is different ..
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13680
     or if the bitsPerPixels are different
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13681
    "
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13682
    bytesPerLineIn := (info at:#bytesPerLine).                    "what I got"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13683
    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
 13684
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13685
    maskR := info at:#redMask ifAbsent:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13686
    maskG := info at:#greenMask ifAbsent:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13687
    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
 13688
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13689
    ((bytesPerLine ~~ bytesPerLineIn)
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 13690
    or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13691
	tmpData := inData.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13692
	inData := ByteArray uninitializedNew:(bytesPerLine * height).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13693
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13694
	srcRow := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13695
	dstRow := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13696
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13697
	bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13698
	    "/ for now, only 32 -> 24 is supported
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13699
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13700
	    maskR == 0 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13701
		bitsR := device bitsRed.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13702
		bitsG := device bitsGreen.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13703
		bitsB := device bitsBlue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13704
		maskR := (1 bitShift:bitsR) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13705
		maskG := (1 bitShift:bitsG) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13706
		maskB := (1 bitShift:bitsB) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13707
		shR := device shiftRed negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13708
		shG := device shiftGreen negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13709
		shB := device shiftBlue negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13710
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13711
		shR := (maskR lowBit - 1) negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13712
		bitsR := maskR highBit - maskR lowBit + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13713
		maskR := maskR bitShift:shR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13714
		shG := (maskG lowBit - 1) negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13715
		bitsG := maskG highBit - maskG lowBit + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13716
		maskG := maskG bitShift:shG.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13717
		shB := (maskB lowBit - 1) negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13718
		bitsB := maskB highBit - maskB lowBit + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13719
		maskB := maskB bitShift:shB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13720
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13721
	    shR2 := (8 - bitsR).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13722
	    shG2 := (8 - bitsG).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13723
	    shB2 := (8 - bitsB).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13724
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13725
	    ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13726
		"/ 'reformatting 32->24...' printNL.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13727
		1 to:h do:[:hi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13728
		    srcIndex := srcRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13729
		    dstIndex := dstRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13730
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13731
		    1 to:w do:[:wi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13732
			lword := tmpData doubleWordAt:srcIndex MSB:isMSB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13733
			r := (lword bitShift:shR) bitAnd:maskR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13734
			g := (lword bitShift:shG) bitAnd:maskG.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13735
			b := (lword bitShift:shB) bitAnd:maskB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13736
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13737
			inData at:dstIndex   put:r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13738
			inData at:dstIndex+1 put:g.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13739
			inData at:dstIndex+2 put:b.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13740
			srcIndex := srcIndex + 4.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13741
			dstIndex := dstIndex + 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13742
		    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13743
		    dstRow := dstRow + bytesPerLine.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13744
		    srcRow := srcRow + bytesPerLineIn
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13745
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13746
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13747
		((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13748
		    "/ 'reformatting 16->24...' printNL.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13749
		    1 to:h do:[:hi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13750
			srcIndex := srcRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13751
			dstIndex := dstRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13752
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13753
			1 to:w do:[:wi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13754
			    word := tmpData wordAt:srcIndex MSB:isMSB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13755
			    r := (word bitShift:shR) bitAnd:maskR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13756
			    g := (word bitShift:shG) bitAnd:maskG.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13757
			    b := (word bitShift:shB) bitAnd:maskB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13758
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13759
			    inData at:dstIndex   put:(r bitShift:shR2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13760
			    inData at:dstIndex+1 put:(g bitShift:shG2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13761
			    inData at:dstIndex+2 put:(b bitShift:shB2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13762
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13763
			    srcIndex := srcIndex + 2.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13764
			    dstIndex := dstIndex + 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13765
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13766
			dstRow := dstRow + bytesPerLine.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13767
			srcRow := srcRow + bytesPerLineIn
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13768
		    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13769
		] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13770
		    ('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13771
							bitsPerPixel printString) errorPrintCR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13772
		    self shouldImplement.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13773
		    ^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13774
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13775
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13776
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13777
	    "/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13778
	    "/ repad in the buffer
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13779
	    "/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13780
	    1 to:h do:[:hi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13781
		inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13782
			      with:tmpData startingAt:srcRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13783
		dstRow := dstRow + bytesPerLine.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13784
		srcRow := srcRow + bytesPerLineIn
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13785
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13786
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13787
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13788
	(bytesPerLine * height) ~~ inData size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13789
	    tmpData := inData.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13790
	    inData := ByteArray uninitializedNew:(bytesPerLine * height).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13791
	    inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13792
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13793
    ].
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 13794
    self bits:inData.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13795
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 13796
    "/
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 13797
    "/  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
 13798
    "/
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 13799
    photometric == #palette ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13800
	"/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13801
	"/ 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
 13802
	"/ find out, which colors are in the picture
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13803
	"/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13804
	usedPixels := inData usedValues.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13805
	mapSize := usedPixels max + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13806
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13807
	"get the palette"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13808
	map := Array new:mapSize.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13809
	usedPixels do:[:colorIndex |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13810
	    |i|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13811
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13812
	    i := colorIndex + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13813
	    device getRGBFrom:colorIndex into:[:r :g :b |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13814
		map at:i put:(Color red:r green:g blue:b)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13815
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13816
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13817
	self setColorMap:map.
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 13818
    ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 13819
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 13820
    "Modified: / 9.1.1998 / 21:32:36 / stefan"
2054
3d1619286006 fixed readout from 32bit servers
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
 13821
    "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
 13822
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13823
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13824
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 13825
    "read an image from the display screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 13826
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13827
	      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
 13828
	      (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
 13829
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13830
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13831
	fromScreen:aRectangle
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13832
	on:Screen current
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13833
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13834
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 13835
    "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
 13836
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13837
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13838
fromScreen:aRectangle on:aDevice
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13839
    "read an image from aDevices display screen.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13840
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13841
     and PseudoColor cases have been tested ...
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13842
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 13843
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 13844
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13845
	      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
 13846
	      (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
 13847
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13848
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13849
	fromScreen:aRectangle
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13850
	on:aDevice
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13851
	grab:true
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 13852
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 13853
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 13854
     Image fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 13855
     Image fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 13856
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 13857
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 13858
    "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
 13859
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13860
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13861
fromScreen:aRectangle on:aDevice grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13862
    "read an image from aDevices display screen.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13863
     If the doGrab argument is true, the display
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13864
     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
 13865
     shown while the readout is done.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13866
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13867
     and PseudoColor cases have been tested ...
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13868
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 13869
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 13870
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13871
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13872
	      (use with a false grabArg then)."
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 13873
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 13874
    |curs rootView prevGrab|
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 13875
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 13876
"/    doGrab ifTrue:[ |cid|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13877
"/        curs := Cursor sourceForm:(Image fromFile:'bitmaps/Camera.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13878
"/                         maskForm:(Image fromFile:'bitmaps/Camera_m.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13879
"/                          hotSpot:16@16.
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13880
"/        curs notNil ifTrue:[
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13881
"/            cid := (curs onDevice:aDevice) id
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13882
"/        ].
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 13883
"/    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13884
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13885
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13886
     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
 13887
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13888
    rootView := aDevice rootView.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13889
    doGrab ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13890
	prevGrab := aDevice activePointerGrab.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13891
	aDevice grabPointerInView:rootView withCursor:curs.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13892
    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13893
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13894
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13895
     get the pixels
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 13896
    "
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13897
    [
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13898
	self from:rootView in:aRectangle.
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 13899
    ] ensure:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13900
	doGrab ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13901
	    aDevice ungrabPointer.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13902
	    prevGrab notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13903
		 aDevice grabPointerInView:prevGrab.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13904
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13905
	]
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13906
    ]
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 13907
3092
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 13908
    "
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 13909
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:false
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 13910
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:true
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 13911
    "
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13912
!
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13913
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13914
photometricFromScreen:aDevice
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13915
    "read aDevices display photometric and set my colormap for it.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13916
     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
 13917
     or from an offScreen bitmap, for correct pixel interpretation."
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13918
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13919
    |depth visType bitsPerPixel|
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13920
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13921
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13922
     get some attributes of the display device
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13923
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13924
    visType := aDevice visualType.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13925
    depth := aDevice depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13926
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13927
    "/ kludge for 15bit XFree server
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13928
    depth == 15 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13929
	depth := 16
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13930
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13931
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13932
    (visType == #StaticGray) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13933
	(aDevice blackpixel == 0) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13934
	    photometric := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13935
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13936
	    photometric := #whiteIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13937
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13938
	samplesPerPixel := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13939
	bitsPerPixel := depth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13940
	bitsPerSample := ByteArray with:bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13941
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13942
	 were done, the pixel values are the grey values
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13943
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13944
	^ self
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13945
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13946
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13947
    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13948
	photometric := #rgb.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13949
	samplesPerPixel := 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13950
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13951
	"/ for now - only support 24bit TrueColor
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13952
	depth ~~ 24 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13953
	    'IMAGE: unsupported display depth' errorPrintCR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13954
	].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13955
"/                bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 13956
"/                bitsPerSample := ByteArray with:aDevice bitsRed
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13957
"/                                       with:aDevice bitsGreen
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13958
"/                                       with:aDevice bitsBlue
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13959
	bitsPerPixel := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13960
	bitsPerSample := #[8 8 8].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13961
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13962
	 were done, the pixel values are the rgb values
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13963
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13964
	^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13965
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13966
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13967
    ((visType ~~ #PseudoColor)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13968
    and:[(visType ~~ #StaticColor)
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13969
    and:[visType ~~ #GrayScale]]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13970
	self error:'screen visual not supported'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13971
	^ nil
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13972
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13973
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13974
    photometric := #palette.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13975
    samplesPerPixel := 1.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13976
    bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 13977
    bitsPerSample := ByteArray with:bitsPerPixel.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13978
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13979
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13980
     still need the pixels r/g/b values ...
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13981
    "
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
 13982
    self setColorMap:aDevice colorMap
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13983
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 13984
    "Modified: 11.7.1996 / 11:11:34 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13985
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13986
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13987
!Image methodsFor:'virtual anti-aliased'!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13988
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 13989
vitualAntiAliasedAlongXvertical:bottomOrTop horizontal:leftOrRight form:tempForm color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13990
    |isBottom isLeft additionalY workPoint startX endX pixels pixelPos percent distance nearestKey tmp|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13991
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13992
    isBottom := bottomOrTop sameAs:'bottom'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13993
    isBottom ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13994
        additionalY := -1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13995
    ] ifFalse:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13996
        additionalY := 1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13997
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 13999
    isLeft := leftOrRight sameAs:'left'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14000
    isLeft ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14001
        workPoint := (xRun - 1)@yRun.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14002
        [(
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14003
            (tempForm atX:workPoint x y:workPoint y) == 0 and:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14004
            (tempForm atX:workPoint x y:workPoint y + additionalY) == 1]) and:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14005
            (tempForm atX:workPoint x - 1 y:workPoint y + additionalY) == 1]
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14006
        ] whileTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14007
            startX := workPoint x.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14008
            endX isNil ifTrue:[endX := workPoint x].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14009
            workPoint := (workPoint x - 1)@yRun.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14010
        ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14011
    ] ifFalse:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14012
        workPoint := (xRun + 1)@yRun.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14013
        [(
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14014
            (tempForm atX:workPoint x y:workPoint y) == 0 and:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14015
            (tempForm atX:workPoint x y:workPoint y + additionalY) == 1]) and:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14016
            (tempForm atX:workPoint x + 1 y:workPoint y + additionalY) == 1]
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14017
        ] whileTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14018
            endX := workPoint x.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14019
            startX isNil ifTrue:[startX := workPoint x].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14020
            workPoint := (workPoint x + 1)@yRun.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14021
        ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14022
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14023
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14024
    (startX notNil and:[endX notNil]) ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14025
        startX = endX ifTrue:[        
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14026
            self atImageAndMask:startX@yRun putValue:((colorDictionary at:aColor) at:blendStart).
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14027
        ] ifFalse:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14028
            pixels := (endX - startX) + 1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14029
            startX to:endX do:[:x | 
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14030
                isLeft ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14031
                    pixelPos := (x - startX) + 1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14032
                ] ifFalse:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14033
                    pixelPos := (endX - x) + 1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14034
                ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14035
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14036
                percent := (100 / (pixels / pixelPos)) asFloat / 100.       
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14037
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14038
                (colorDictionary at:aColor) keys do:[:aKey |
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14039
                    nearestKey isNil ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14040
                        distance := percent dist:aKey.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14041
                        nearestKey := aKey.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14042
                    ] ifFalse:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14043
                        tmp := percent dist:aKey.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14044
                        distance > tmp ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14045
                            distance := tmp.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14046
                            nearestKey := aKey.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14047
                        ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14048
                    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14049
                ].        
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14050
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14051
                self atImageAndMask:x@yRun putValue:((colorDictionary at:aColor) at:nearestKey).
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14052
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14053
                distance := nil.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14054
                nearestKey := nil.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14055
            ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14056
        ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14057
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14058
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14059
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14060
vitualAntiAliasedAlongYhorizontal:leftOrRight vertical:bottomOrTop form:tempForm color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14061
    |isLeft isBottom additionalX workPoint startY endY pixels pixelPos percent distance nearestKey tmp|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14062
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14063
    isLeft := leftOrRight sameAs:'left'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14064
    isLeft ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14065
        additionalX := 1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14066
    ] ifFalse:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14067
        additionalX := -1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14068
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14069
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14070
    isBottom := bottomOrTop sameAs:'bottom'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14071
    isBottom ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14072
        workPoint := xRun@(yRun + 1).
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14073
        [(
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14074
            (tempForm atX:workPoint x y:workPoint y) == 0 and:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14075
            (tempForm atX:workPoint x + additionalX y:workPoint y) == 1]) and:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14076
            (tempForm atX:workPoint x + additionalX y:workPoint y + 1) == 1]
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14077
        ] whileTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14078
            endY := workPoint y.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14079
            startY isNil ifTrue:[startY := workPoint y].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14080
            workPoint := xRun@(workPoint y + 1).
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14081
        ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14082
    ] ifFalse:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14083
        workPoint := xRun@(yRun - 1).
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14084
        [(
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14085
            (tempForm atX:workPoint x y:workPoint y) == 0 and:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14086
            (tempForm atX:workPoint x + additionalX y:workPoint y) == 1]) and:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14087
            (tempForm atX:workPoint x + additionalX y:workPoint y - 1) == 1]
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14088
        ] whileTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14089
            startY := workPoint y.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14090
            endY isNil ifTrue:[endY := workPoint y].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14091
            workPoint := xRun@(workPoint y - 1).
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14092
        ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14093
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14094
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14095
    (startY notNil and:[endY notNil]) ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14096
        startY = endY ifTrue:[        
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14097
            self atImageAndMask:xRun@startY putValue:((colorDictionary at:aColor) at:blendStart).
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14098
        ] ifFalse:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14099
            pixels := (endY - startY) + 1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14100
            startY to:endY do:[:y |    
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14101
                isBottom ifTrue:[        
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14102
                    pixelPos := (endY - y) + 1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14103
                ] ifFalse:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14104
                    pixelPos := (y - startY) + 1.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14105
                ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14106
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14107
                percent := (100 / (pixels / pixelPos)) asFloat / 100.        
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14108
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14109
                (colorDictionary at:aColor) keys do:[:aKey |
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14110
                    nearestKey isNil ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14111
                        distance := percent dist:aKey.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14112
                        nearestKey := aKey.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14113
                    ] ifFalse:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14114
                        tmp := percent dist:aKey.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14115
                        distance > tmp ifTrue:[
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14116
                            distance := tmp.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14117
                            nearestKey := aKey.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14118
                        ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14119
                    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14120
                ].        
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14121
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14122
                self atImageAndMask:xRun@y putValue:((colorDictionary at:aColor) at:nearestKey).
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14123
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14124
                distance := nil.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14125
                nearestKey := nil.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14126
            ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14127
        ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14128
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14129
! !
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14130
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
 14131
!Image class methodsFor:'documentation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14132
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14133
version
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 14134
    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.437 2010-11-24 10:18:07 cg Exp $'
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 14135
!
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 14136
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 14137
version_CVS
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 14138
    ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.437 2010-11-24 10:18:07 cg Exp $'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
 14139
! !
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 14140
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14141
Image initialize!