Image.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 28 Feb 2016 14:47:05 +0000
branchjv
changeset 7170 e5374bb05083
parent 7157 9c370b5a2596
child 7177 03d926bea344
permissions -rw-r--r--
Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
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
6755
cee1206f74db class: Image
Claus Gittinger <cg@exept.de>
parents: 6653
diff changeset
    14
"{ NameSpace: Smalltalk }"
cee1206f74db class: Image
Claus Gittinger <cg@exept.de>
parents: 6653
diff changeset
    15
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    16
Object subclass:#Image
6284
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    17
	instanceVariableNames:'pixelFunction bytes width height bitsPerPixel depth colorMap
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
    18
		maxPixelValue rowByteSize bitsPerSample samplesPerPixel
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    19
		photometric device deviceForm monoDeviceForm fullColorDeviceForm
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    20
		mask maskedPixelsAre0 fileName imageSequence'
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    21
	classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    22
		CollectGarbageWhenRunningOutOfColors ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    23
		ImageNotFoundQuerySignal BadImageFormatQuerySignal
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
    24
		ImageSaveErrorSignal ImageLoadErrorSignal FileCreationErrorSignal
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
    25
		CannotRepresentImageSignal InformationLostQuerySignal
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
    26
		UnrepresentableColorSignal ARGB_A_OFFSET_MACHINE
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
    27
		ARGB_R_OFFSET_MACHINE ARGB_G_OFFSET_MACHINE ARGB_B_OFFSET_MACHINE'
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    28
	poolDictionaries:''
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
    29
	category:'Graphics-Images'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    30
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    31
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
    32
!Image class methodsFor:'documentation'!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    33
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    34
copyright
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    35
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    36
 COPYRIGHT (c) 1991 by Claus Gittinger
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
    37
	      All Rights Reserved
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    38
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    39
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    40
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    41
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    42
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    43
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    44
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    45
"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    46
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    47
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    48
documentation
48194c26a46c Initial revision
claus
parents:
diff changeset
    49
"
6284
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    50
    this class provides representation for all kinds of images
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    51
    (monochrome, greyscale and color) and may finally replace Form.
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    52
    Depths of 1, 2, 4, 8, 16, 24 and 32 are supported.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    53
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    54
    An Image keeps all of its information in a device independent way,
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    55
    but may be associated to a device (i.e. getting a device-specific version of it).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    56
    The data held keeps all information which was originally present,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    57
    even if the display-device has lower resolution.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    58
    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
    59
    color information.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    60
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    61
    Images may be created manually (by providing a pixel array),
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    62
    by screen capture, by reading a file (using an ImageReader) or
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    63
    dynamically computed by a pixelFunction (functional image).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    64
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    65
    This gives you a device independent image.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
    66
    For display, a device representation is required, which can be
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    67
    aquired by sending the 'onDevice:aDevice' message to the image. 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    68
    This creates a (possibly dithered) device-form,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    69
    representing the image using the currently available colors.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
    70
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    71
    In rare cases, an explicit monochrome representation of the image is needed
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    72
    (some older 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
    73
    it the message
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
    74
        'monochromeOn:aDevice'.
6284
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    75
ebd0dfb1322c cleanup - removed unused instvars
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
    76
    As this class is very old and originated at times when typical graphic diplays only
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    77
    supported a limited number of colors (16 or 256), you will find a lot of code which deals
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    78
    with color allocation optimizations and dithering. Nowadays, these are hardly ever needed,
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    79
    and most of the time, images will be converted to 24bit truecolor (8x8x8) when converted
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    80
    to a device representation.
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    81
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    82
    An images pixel interpretation is controlled by the photometric instance variable
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    83
    and (if that is #palette) a colorMap.
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    84
    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
    85
    (and using specialized colorMaps for b&w / greyScale images).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    86
    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
    87
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    88
    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
    89
    which have the file-format knowledge built in.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    90
    There are readers for most common formats available
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    91
    (see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.).
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    92
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    93
    File formats are handled by subclasses of ImageReader, which understand
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    94
    a specific format. You can add more readers, by adding an association
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    95
    to the mapping maintained in the MIMETypes class.
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    96
    (see the MIMETypes>>initialize and possibly the display.rc file, where this is done).
286
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    97
39ca471bfaf9 commentary
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    98
    Some algorithms used here (especially dithering & color allocation) are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
    99
    experimental and far from being perfect (some are very slow).
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   100
    For now, the most common cases have been optimized and perform reasonably
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   101
    fast - however, with uncommon depth/visualType combinations, you may
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   102
    run into very slow fallback methods. If this leads to problems, you may have to
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   103
    write a specially tuned (inline-C) version for that case.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   104
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   105
    The pixelFunction enables dynamically computed functional images: instead of
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   106
    providing a byteArray containing pixel data, a function is used which maps
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   107
    x/y coordinates to a pixel value (see examples).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   108
    For display, the bits array is used internally and filled by the function.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   109
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   110
    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
   111
    (may) be done in the future if there is a demand for it ...
6166
87e576aea243 class: Image
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   112
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   113
    Dithering can be controlled by the DitherAlgorithm classVariable:
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   114
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   115
       DitherAlgorithm:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   116
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   117
       nil                  a simple threshold algorithm
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   118
                            (i.e. for mono, p<0.5 -> black, p>=0.5 -> white)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   119
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   120
       #pattern             patterned dither
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   121
                            (for p, take dithered color to fill pixel;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   122
                             uses dithering in color-class)
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   123
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   124
       #error               error diffusion dither (Floyd-Steinberg)
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   125
                            planned - not yet implemented.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   126
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   127
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   128
    Notice:
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   129
        the set of attributes and the way they are stored originated initially 
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   130
        from the need to represent tiff images. These turned out to use a relatively
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   131
        large set of atributes, of which many are unused in other image formats.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   132
        (so it was sufficient).
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   133
        Later, some VisualWorks compatibility protocol was added (mapped palettes, for
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   134
        example), and some stuff could well be redefined in simpler ways.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   135
        We may do that, if we are bored and there is nothing else to improve... ;-)
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
   136
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   137
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   138
    [instance variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   139
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   140
        width               <Integer>       the width in pixels
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   141
        height              <Integer>       the height in pixels
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   142
        bytes               <ByteArray>     the full image information
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   143
        photometric         <Symbol>        #rgb, #palette, #blackIs0 or #whiteIs0
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   144
        samplesPerPixel     <Integer>       the number of planes
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   145
        bitsPerSample       <Array>         the number of bits per plane
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   146
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   147
        colorMap            <Array>         only if photometric is #palette;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   148
                                            maps pixel values to r/g/b values.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   149
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   150
        device              <Workstation>   the device on which deviceForm,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   151
                                            monoDeviceForm and lowResDeviceForm are
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   152
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   153
        deviceForm          <Form>          the device form which gives the best
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   154
                                            possible aproximation of the image on
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   155
                                            device using standard colors.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   156
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   157
        monoDeviceForm      <Form>          the device form which gives a monochrome
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   158
                                            aproximation of the image on device.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   159
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   160
        fullColorDeviceForm <Form>          the device form which gives the best
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   161
                                            possible aproximation of the image on
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   162
                                            device using private colors.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   163
                                            (not yet implemented)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   164
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   165
        mask                <ImageMask>     an optional mask;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   166
                                            if non-nil, only pixels for which the
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   167
                                            corresponding mask bit is non-zero
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   168
                                            are drawn.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   169
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   170
        maskedPixelsAre0    <Boolean>       a hint for image processors and drawers
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   171
                                            if true, masked pixels are known to be
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   172
                                            zero in the pixel bytes.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   173
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   174
        fileName            <String>        the name of the file from which the
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   175
                                            image was loaded - nil otherwise.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   176
                                            Useful for image save functions
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   177
                                            and for the UIPainter utility.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   178
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   179
        imageSequence                       the imageSequence, of which the
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   180
                                            instance is a frame or nil,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   181
                                            if its not part of a sequence.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   182
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   183
        bitsPerPixel                        not used in ST/X
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   184
        depth                               - these have been added in instVar-slots
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   185
        maxPixelValue                       - according to the ST-80's image class.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   186
        rowByteSize                         - to allow loading of st-80 images
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   187
                                            - (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
   188
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   189
    [class variables:]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   190
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   191
        Lobby               <Registry>      keeps track of known images
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   192
                                            (for resource freeing with garbage collector)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   193
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   194
        DitherAlgorithm     <Symbol>        defines how to dither
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   195
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   196
        NumberOfDitherColors <Integer>      defines, how many dither colors to use
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   197
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   198
        FileFormats         <Dictionary>    associates filename extensions to
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   199
                                            image reader classes (now set-up in startup-file)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   200
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   201
        CollectGarbageWhenRunningOutOfColors
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   202
                            <Boolean>       if true, and we run out of available
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   203
                                            device colors during creation of a
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   204
                                            device image, collect garbage for
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   205
                                            possible image reclamation.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   206
                                            If false, proceed immediately.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   207
                                            Default is true.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   208
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   209
        ImageNotFoundQuerySignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   210
                            <QuerySignal>   raised, if an image could not be loaded
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   211
                                            from a file. The parameter is the images
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   212
                                            fileName.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   213
                                            A handler may return a replacement
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   214
                                            image or proceed with nil.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   215
                                            If unhandled, a nil is returned from the
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   216
                                            image creation.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   217
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   218
        BadImageFormatQuerySignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   219
                            <QuerySignal>   raised, if an image could not be loaded
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   220
                                            from a file due to a file error or
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   221
                                            unsupported format.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   222
                                            A handler may return a replacement
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   223
                                            image or proceed with nil.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   224
                                            If unhandled, a nil is returned from the
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   225
                                            image creation.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   226
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   227
        ImageSaveErrorSignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   228
                            <Signal>        parent of errors below.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   229
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   230
        FileCreationErrorSignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   231
                            <Signal>        file could not be created when saving an
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   232
                                            image.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   233
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   234
        CannotRepresentImageSignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   235
                            <Signal>        the specified ImageReader cannot represent
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   236
                                            the given image.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   237
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   238
        InformationLostQuerySignal
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   239
                            <Signal>        the specified ImageReader can represent
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   240
                                            the given image, but some information
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   241
                                            (typically color resolution) is lost.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   242
                                            If unhandled, the save proceeds as usual.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   243
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   244
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   245
    caveat:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   246
        the information in
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   247
            photometric, bitsPerPixel, bitsPerSample, samplesPerPixel, depth , colorMap and maxPixelValue
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   248
        is partially redundant and its handling stupid (not to say: braindamaged ;-).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   249
        The only excuse is that it grew over time, had to incorporate various alien/older schemes for
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   250
        compatibility reasons. All of the above belongs into the single colorMap which must migrate from
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   251
        a stupid seqColl to a color-aware real colorMap.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   252
        (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
   253
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   254
    todo:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   255
        support alpha masks
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   256
        cleanup the dithering & conversion code
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   257
        cleanup the color/photometric mess
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   258
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
   259
    [See also:]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   260
        Form Icon ImageReader
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   261
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   262
    [author:]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   263
        Claus Gittinger
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   264
"
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   265
!
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   266
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   267
examples
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   268
"
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   269
    reading from a file (many formats are supported):
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   270
    (notice, that the bitmaps directory is searched for along
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   271
     the system path - therefore, you may add your own bitmap
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   272
     directory to the beginning of the path and thus override
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   273
     any default bitmaps, or make certain that your application
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   274
     finds its bitmaps - even if they are in a separate directory)
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   275
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   276
                                                                                        [exBegin]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   277
        (Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') inspect
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   278
                                                                                        [exEnd]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   279
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   280
    better use package relative file names:
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   281
                                                                                        [exBegin]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   282
        (Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies') inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   283
                                                                                        [exEnd]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   284
    various file formats are supported:
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   285
                                                                                        [exBegin]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   286
        (Image fromFile:'bitmaps/xpmBitmaps/misc_icons/SmalltalkX_clr.xpm' inPackage:'stx:goodies') inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   287
                                                                                        [exEnd]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   288
                                                                                        [exBegin]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   289
        (Image fromFile:'bitmaps/winBitmaps/okSmily_up.bmp' inPackage:'stx:goodies') inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   290
                                                                                        [exEnd]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   291
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   292
    The following examples demonstrate various depth and colorMap variations ...
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   293
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   294
    inline image:
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   295
      default: depth=1 & #blackIs0
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   296
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   297
        (Image 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   298
            width:8 height:8
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   299
            fromArray:#( 2r11111111
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   300
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   301
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   302
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   303
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   304
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   305
                         2r10000001
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   306
                         2r11111111 )
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   307
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   308
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   309
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   310
      with #whiteIs0 photometric
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   311
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   312
        ((Image width:8 height:8
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   313
               fromArray:#( 2r11111111
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   314
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   315
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   316
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   317
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   318
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   319
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   320
                            2r11111111 ))
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   321
            photometric:#whiteIs0
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   322
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   323
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   324
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   325
      with a colorMap
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   326
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   327
        ((Image width:8 height:8
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   328
               fromArray:#( 2r11111111
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   329
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   330
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   331
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   332
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   333
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   334
                            2r10000001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   335
                            2r11111111 ))
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   336
            colorMap:(Array with:(Color red)
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   337
                            with:(Color yellow))
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   338
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   339
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   340
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   341
      a depth4 greyScale image:
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   342
      (default photometric is #blackIs0)
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   343
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   344
        (Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   345
             width:8
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   346
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   347
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   348
                            16r00 16r11 16r22 16r33
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   349
                            16r44 16r55 16r66 16r77
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   350
                            16r88 16r99 16raa 16rbb
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   351
                            16rcc 16rdd 16ree 16rff
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   352
                        ]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   353
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   354
                                                                        [exEnd]
2645
a82f50c19af1 comment
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
   355
      the same, magnified:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   356
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   357
        ((Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   358
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   359
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   360
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   361
                            16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   362
                            16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   363
                            16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   364
                            16rcd 16ref
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   365
                        ])
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   366
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   367
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   368
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   369
      the following has the same effect:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   370
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   371
        ((Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   372
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   373
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   374
             depth:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   375
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   376
                            16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   377
                            16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   378
                            16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   379
                            16rcd 16ref
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   380
                        ])
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   381
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   382
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   383
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   384
      with reverse grey-interpretation:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   385
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   386
        ((Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   387
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   388
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   389
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   390
                            16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   391
                            16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   392
                            16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   393
                            16rcd 16ref
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   394
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   395
            photometric:#whiteIs0;
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   396
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   397
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   398
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   399
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   400
      with 1-bit-per-pixel rgb interpretation:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   401
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   402
        ((Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   403
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   404
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   405
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   406
                            16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   407
                            16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   408
                            16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   409
                            16rcd 16ref
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   410
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   411
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   412
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   413
            bitsPerSample:#(1 1 1);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   414
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   415
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   416
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   417
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   418
      with 1/2/1 rgb interpretation:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   419
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   420
        ((Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   421
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   422
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   423
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   424
                            16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   425
                            16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   426
                            16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   427
                            16rcd 16ref
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   428
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   429
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   430
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   431
            bitsPerSample:#(1 2 1);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   432
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   433
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   434
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   435
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   436
      a 2/2/0 rgb image (i.e. no blue):
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   437
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   438
         |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   439
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   440
         i := Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   441
                    width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   442
                    height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   443
                    fromArray:#[ 16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   444
                                 16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   445
                                 16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   446
                                 16rcd 16ref ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   447
         i photometric:#rgb.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   448
         i samplesPerPixel:3.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   449
         i bitsPerSample:#(2 2 0).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   450
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   451
         i := i magnifiedBy:30.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   452
         i edit.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   453
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   454
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   455
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   456
      a 0/0/4 rgb image (i.e. no red or green):
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   457
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   458
         |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   459
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   460
         i := Depth4Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   461
                    width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   462
                    height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   463
                    fromArray:#[ 16r01 16r23
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   464
                                 16r45 16r67
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   465
                                 16r89 16rab
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   466
                                 16rcd 16ref ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   467
         i photometric:#rgb.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   468
         i samplesPerPixel:3.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   469
         i bitsPerSample:#(0 0 4).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   470
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   471
         i := i magnifiedBy:30.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   472
         i edit.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   473
                                                                        [exEnd]
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   474
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   475
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   476
      a 2plane greyscale image:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   477
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   478
        ((Depth2Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   479
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   480
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   481
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   482
                            4r0123
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   483
                            4r1230
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   484
                            4r2301
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   485
                            4r3012
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   486
                        ])
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   487
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   488
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   489
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   490
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   491
      with colors:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   492
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   493
        ((Depth2Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   494
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   495
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   496
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   497
                            4r0123
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   498
                            4r1230
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   499
                            4r2301
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   500
                            4r3012
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   501
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   502
            colorMap:(Array with:(Color black)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   503
                            with:(Color red)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   504
                            with:(Color green)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   505
                            with:(Color blue));
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   506
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   507
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   508
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   509
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   510
      depth8 image with 3/3/2 rgb interpretation:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   511
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   512
        ((Depth8Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   513
             width:16
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   514
             height:16
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   515
             fromArray:(ByteArray withAll:(0 to:16rFF)))
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   516
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   517
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   518
            bitsPerSample:#(3 3 2);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   519
            magnifiedBy:10
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   520
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   521
                                                                        [exEnd]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   522
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
   523
      depth8 image with 2/2/2 rgb interpretation:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   524
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   525
        ((Depth8Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   526
             width:8
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   527
             height:8
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   528
             fromArray:(ByteArray withAll:(0 to:16r3F)))
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   529
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   530
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   531
            bitsPerSample:#(2 2 2);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   532
            magnifiedBy:10
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   533
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   534
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   535
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   536
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   537
        ((Depth8Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   538
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   539
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   540
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   541
                    16r30 16r0C  16r03 16r3F
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   542
                    16r20 16r08  16r02 16r2A
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   543
                    16r10 16r04  16r01 16r15
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   544
                    16r00 16r00  16r00 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   545
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   546
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   547
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   548
            bitsPerSample:#(2 2 2);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   549
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   550
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   551
                                                                        [exEnd]
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
   552
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   553
      trueColor image: remember: bytes are MSB
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   554
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   555
        ((Depth16Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   556
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   557
             height:5
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   558
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   559
                    2r01111100 2r00000000  2r00000011 2r11100000  2r00000000 2r00011111  2r01111111 2r11111111
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   560
                    2r00111100 2r00000000  2r00000001 2r11100000  2r00000000 2r00001111  2r00111101 2r11101111
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   561
                    2r00011100 2r00000000  2r00000000 2r11100000  2r00000000 2r00000111  2r00011100 2r11100111
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   562
                    2r00001100 2r00000000  2r00000000 2r01100000  2r00000000 2r00000001  2r00001100 2r01100011
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   563
                    2r00000100 2r00000000  2r00000000 2r00100000  2r00000000 2r00000001  2r00000100 2r00100001
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   564
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   565
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   566
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   567
            bitsPerSample:#(5 5 5);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   568
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   569
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   570
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   571
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   572
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   573
        ((Depth24Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   574
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   575
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   576
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   577
                    16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00  16rFF 16r00 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   578
                    16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00  16r00 16rFF 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   579
                    16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF  16r00 16r00 16rFF
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   580
                    16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF  16rFF 16rFF 16rFF
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   581
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   582
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   583
            samplesPerPixel:3;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   584
            bitsPerSample:#(8 8 8);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   585
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   586
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   587
                                                                        [exEnd]
4762
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   588
f70af9e4a5f1 comment
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
   589
      32bit trueColor image:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   590
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   591
        ((Depth32Image
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   592
             width:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   593
             height:4
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   594
             fromArray:#[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   595
                    16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00  16rFF 16r00 16r00 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   596
                    16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00  16r00 16rFF 16r00 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   597
                    16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00  16r00 16r00 16rFF 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   598
                    16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00  16rFF 16rFF 16rFF 16r00
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   599
                        ])
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   600
            photometric:#rgb;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   601
            samplesPerPixel:4;
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   602
            bitsPerSample:#(8 8 8 8);
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   603
            magnifiedBy:30
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   604
        ) edit
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   605
                                                                        [exEnd]
2760
94d2d524081b example added (24-bit image)
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
   606
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   607
    storing - only a subset of formats (TIFF, XBM, XPM) currently support storing:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   608
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   609
        |img|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   610
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   611
        img := Image fromFile:'bitmaps/winBitmaps/okSmily_up.bmp' inPackage:'stx:goodies'.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   612
        img saveOn:'myImage.tiff'.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   613
        (Image fromFile:'myImage.tiff') inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   614
        img saveOn:'myImage.gif'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   615
        (Image fromFile:'myImage.gif') inspect.
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   616
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   617
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   618
    magnifying (any factor):
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   619
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   620
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   621
            magnifiedTo:(48@48))
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   622
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   623
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   624
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   625
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   626
            magnifiedBy:0.7)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   627
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   628
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   629
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   630
    rotating (any angle in degrees clockwise):
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   631
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   632
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   633
            rotated:90)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   634
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   635
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   636
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   637
        (((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   638
            magnifiedBy:0.3@0.7) rotated:270)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   639
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   640
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   641
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   642
        (((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   643
            ) rotated:30)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   644
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   645
                                                                        [exEnd]
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
   646
    negative:
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   647
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   648
        ((Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies')
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   649
            negative)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   650
                inspect
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   651
                                                                        [exEnd]
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   652
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   653
      depth32 image with 8+8+8+8 argb interpretation:
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   654
                                                                        [exBegin]
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   655
        ((Depth32Image
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   656
             width:4 height:4
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   657
             fromArray:#[ 
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   658
                255 255 0 0       255 255 0 0       255 255 0 0       255 255 0 0
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   659
                255 0 255 0       255 0 255 0       255 0 255 0       255 0 255 0
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   660
                255 0 0 255       255 0 0 255       255 0 0 255       255 0 0 255
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   661
                255 255 255 255   255 255 255 255   255 255 255 255   255 255 255 255 ])
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   662
            photometric:#argb;
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   663
            samplesPerPixel:4;
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   664
            bitsPerSample:#(8 8 8 8);
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   665
            magnifiedBy:10
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   666
        ) edit
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   667
                                                                        [exEnd]
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
   668
7126
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   669
      depth32 image with 8+8+8+8 rgba interpretation:
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   670
                                                                        [exBegin]
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   671
        ((Depth32Image
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   672
             width:4 height:4
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   673
             fromArray:#[ 
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   674
                255 0 0 255       255 0 0 255       255 0 0 255       255 0 0 255
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   675
                0 255 0 255       0 255 0 255       0 255 0 255       0 255 0 255
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   676
                0 0 255 255       0 0 255 255       0 0 255 255       0 0 255 255
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   677
                255 255 255 255   255 255 255 255   255 255 255 255   255 255 255 255 ])
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   678
            photometric:#rgba;
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   679
            samplesPerPixel:4;
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   680
            bitsPerSample:#(8 8 8 8);
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   681
            magnifiedBy:10
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   682
        ) edit
a81b992fd069 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 7123
diff changeset
   683
                                                                        [exEnd]
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   684
"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   685
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   686
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   687
examples_functionalImages
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   688
"
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   689
    Functional images (please read 'Functional Images' by Conal Elliot, Microsoft Research).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   690
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   691
    Plain x/y mapping:
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   692
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   693
        |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   694
        i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   695
        i pixelFunction:[:x :y | ((x // 16) bitXor:(y // 16)) odd ifTrue:1 ifFalse:[0]].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   696
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   697
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   698
    Transformed x/y mapping:
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   699
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   700
        |i f|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   701
        f := [:x :y | (x between:0.4 and:0.6) asInteger].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   702
        i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   703
        i pixelFunction:f inX:(0.0 to:1.0) y:(0.0 to:1.0).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   704
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   705
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   706
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   707
        |i f|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   708
        f := [:x :y | ((x between:0.4 and:0.6) or:[(y between:0.4 and:0.6)]) asInteger].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   709
        i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   710
        i pixelFunction:f inX:(0.0 to:1.0) y:(0.0 to:1.0).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   711
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   712
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   713
    Image based on polar coordinate:
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   714
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   715
        |i f|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   716
        f := [:x :y | ((x@y) r * 10) asInteger bitAnd:1].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   717
        i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   718
        i pixelFunction:f inX:(-1.0 to:1.0) y:(-1.0 to:1.0).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   719
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   720
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   721
    Grayscale image based on polar coordinate:
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   722
                                                                        [exBegin]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   723
        |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   724
        i := Depth8Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   725
        i photometric:#blackIs0.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   726
        i pixelFunction:[:x :y | ((x@y) r * 255) truncated min:255] inX:(-1 to:1) y:(-1 to:1).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   727
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   728
                                                                        [exEnd]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   729
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   730
    Taking another image as ''input''
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   731
                                                                        [exBegin]
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   732
        |garfield f i h|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   733
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   734
        garfield := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   735
        h := garfield height.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
   736
        f := [:x :y | (garfield colorAtX:x y:h-y) rgbValue].
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   737
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   738
        i := Depth24Image extent:garfield extent.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   739
        i pixelFunction:f.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   740
        i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
   741
                                                                        [exEnd]
649
38e6d0015137 examples
Claus Gittinger <cg@exept.de>
parents: 622
diff changeset
   742
"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   743
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   744
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   745
!Image class methodsFor:'initialization'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   746
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   747
addReader:aReaderClass suffix:aSuffix
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
   748
    <resource: #obsolete>
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   749
    "register an additional image reader.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   750
     This is provided for subclasses, to regster themself when
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   751
     loaded (or from the startup scripts)"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   752
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   753
    self obsoleteMethodWarning.
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   754
    self addReader:aReaderClass suffix:aSuffix mimeType:nil
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   755
!
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   756
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   757
addReader:aReaderClass suffix:aSuffix mimeType:mimeType
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
   758
    <resource: #obsolete>
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   759
    "register an additional image reader.
1800
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   760
     This interface is kept for backward compatibility.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   761
     The knowledge has been concentrated in MIMETypes"
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   762
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   763
    self obsoleteMethodWarning.
1b4d3067bdc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1799
diff changeset
   764
    MIMETypes
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   765
	defineImageType:mimeType suffix:aSuffix reader:aReaderClass
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   766
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   767
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   768
     Image addReader:GIFReader suffix:'gif'
1780
b20be7704d6f added mimeType
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
   769
     Image addReader:GIFReader suffix:'gif' mimeType:'image/gif'
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   770
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   771
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   772
    "Modified: 30.6.1997 / 21:59:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   773
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   774
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   775
fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   776
    "return the collection of supported file formats.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   777
     The returned dictionary maps file-extensions to image reader classes."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   778
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   779
    ^ MIMETypes fileSuffixToImageReaderMapping
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   780
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   781
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   782
     Image fileFormats
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   783
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   784
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   785
    "Modified: 30.6.1997 / 22:05:58 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   786
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
   787
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   788
flushDeviceImages
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   789
    "simply release all deviceForms"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   790
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   791
    Lobby do:[:anImage |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
   792
	anImage release
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   793
    ]
869
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   794
464ffa8c0c67 comment
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
   795
    "Modified: 15.6.1996 / 15:45:02 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   796
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   797
48194c26a46c Initial revision
claus
parents:
diff changeset
   798
initialize
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   799
    "initialize class constants"
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
   800
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   801
    "setup tracker of known pictures"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   802
    Lobby isNil ifTrue:[
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   803
        Lobby := Registry new.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   804
        ObjectMemory addDependent:self.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   805
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   806
        "/ define the algorithm to use for dithering -
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   807
        "/ supported values are:
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   808
        "/      #threshold
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   809
        "/      #ordered
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   810
        "/      #floydSteinberg
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   811
        "/      #burkes
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   812
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   813
        DitherAlgorithm := #floydSteinberg.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   814
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   815
        (Display notNil and:[Display hasGrayscales]) ifFalse:[
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   816
            NumberOfDitherColors := 64
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   817
        ] ifTrue:[
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   818
            "as far as I remember, this is about the number of grey values, the eye can distinguish"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   819
            NumberOfDitherColors := 100
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   820
        ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   821
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   822
        "define reader classes"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   823
        self initializeFileFormatTable.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   824
        self initializeMIMETable.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   825
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   826
        CollectGarbageWhenRunningOutOfColors := false.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   827
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   828
        ImageErrorSignal := Error newSignalMayProceed:true.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   829
        ImageErrorSignal nameClass:self message:#imageErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   830
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   831
        ImageSaveErrorSignal := ImageErrorSignal newSignalMayProceed:true.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   832
        ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   833
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   834
        FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   835
        FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   836
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   837
        CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   838
        CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   839
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   840
        ImageLoadErrorSignal := QuerySignal new.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   841
        ImageLoadErrorSignal nameClass:self message:#imageLoadErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   842
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   843
        ImageNotFoundQuerySignal := QuerySignal new.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   844
        ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   845
        ImageNotFoundQuerySignal parent:ImageLoadErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   846
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   847
        InformationLostQuerySignal := QuerySignal new.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   848
        InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   849
        InformationLostQuerySignal parent:ImageLoadErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   850
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   851
        BadImageFormatQuerySignal := QuerySignal new.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   852
        BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   853
        BadImageFormatQuerySignal parent:ImageLoadErrorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   854
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   855
        UnrepresentableColorSignal := ImageErrorSignal newSignalMayProceed:true.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   856
        UnrepresentableColorSignal nameClass:self message:#unrepresentableColorSignal.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   857
    ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   858
    UninterpretedBytes isBigEndian ifTrue:[
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   859
        ARGB_A_OFFSET_MACHINE := 1.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   860
        ARGB_R_OFFSET_MACHINE := 2.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   861
        ARGB_G_OFFSET_MACHINE := 3.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   862
        ARGB_B_OFFSET_MACHINE := 4.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   863
    ] ifFalse:[ 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   864
        ARGB_A_OFFSET_MACHINE := 4.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   865
        ARGB_R_OFFSET_MACHINE := 3.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   866
        ARGB_G_OFFSET_MACHINE := 2.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   867
        ARGB_B_OFFSET_MACHINE := 1.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   868
    ].
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   869
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   870
    "Modified: / 18-05-1999 / 15:50:03 / cg"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
   871
    "Modified: / 28-02-2016 / 14:36:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   872
!
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
   873
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   874
initializeFileFormatTable
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   875
    "initialize a default table to map from file extension to reader class.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
   876
     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
   877
     see the 'smalltalk.rc'/'display.rc' startup files for a real (full) map."
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   878
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   879
    MIMETypes notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   880
	MIMETypes imageReaderForSuffix:'xbm'  put:XBMReader.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   881
	MIMETypes imageReaderForSuffix:'tiff' put:TIFFReader.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   882
	MIMETypes imageReaderForSuffix:'gif'  put:GIFReader.
1814
5d413419cf51 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1802
diff changeset
   883
    ].
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   884
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   885
    "
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   886
     Image initializeFileFormatTable
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
   887
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
   888
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   889
    "Modified: 30.6.1997 / 22:07:28 / cg"
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   890
!
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   891
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   892
initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   893
    "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
   894
     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
   895
     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
   896
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   897
    MIMETypes notNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   898
	MIMETypes mimeTypeForSuffix:'gif'       put:'image/gif'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   899
	MIMETypes mimeTypeForSuffix:'tiff'      put:'image/tiff'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   900
	MIMETypes mimeTypeForSuffix:'tif'       put:'image/tiff'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   901
	MIMETypes mimeTypeForSuffix:'xbm'       put:'image/x-xbitmap'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   902
	MIMETypes mimeTypeForSuffix:'xpm'       put:'image/x-xpixmap'.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
   903
    ].
1785
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   904
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   905
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   906
     Image initializeMIMETable
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   907
    "
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   908
3196d65f5fa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1784
diff changeset
   909
    "Created: 27.6.1997 / 16:43:48 / cg"
1815
50212910fc13 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   910
    "Modified: 21.7.1997 / 17:33:59 / cg"
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   911
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
   912
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   913
update:something with:aParameter from:changedObject
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   914
    "flush all device specific stuff when restarted from a snapshot"
48194c26a46c Initial revision
claus
parents:
diff changeset
   915
48194c26a46c Initial revision
claus
parents:
diff changeset
   916
    (something == #restarted) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
   917
	self flushDeviceImages
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   918
    ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   919
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
   920
    "Created: 21.6.1996 / 19:47:43 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   921
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
   922
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
   923
!Image class methodsFor:'instance creation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
   924
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   925
extent:ext
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   926
    "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
   927
     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
   928
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   929
    ^ 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
   930
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   931
    "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
   932
    "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
   933
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
   934
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   935
extent:ext depth:d
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   936
    "ST-80 compatibility"
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   937
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
   938
    ^ self width:ext x height:ext y depth:d
3023
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   939
!
cb063801decd more Squeak compatibility
ps
parents: 2980
diff changeset
   940
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   941
extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   942
    ^ 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
   943
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   944
    "
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   945
	|colorMap aaImgArray|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   946
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   947
	colorMap := Array with:Color white with:Color blue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   948
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   949
	aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   950
	aaImgArray last
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   951
	    fillAntiAliasedArc:200@200
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   952
	    radius:80
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   953
	    from:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   954
	    angle:360
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   955
	    withColor:Color blue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   956
	    antiAliasedPalette:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   957
	    startWith:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   958
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   959
	aaImgArray last inspect.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   960
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   961
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   962
	|colorMap aaImgArray|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   963
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   964
	colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   965
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   966
	aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   967
	aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   968
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   969
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   970
	aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   971
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   972
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   973
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   974
	aaImgArray last inspect.
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
   975
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   976
    "
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   977
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   978
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   979
extent:ext depth:d antiAliasedPalette:aBasicColorArray bgColor:bgColor mixedArray:mixedArray
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   980
    |colors colorMap colorIndex colorDictionary tmpDic newImage emptyBits|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   981
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   982
    colors := OrderedCollection new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   983
    colorMap := OrderedCollection new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   984
    colorIndex := 0.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   985
    colorDictionary := Dictionary new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   986
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
   987
    aBasicColorArray do:[:aColor |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   988
	colorMap add:aColor.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   989
	colorIndex := colorIndex + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   990
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   991
	tmpDic := Dictionary new.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   992
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   993
	mixedArray do:[:aFloat |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   994
	    tmpDic at:aFloat put:colorIndex.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   995
	    colorMap add:(aColor mixed:aFloat with:bgColor).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   996
	    colorIndex := colorIndex + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   997
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   998
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
   999
	colorDictionary at:aColor put:tmpDic.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1000
    ].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1001
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1002
    newImage := (self implementorForDepth:d) new.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1003
    newImage width:ext x height:ext y depth:d palette:colorMap.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1004
    newImage createPixelStore.
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1005
"/    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1006
"/    newImage bits:emptyBits.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1007
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1008
    ^ Array with:colorDictionary with:mixedArray first with:newImage
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1009
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1010
    "
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1011
	|colorMap aaImgArray|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1012
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1013
	colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1014
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1015
	aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1016
	aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1017
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1018
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1019
	aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1020
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1021
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1022
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1023
	aaImgArray last inspect.
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1024
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1025
 ###################
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  1026
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1027
	|colorMap aaImgArray|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1028
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1029
	colorMap := Array with:Color white with:Color blue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1030
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1031
	aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1032
	aaImgArray last
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1033
	    fillAntiAliasedArc:200@200
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1034
	    radius:80
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1035
	    from:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1036
	    angle:360
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1037
	    withColor:Color blue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1038
	    antiAliasedPalette:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1039
	    startWith:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1040
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1041
	aaImgArray last inspect.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1042
    "
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1043
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1044
    "Modified: / 02-11-2010 / 20:57:41 / cg"
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1045
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  1046
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1047
extent:ext depth:d bits:bits
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1048
    "ST-80 compatibility; assume 32-bit padding"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1049
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1050
    ^ self extent:ext depth:d bits:bits pad:32
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1051
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1052
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1053
extent:ext depth:d bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1054
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1055
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1056
    ^ self width:ext x height:ext y depth:d fromArray:bits pad:padding
24
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1057
!
e810b1be068b *** empty log message ***
claus
parents: 17
diff changeset
  1058
1276
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1059
extent:ext depth:d bitsPerPixel:bpp palette:aColormap usingBits:bits
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1060
    "ST-80 compatibility"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1061
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1062
    |img|
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1063
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1064
    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
  1065
    img colorMap:aColormap.
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1066
    ^ img
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1067
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1068
    "Created: 25.1.1997 / 03:50:22 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1069
    "Modified: 25.1.1997 / 12:27:35 / cg"
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1070
!
ec4112f62da7 ST-80 stuff
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
  1071
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1072
extent:ext depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1073
    "create & return a blank image of the given size.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1074
     ST-80 compatibility"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1075
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1076
    |newImage emptyBits|
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1077
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1078
    newImage := (self implementorForDepth:d) new.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1079
    newImage width:ext x height:ext y depth:d palette:aColormap.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1080
    newImage createPixelStore.
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1081
"/    emptyBits := ByteArray new:(newImage bytesPerRow * ext y).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1082
"/    newImage bits:emptyBits.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1083
    ^ newImage
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1084
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1085
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1086
     Image extent:16@16 depth:8 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1087
     Image extent:16@16 depth:4 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1088
     Image extent:16@16 depth:2 palette:nil
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1089
    "
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1090
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1091
    "Created: / 06-03-1997 / 15:24:01 / cg"
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
  1092
    "Modified: / 02-11-2010 / 20:56:53 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1093
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  1094
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1095
extent:ext depth:d palette:aColormap bits:bits
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1096
    "ST-80 compatibility"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1097
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1098
    ^ self extent:ext depth:d palette:aColormap bits:bits pad:16
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1099
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1100
    "Modified: 7.10.1996 / 11:32:16 / cg"
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1101
!
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1102
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1103
extent:ext depth:d palette:aColormap bits:bits pad:padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1104
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1105
1070
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1106
    |img|
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1107
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1108
    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
  1109
    img colorMap:aColormap.
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1110
    ^ img
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1111
6a695c4bb749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1063
diff changeset
  1112
    "Modified: 7.10.1996 / 11:32:00 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1113
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1114
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1115
extent:ext fromArray:bits offset:offset
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1116
    "ST-80 compatibility"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1117
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1118
    ^ self width:ext x height:ext y fromArray:bits
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1119
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1120
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1121
fromForm:aForm
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1122
    "create & return an Image given a aForm"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1123
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1124
    ^ self fromSubForm:(0@0 extent:aForm extent) in:aForm
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1125
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1126
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1127
     |f|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1128
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1129
     f := Form width:16 height:16.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1130
     f clear.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1131
     f displayLineFromX:0 y:0 toX:15 y:15.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1132
     f inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1133
     (Image fromForm:f) inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1134
    "
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1135
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1136
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1137
     |f|
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1138
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1139
     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
  1140
     f clear.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1141
     f paint:(Color red).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1142
     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
  1143
     f paint:(Color green).
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1144
     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
  1145
     f inspect.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1146
     (Image fromForm:f) inspect
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1147
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  1148
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1149
    "Modified: 11.7.1996 / 11:21:42 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1150
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1151
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1152
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1153
    "create & return an Image given another image. This can be used to
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1154
     convert an image to another depth."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1155
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1156
    ^ 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
  1157
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1158
    "
3448
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1159
     |i i2 idx|
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1160
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1161
     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
  1162
     i2 := i deepCopy.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1163
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1164
     idx := i2 colorMap indexOfPaintNearest:(Color green).
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1165
     i2 colorMap at:idx put:Color red.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1166
     i2 inspect.
44cbe8a45067 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3433
diff changeset
  1167
     i inspect.
3259
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
!
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
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1172
    "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
  1173
     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
  1174
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1175
    (self == Image
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1176
    or:[anImage class == self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  1177
	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
  1178
    ^ self new fromImage:anImage photometric:photometricOrNil.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1179
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1180
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1181
     |i1 i8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1182
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1183
     i1 := Image fromFile:'goodies/bitmaps/SBrowser.xbm'.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1184
     i8 := Depth8Image fromImage:i1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1185
     i8 inspect
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1186
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1187
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1188
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1189
fromSubForm:aRectangle in:aForm
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1190
    "create & return an subImage given a aForm"
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1191
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1192
    |depth device vis img photometric|
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1193
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1194
    depth := aForm depth.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1195
    device := aForm device.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1196
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1197
    photometric := (depth > 8) ifTrue:#rgb ifFalse:#palette.
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1198
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1199
    (device notNil and:[depth == device depth]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1200
	"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1201
	"/ for truecolor displays, return a Depth24Image
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1202
	"/ (must do this for depth15 & depth16 displays, since
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1203
	"/  Depth16Image has no way to specify r/g/b masks ...)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1204
	"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1205
	vis := device visualType.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1206
	(vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1207
	    depth > 8 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1208
		depth := 24.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1209
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1210
	].
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1211
    ].
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1212
    img := self newForDepth:depth.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1213
    img photometric:photometric.
4937
1b0ebaed9336 photometric fix
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
  1214
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1215
    device isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1216
	^ img from:aForm in:aRectangle.
3026
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1217
    ].
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1218
    ^ img from:aForm in:aRectangle
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1219
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1220
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1221
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1222
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1223
     f := Form width:16 height:16.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1224
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1225
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1226
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1227
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1228
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1229
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1230
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1231
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1232
     |f|
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1233
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1234
     f := Form width:16 height:16 depth:(Display depth) on:Display.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1235
     f clear.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1236
     f paint:(Color red).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1237
     f displayLineFromX:0 y:0 toX:15 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1238
     f paint:(Color green).
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1239
     f displayLineFromX:15 y:0 toX:0 y:15.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1240
     f inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1241
     (Image fromForm:f) inspect.
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1242
     (Image fromSubForm:(5@5 corner:10@10) in:f) inspect
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1243
    "
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1244
!
7107903826d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3023
diff changeset
  1245
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1246
fromSubImage:anImage in:aRectangle
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1247
    "create & return an Image from a rectangular area in another image.
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1248
     This can also be used to get a subimage in another depth.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1249
     As with layouts, the rectangle may contain integers (= nr of pixels) or float numbers (= relative size).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1250
     Color precision may be lost, if conversion is from a higher depth image. 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1251
     For palette & rgb images, this may fail if a color cannot be represented."
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1252
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1253
    |cls|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1254
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1255
    self == Image ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1256
        cls := (self implementorForDepth:anImage depth).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1257
    ] ifFalse:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1258
        cls := self.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1259
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1260
    ^ cls new fromSubImage:anImage in:aRectangle.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1261
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1262
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1263
     |i1 i8|
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1264
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1265
     i1 := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1266
     i8 := Depth8Image fromSubImage:i1 in:(250@90 extent:50@50).
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1267
     i8 inspect
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1268
    "
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1269
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1270
     |i1 i8|
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1271
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1272
     i1 := Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1273
     i8 := Image fromSubImage:i1 in:(70@50 extent:50@50).
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1274
     i8 inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1275
    "
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1276
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1277
     |i1 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1278
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1279
     i1 := Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1280
     i24 := Depth24Image fromSubImage:i1 in:(70@50 extent:50@50).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1281
     i24 inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1282
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1283
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1284
     |i1 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1285
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1286
     i1 := Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1287
     i1 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1288
     i24 := Depth24Image fromSubImage:i1 in:(0.25@0.25 extent:0.5@0.5).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1289
     i24 inspect
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  1290
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1291
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1292
    "Created: 20.9.1995 / 01:05:43 / claus"
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  1293
    "Modified: 24.4.1997 / 23:13:02 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1294
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1295
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1296
new
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1297
    "create a new image. Redefined to set the photometric to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1298
     greyScale with black being 0 as default."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1299
4416
fb209558d622 proper #initialize
Claus Gittinger <cg@exept.de>
parents: 4415
diff changeset
  1300
    ^ self basicNew initialize
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1301
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1302
    "Modified: 10.6.1996 / 18:08:37 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1303
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1304
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1305
newForDepth:depth
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1306
    "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
  1307
     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
  1308
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1309
    |cls|
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1310
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1311
    cls := self implementorForDepth:depth.
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1312
    ^ cls new
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1313
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1314
    "
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1315
     Image newForDepth:8
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1316
    "
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1317
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1318
    "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
  1319
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1320
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1321
width:w height:h
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1322
    "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
  1323
     Assume a depth of 1, unless an explicit imageClass is the receiver."
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1324
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1325
    |cls|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1326
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1327
    cls := self.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1328
    cls == Image ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1329
	cls := self implementorForDepth:1
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1330
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1331
    ^ cls new width:w height:h
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1332
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  1333
    "Modified: / 06-06-2007 / 11:10:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1334
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1335
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1336
width:w height:h depth:d
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1337
    "create a new image, given width, height and depth"
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1338
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1339
    ^ (self newForDepth:d)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1340
	width:w height:h depth:d
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1341
!
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1342
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1343
width:w height:h depth:d fromArray:pixelData
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1344
    "create a new image, given width, height, depth and data.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1345
     Data must be a ByteArray containing correctly aligned bits for the specified
134
claus
parents: 132
diff changeset
  1346
     depth (8-bit padded)."
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1347
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1348
    ^ (self newForDepth:d)
7101
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1349
        width:w height:h depth:d fromArray:pixelData
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1350
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1351
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1352
     Image width:8
7101
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1353
           height:8
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1354
           depth:1
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1355
           fromArray:#[2r11001100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1356
                       2r00110011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1357
                       2r11001100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1358
                       2r00110011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1359
                       2r11001100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1360
                       2r00110011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1361
                       2r11001100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1362
                       2r00110011].
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1363
    "
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1364
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
  1365
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1366
     Image width:8
7101
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1367
           height:8
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1368
           depth:2
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1369
           fromArray:#[4r1100 4r1100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1370
                       4r0011 4r0011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1371
                       4r1100 4r1100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1372
                       4r0011 4r0011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1373
                       4r1100 4r1100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1374
                       4r0011 4r0011
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1375
                       4r1100 4r1100
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1376
                       4r0011 4r0011].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1377
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1378
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1379
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1380
     Image width:8
7101
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1381
           height:8
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1382
           depth:4
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1383
           fromArray:#[16r00 16r01 16rf0 16rf1
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1384
                       16r02 16r03 16rf2 16rf3
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1385
                       16r04 16r05 16rf4 16rf5
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1386
                       16r06 16r07 16rf6 16rf7
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1387
                       16r08 16r09 16rf8 16rf9
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1388
                       16r0a 16r0b 16rfa 16rfb
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1389
                       16r0c 16r0d 16rfc 16rfd
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1390
                       16r0e 16r0f 16rfe 16rff].
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1391
    "
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1392
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1393
    "
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1394
     Image width:8
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1395
           height:8
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1396
           depth:16
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1397
           fromArray:#(1 1 1 1 1 1 1 1
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1398
                       2 2 2 2 2 2 2 2    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1399
                       3 3 3 3 3 3 3 3    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1400
                       4 4 4 4 4 4 4 4    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1401
                       5 5 5 5 5 5 5 5    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1402
                       6 6 6 6 6 6 6 6    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1403
                       7 7 7 7 7 7 7 7    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1404
                       8 8 8 8 8 8 8 8    
8c2377f29588 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 6900
diff changeset
  1405
                      ) asWordArray.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1406
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1407
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1408
    "Modified: 10.6.1996 / 18:18:10 / cg"
132
claus
parents: 125
diff changeset
  1409
!
claus
parents: 125
diff changeset
  1410
134
claus
parents: 132
diff changeset
  1411
width:w height:h depth:d fromArray:pixelData pad:padding
claus
parents: 132
diff changeset
  1412
    "create a new image, given width, height, depth and data.
claus
parents: 132
diff changeset
  1413
     Data must be a ByteArray containing correctly aligned bits for the specified
claus
parents: 132
diff changeset
  1414
     depth."
claus
parents: 132
diff changeset
  1415
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1416
    |img newBits
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1417
     srcRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1418
     dstRowBytes "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  1419
     nextDstIndex "{ Class: SmallInteger }"
2527
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1420
     srcIndex "{ Class: SmallInteger }"
5391e6e2c8a6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2526
diff changeset
  1421
     dstIndex "{ Class: SmallInteger }" |
134
claus
parents: 132
diff changeset
  1422
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  1423
    img := (self newForDepth:d) width:w height:h depth:d .
134
claus
parents: 132
diff changeset
  1424
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1425
    srcRowBytes := ((w * d + padding - 1) bitShift:-5) bitShift:2.
5341
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1426
    dstRowBytes := img bytesPerRow.
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1427
ede63c3764ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5326
diff changeset
  1428
    (padding ~~ 8 and:[(srcRowBytes \\ 4 ~~ 0) or:[srcRowBytes ~= dstRowBytes]]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1429
	"must repad; ST/X uses byte padding, while ST-80 uses longword
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1430
	 padding. This is stupid, and may be changed in ST/X with future versions.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1431
	"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1432
	dstRowBytes := img bytesPerRow.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1433
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1434
	newBits := ByteArray uninitializedNew:(dstRowBytes * h).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1435
	srcIndex := 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1436
	dstIndex := 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1437
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1438
	1 to:h do:[:row |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1439
	    nextDstIndex := dstIndex + dstRowBytes.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1440
	    newBits replaceFrom:dstIndex
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1441
			     to:(nextDstIndex - 1)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1442
			   with:pixelData
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1443
		     startingAt:srcIndex.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1444
	    srcIndex := srcIndex + srcRowBytes.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1445
	    dstIndex := nextDstIndex.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1446
	].
134
claus
parents: 132
diff changeset
  1447
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1448
	pixelData class isBytes ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1449
	    newBits := ByteArray withAll:pixelData
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1450
	] ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1451
	    newBits := pixelData
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  1452
	]
134
claus
parents: 132
diff changeset
  1453
    ].
claus
parents: 132
diff changeset
  1454
    img bits:newBits.
claus
parents: 132
diff changeset
  1455
    ^ img
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1456
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  1457
    "Modified: / 27-05-2007 / 14:01:32 / cg"
134
claus
parents: 132
diff changeset
  1458
!
claus
parents: 132
diff changeset
  1459
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1460
width:w height:h fromArray:anArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1461
    "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
  1462
     receiving class is Image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1463
     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
  1464
     (i.e. 8 bits per byte)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1465
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1466
    |cls d pixels|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1467
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1468
    cls := self.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1469
    cls == Image ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1470
	cls := self implementorForDepth:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1471
	d := 1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1472
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1473
	d := cls imageDepth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1474
    ].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1475
    anArray class isBytes ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1476
	pixels := ByteArray withAll:anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1477
    ] ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1478
	pixels := anArray
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1479
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1480
    ^ cls new width:w height:h depth:d fromArray:pixels
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1481
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1482
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1483
     Image width:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1484
	   height:8
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1485
	   fromArray:#[2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1486
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1487
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1488
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1489
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1490
		       2r00110011
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1491
		       2r11001100
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1492
		       2r00110011].
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  1493
    "
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1494
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  1495
    "Modified: 8.6.1996 / 10:07:26 / cg"
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1496
!
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1497
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1498
width:w height:h photometric:photometric
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1499
    "create a new image, given width, height.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1500
     Assume a depth of 1, unless an explicit imageClass is the receiver."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1501
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1502
    |cls|
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1503
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1504
    cls := self.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1505
    cls == Image ifTrue:[
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1506
        cls := self implementorForDepth:1
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1507
    ].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1508
    ^ cls new width:w height:h; photometric:photometric; yourself
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1509
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1510
    "Modified: / 06-06-2007 / 11:10:55 / cg"
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1511
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  1512
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1513
width:w height:h photometric:photometric bitsPerSample:bitsPerSample
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1514
    "create a new image, given width, height.
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1515
     Assume a depth of 1, unless an explicit imageClass is the receiver."
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1516
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1517
    |cls|
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1518
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1519
    cls := self.
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1520
    cls == Image ifTrue:[
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1521
        cls := self implementorForDepth:1
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1522
    ].
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1523
    ^ cls new width:w height:h; photometric:photometric; bitsPerSample:bitsPerSample; yourself
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1524
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  1525
    "Modified: / 06-06-2007 / 11:10:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1526
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1527
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1528
!Image class methodsFor:'Signal constants'!
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1529
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1530
badImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1531
    "return the (query-) signal, which is raised if some
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1532
     bitmap-image could not be loaded due to an unrecognized format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1533
     If unhandled, the image-load returns nil.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1534
     Otherwise, it returns whatever the handler proceeds with.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1535
     The exception gets either the images fileName or an input stream
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1536
     as parameter"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1537
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1538
    ^ BadImageFormatQuerySignal
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1539
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1540
    "Created: 1.2.1997 / 14:40:29 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1541
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1542
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1543
cannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1544
    "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
  1545
     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
  1546
     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
  1547
     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
  1548
     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
  1549
     (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
  1550
     format then."
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1551
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1552
    ^ CannotRepresentImageSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1553
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1554
    "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
  1555
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1556
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1557
fileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1558
    "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
  1559
     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
  1560
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1561
    ^ FileCreationErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1562
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1563
    "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
  1564
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1565
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1566
imageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1567
    "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
  1568
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1569
    ^ ImageErrorSignal
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1570
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1571
    "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
  1572
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  1573
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1574
imageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1575
    "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
  1576
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1577
    ^ ImageLoadErrorSignal
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1578
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1579
    "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
  1580
!
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  1581
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1582
imageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1583
    "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
  1584
     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
  1585
     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
  1586
     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
  1587
     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
  1588
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1589
    ^ ImageNotFoundQuerySignal
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1590
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1591
    "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
  1592
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1593
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1594
imageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1595
    "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
  1596
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1597
    ^ ImageSaveErrorSignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1598
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1599
    "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
  1600
!
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1601
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1602
informationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1603
    "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
  1604
     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
  1605
     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
  1606
     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
  1607
     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
  1608
     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
  1609
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1610
    ^ InformationLostQuerySignal
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1611
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
  1612
    "Created: 27.2.1997 / 12:43:50 / cg"
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1613
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1614
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1615
unrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1616
    "return the signal, which is raised if some color is not
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1617
     representable in the image (when storing a pixel)."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1618
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1619
    ^ UnrepresentableColorSignal
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1620
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  1621
    "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
  1622
! !
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1623
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1624
!Image class methodsFor:'cleanup'!
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1625
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1626
releaseResourcesOnDevice:aDevice
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1627
    "this is sent when a display connection is closed,
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1628
     to release all cached Images from that device"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1629
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1630
    Lobby
6390
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1631
        unregisterAllForWhich:[:eachImage |
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1632
            |ok|
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1633
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1634
            ok := eachImage graphicsDevice == aDevice.
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1635
            ok ifTrue:[
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1636
                eachImage releaseFromDevice
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1637
            ].
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1638
            ok
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1639
        ].
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1640
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1641
    "
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1642
      self releaseResourcesOnDevice:Screen current
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
  1643
    "
1230
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1644
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1645
    "Created: 16.1.1997 / 19:30:44 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1646
    "Modified: 16.1.1997 / 19:33:49 / cg"
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1647
! !
279016623d5a resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents: 1175
diff changeset
  1648
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1649
!Image class methodsFor:'file reading'!
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1651
fromFile:aFileName
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1652
    "read an image from a file - this methods tries to find
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1653
     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
  1654
     and lets the appropriate reader read the file.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1655
     Also, unless the path is absolute,
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1656
     all bitmap directories along the searchPath are checked
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1657
     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
  1658
     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
  1659
     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
  1660
     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
  1661
     proceed with some replacement image. If unhandled, nil is returned."
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1662
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1663
    |image fn nm inStream suffix readerClass
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1664
     mustDecompress readersErrorMsg|
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1665
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1666
    "before trying each reader, check if the file is readable"
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1667
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1668
    fn := aFileName asFilename.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1669
    fn isAbsolute ifFalse:[
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1670
        inStream := Smalltalk systemFileStreamFor:fn.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1671
        inStream isNil ifTrue:[
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1672
            inStream := Smalltalk bitmapFileStreamFor:fn.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1673
            inStream isNil ifTrue:[
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1674
                "this signal is a query - if noone seems to care, return nil.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1675
                 However, a handler may provide a replacement image."
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1676
                ^ ImageNotFoundQuerySignal
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1677
                            raiseRequestWith:fn
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1678
                            errorString:('IMAGE [warning]: ''' , fn pathName, ''' does not exist or is not readable').
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1679
            ].
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1680
        ].
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1681
        fn := inStream pathName asFilename.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1682
        inStream close.
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1683
    ].
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1684
4158
930761d24ab2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4156
diff changeset
  1685
    nm := fn name.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1686
    suffix := fn suffix.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1687
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1688
    "handle compressed-suffix"
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1689
    (#('gz') includes:suffix) ifTrue:[
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1690
        |baseFn|
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1691
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1692
        baseFn := fn withoutSuffix.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1693
        nm := baseFn name.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1694
        suffix := baseFn suffix.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1695
        mustDecompress := true.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1696
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1697
    suffix isEmpty ifTrue:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1698
        suffix := nm.
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1699
    ].
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1700
6507
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1701
    "get the imageReader class from the file's extension and ask it first"
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1702
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1703
    readerClass notNil ifTrue:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1704
        mustDecompress == true ifTrue:[
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1705
            |zipStream|
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1706
            inStream := fn readStream.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1707
            zipStream := ZipStream readOpenOn:inStream suppressHeaderAndChecksum:true.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1708
            zipStream notNil ifTrue:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1709
                [
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1710
                    image := readerClass fromStream:zipStream.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1711
                ] ensure:[
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1712
                    zipStream close.
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1713
                    inStream close.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1714
                ].
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1715
            ]
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1716
        ] ifFalse:[
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1717
            BadImageFormatQuerySignal handle:[:ex |
6586
9d16907daea8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6532
diff changeset
  1718
                BadImageFormatQuerySignal isHandled ifTrue:[ ex reject ].
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1719
                Transcript showCR:(readersErrorMsg := ex description).
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1720
                image := nil.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1721
                ex return.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1722
            ] do:[
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1723
                image := readerClass fromFile:fn.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1724
            ].
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1725
        ].
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1726
        image notNil ifTrue:[^ image].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1727
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1728
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1729
    (readerClass isNil or:[readersErrorMsg notNil]) ifTrue:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1730
        "no known extension (or wrong extension)
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1731
         - ask all readers if they know this format ...
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1732
         ... these look into the file, and investigate the header.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1733
         therefore, it takes a bit longer."
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1734
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1735
        MIMETypes imageReaderClasses do:[:mimeReaderClass |
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1736
            (mimeReaderClass notNil
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1737
            and:[mimeReaderClass ~~ readerClass]) ifTrue:[
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1738
               (mimeReaderClass isValidImageFile:fn) ifTrue:[
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1739
                    image := mimeReaderClass fromFile:fn.
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1740
                    image notNil ifTrue:[
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1741
                        ^ image
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1742
                    ]
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1743
                ]
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1744
            ]
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1745
        ].
4159
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1746
    ].
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1747
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1748
    "nope - unknown format
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1749
     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
  1750
     However, a handler may provide a replacement image."
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1751
3656
11670e0e6fcb invalid format notification fixed
Claus Gittinger <cg@exept.de>
parents: 3623
diff changeset
  1752
    ^ BadImageFormatQuerySignal
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1753
        raiseRequestWith:fn
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1754
        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
  1755
d27c88bc4c79 Fix image reading
Stefan Vogel <sv@exept.de>
parents: 4158
diff changeset
  1756
    "
6532
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1757
     Image fromFile:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1758
     Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1759
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1760
     Image fromFile:'bitmaps/winBitmaps/a11.ico' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1761
     Image fromFile:'bitmaps/xpmBitmaps/countries/czech.xpm' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1762
     Image fromFile:'bitmaps/xpmBitmaps/countries/czech.xpm.gz' inPackage:'stx:goodies'
f50614a23989 class: Image
Stefan Vogel <sv@exept.de>
parents: 6507
diff changeset
  1763
     Image fromFile:'Demos/bitmaps/hello_world.icon' inPackage:'stx:clients'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1764
    "
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1765
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1766
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1767
     Image fromFile:'fooBar'
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1768
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1769
1774
4241f730e0a6 fixed gunzipped image reading;
Claus Gittinger <cg@exept.de>
parents: 1771
diff changeset
  1770
    "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
  1771
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1772
     Image imageNotFoundQuerySignal
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1773
     handle:[:ex |
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1774
        Transcript showCR:ex description.
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1775
        ex proceedWith:nil
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1776
     ] do:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1777
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1778
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1779
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1780
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1781
    "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
  1782
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1783
     Image imageNotFoundQuerySignal
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
  1784
     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
  1785
     do:[
6375
b31008047817 class: Image
Claus Gittinger <cg@exept.de>
parents: 6370
diff changeset
  1786
         Image fromFile:'fooBar'
1156
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1787
     ]
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1788
    "
71ded63a3fae dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents: 1143
diff changeset
  1789
4843
36621a8aafd5 care for absolute filename when loading an image
Claus Gittinger <cg@exept.de>
parents: 4793
diff changeset
  1790
    "Modified: / 19-11-2007 / 15:50:52 / cg"
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1791
!
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1792
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1793
fromFile:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1794
    "read an image for a package from a file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1795
     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
  1796
     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
  1797
     and lets the appropriate reader read the file.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1798
     Also, all bitmap directories along the searchPath are checked
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1799
     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
  1800
     separate directory, thereby overriding system bitmaps easily.
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1801
     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
  1802
     the ImageNotFoundQuerySignal is raised, which may be handled to
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1803
     proceed with some replacement image. If unhandled, nil is returned."
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1804
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1805
    ^ Smalltalk imageFromFileNamed:aFileName inPackage:aPackage
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1806
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1807
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1808
     Image fromFile:'libtool/bitmaps/SBrowser.xbm'
3426
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1809
     Image fromFile:'bitmaps/SBrowser.xbm' inPackage:'stx:libtool'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1810
     Image fromFile:'garfield.gif' inPackage:'stx:goodies/bitmaps/gifImages'
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1811
    "
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1812
!
ebd06c83448e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3389
diff changeset
  1813
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1814
fromFile:aFileName on:aDevice
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1815
    "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
  1816
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1817
     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
  1818
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1819
    |img|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1820
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1821
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1822
    img notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1823
	^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1824
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1825
    ^ nil
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1826
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1827
    "Modified: 1.2.1997 / 14:48:07 / cg"
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1828
!
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1829
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1830
fromFile:aFileName resolution:res
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1831
    "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
  1832
     as appropriate (only req'd for very high resolution displays).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1833
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1834
     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
  1835
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1836
    ^ self fromFile:aFileName resolution:res on:nil
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1837
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1838
    "Created: 19.12.1996 / 14:02:13 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1839
    "Modified: 1.2.1997 / 14:48:16 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1840
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1841
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1842
fromFile:aFileName resolution:dpi on:aDevice
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1843
    "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
  1844
     as appropriate (only req'd with very high resolution displays).
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1845
     Prepare a device representation.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1846
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1847
     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
  1848
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1849
    |img dev dpiH mag|
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1850
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1851
    img := self fromFile:aFileName.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1852
    img isNil ifTrue:[^ nil].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1853
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1854
    "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
  1855
    dev := aDevice.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1856
    dev isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1857
	"should not happen ..."
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1858
	dev := Screen current
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1859
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1860
3059
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1861
    dev notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1862
	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
  1863
    ] ifFalse:[
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1864
	dpiH := 90
0895d23678ac assume 90dpi in #fromFile:resolution: if there is no current display
Claus Gittinger <cg@exept.de>
parents: 3038
diff changeset
  1865
    ].
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1866
    ((dpi >= (dpiH * 0.75)) and:[dpi <= (dpiH * 1.5)]) ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1867
    mag := (dpiH / dpi) rounded.
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1868
    mag = 0 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1869
    mag = 1 ifTrue:[^ img].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1870
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1871
    img := img magnifiedBy:(mag @ mag).
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1872
    aDevice notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1873
	^ img onDevice:aDevice
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1874
    ].
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  1875
    ^ img
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1876
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1877
    "Modified: 1.2.1997 / 14:48:20 / cg"
1139
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1878
!
416e6abb408f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1879
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1880
fromStream:aStream
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1881
    "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
  1882
     out the file format itself (by contents)
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1883
     and lets the appropriate reader read the file.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1884
     To do this, the stream must be positionable.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1885
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1886
     if the stream does not contain an appropriate image."
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1887
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1888
    |image|
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1889
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1890
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1891
     ask all readers if they know
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1892
     this format ...
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1893
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  1894
    MIMETypes imageReaderClasses do:[:readerClass |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1895
	readerClass notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1896
	    image := readerClass fromStream:aStream.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1897
	    image notNil ifTrue:[^ image].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1898
	]
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1899
    ].
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1900
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1901
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1902
     nope - unknown format
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1903
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1904
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1905
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1906
    ^ ImageNotFoundQuerySignal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1907
		raiseRequestWith:aStream
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1908
		errorString:('IMAGE [warning]: unknown image file format in stream').
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1909
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1910
    "
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1911
     Image fromFile:'goodies/bitmaps/gifImages/claus.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1912
     Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1913
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1914
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1915
     Image fromFile:'clients/Animation/bitmaps/globe1.xbm.Z'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1916
     Image fromFile:'clients/Demos/bitmaps/hello_world.icon'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1917
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1918
     Image fromFile:'librun/stx.ico'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1919
     Image fromFile:'libwidg3/bitmaps/wall.tiff'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1920
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  1921
     Image fromFile:'goodies/bitmaps/test.fax'
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1922
     Image fromFile:'fileIn/bitmaps/founders.im8'
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  1923
     Image fromFile:'goodies/faces/next.com/steve.face'
1051
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1924
    "
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1925
5605bf1b10b9 allow reading from Streams
Claus Gittinger <cg@exept.de>
parents: 1043
diff changeset
  1926
    "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
  1927
    "Modified: 30.6.1997 / 22:03:59 / cg"
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1928
!
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1929
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1930
fromStream:aStream using:aReaderClass
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1931
    "read an image from a stream, given an imageReaderClass.
6507
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1932
     Use this, if you know the file's format, but it has an invalid
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1933
     extension (or non-definite header), so #fromStream: could not
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1934
     find out the images format.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1935
     Return nil (or whatever a handler returned),
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1936
     if the stream does not contain an appropriate image."
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1937
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1938
    |image|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1939
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1940
    image := aReaderClass fromStream:aStream.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1941
    image notNil ifTrue:[^ image].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1942
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1943
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1944
     nope - unknown format
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1945
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1946
"/    'Image [info]: unknown image file format in stream: ' infoPrintCR.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1947
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1948
    ^ ImageNotFoundQuerySignal
6507
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1949
                raiseRequestWith:aStream
05fb9b9d9e53 class: Image
Claus Gittinger <cg@exept.de>
parents: 6496
diff changeset
  1950
                errorString:('IMAGE: unknown image file format in stream').
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1951
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1952
    "Created: 1.2.1997 / 14:46:20 / cg"
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  1953
    "Modified: 1.2.1997 / 14:48:53 / cg"
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1954
! !
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1955
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  1956
!Image class methodsFor:'misc'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1957
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1958
ditherAlgorithm
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1959
    "return the way we dither -
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1960
	#threshold, or nil        -> no dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1961
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1962
	#error or #floydSteinberg -> errorDiffusion; much better
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1963
	#burkes                   -> errorDiffusion; even better."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1964
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1965
    ^ DitherAlgorithm
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1966
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1967
    "Created: 17.6.1996 / 18:57:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1968
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1969
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1970
ditherAlgorithm:aSymbol
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  1971
    "define how to dither -
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1972
	#threshold, or nil        -> no dither
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1973
	#pattern, or #ordered     -> orderedDither (ugly, but fast)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1974
	#error or #floydSteinberg -> errorDiffusion; much better
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1975
	#burkes                   -> errorDiffusion; even better."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1976
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1977
    DitherAlgorithm := aSymbol
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1978
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1979
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1980
     Image dither:#pattern
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1981
     Image dither:#floydSteinberg
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1982
     Image dither:#burkes
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1983
     Image dither:nil
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1984
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1985
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1986
    "Modified: 10.6.1996 / 12:27:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  1987
    "Created: 17.6.1996 / 18:57:19 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1988
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1989
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1990
numberOfDitherColors:n
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1991
    "define how many colors (i.e. patterns) to use when
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  1992
     doing a pattern dither"
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
    NumberOfDitherColors := n
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1995
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1996
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1997
orderedDitherMatrixOfSize:sz
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  1998
    sz == 2 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  1999
	^ #[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2000
		0 2
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2001
		3 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2002
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2003
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2004
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2005
    sz == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2006
	^ #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2007
		 0  8  2 10
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2008
		12  4 14  6
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2009
		 3 11  1  9
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2010
		15  7 13  5
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2011
	   ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2012
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2013
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2014
    sz == 8 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2015
	^  #[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2016
		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
  2017
	       48 16 56 24   50 18 58 26
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2018
	       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
  2019
	       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
  2020
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2021
		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
  2022
	       51 19 59 27   49 17 57 25
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2023
	       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
  2024
	       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
  2025
	    ].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2026
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2027
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2028
    ^ nil
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2029
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  2030
    "Created: 7.6.1996 / 14:15:05 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2031
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2032
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  2033
!Image class methodsFor:'queries'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2034
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2035
bytesPerRowForWidth:width depth:bitsPerPixel padding:padding
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2036
    "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
  2037
     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
  2038
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2039
    |bitsPerRow paddedUnitsPerRow|
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2040
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2041
    bitsPerRow := width * bitsPerPixel.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2042
    paddedUnitsPerRow := bitsPerRow // padding.
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2043
    ((bitsPerRow \\ padding) ~~ 0) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2044
	paddedUnitsPerRow := paddedUnitsPerRow + 1
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2045
    ].
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2046
    ^ paddedUnitsPerRow * (padding // 8)
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2047
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2048
    "
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2049
     self bytesPerRowForWidth:7 depth:1 padding:8
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2050
     self bytesPerRowForWidth:7 depth:1 padding:16
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2051
     self bytesPerRowForWidth:7 depth:1 padding:32
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2052
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2053
     self bytesPerRowForWidth:15 depth:1 padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2054
     self bytesPerRowForWidth:15 depth:1 padding:16
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2055
     self bytesPerRowForWidth:15 depth:1 padding:32
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  2056
    "
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2057
!
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
  2058
6797
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2059
defaultImageFileWriter
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2060
    "only used, if a file is saved with no particular extension
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2061
     or explicit writer given.
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2062
     For now, default to tiff format.
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2063
     Will change to png, as soon as all mask formats are fully supported by it"
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2064
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2065
    ^ TIFFReader
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2066
!
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
  2067
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2068
defaultPhotometric
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2069
    "return the default photometric pixel interpretation.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2070
     This may be a somewhat old leftover from times, when tiff was the first image file type to be read.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2071
     Much better would be to always have some (possibly fake and virtual) colormap around, and ask that one.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2072
     However, in the meantime, many other classes depend on that, so that it should be kept as an API 
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2073
     - even when the internal representation will be replaced by something better in the future."
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2074
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2075
    ^ #blackIs0
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2076
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2077
    "Modified: 20.4.1996 / 23:40:41 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2078
    "Created: 10.6.1996 / 18:08:12 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2079
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2080
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2081
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2082
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2083
     this class.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2084
     Must be redefined in concrete subclasses"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2085
2913
c51ac85e9aa2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2891
diff changeset
  2086
    ^ self subclassResponsibility
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2087
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 518
diff changeset
  2088
    "Modified: 20.4.1996 / 23:40:41 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2089
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2090
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2091
imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2092
    "return a collection of suffixes which are recognized as image-file suffix"
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2093
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2094
    ^ MIMETypes imageFileSuffixes
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2095
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2096
    "
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2097
     Image imageFileSuffixes
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2098
    "
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2099
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2100
    "Modified: 30.6.1997 / 22:04:39 / cg"
1306
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2101
!
d56585b0e8c0 checkin from browser
ca
parents: 1289
diff changeset
  2102
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2103
imageReaderClassForMIME:mimeType
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2104
    "return an appropriate imageReader class for a given mime type;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2105
     nil if there is none (or it did not install itself)"
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2106
1801
3dff7fb2bd59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1800
diff changeset
  2107
    ^ MIMETypes imageReaderForType:mimeType
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2108
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2109
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2110
     Image imageReaderClassForMIME:'image/tiff'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2111
     Image imageReaderClassForMIME:'image/x-portable-pixmap'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2112
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2113
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2114
    "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
  2115
    "Modified: 30.6.1997 / 21:54:10 / cg"
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2116
!
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2117
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2118
imageReaderClassForSuffix:aSuffix
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2119
    "return an appropriate imageReader class for a given file-suffix;
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2120
     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
  2121
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2122
    ^ MIMETypes imageReaderForSuffix:aSuffix
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2123
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2124
    "
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2125
     Image imageReaderClassForSuffix:'tiff'
1783
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2126
     Image imageReaderClassForSuffix:'foo'
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2127
    "
7a487f0d4000 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2128
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
  2129
    "Modified: 30.6.1997 / 22:05:14 / cg"
1572
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2130
!
029910ee5c9e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1570
diff changeset
  2131
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  2132
implementorForDepth:depth
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2133
    "return the class, which best implements images of depth"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2134
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2135
    depth == 1 ifTrue:[^ Depth1Image].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2136
    depth == 2 ifTrue:[^ Depth2Image].
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2137
    depth <= 4 ifTrue:[^ Depth4Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2138
    depth <= 8 ifTrue:[^ Depth8Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2139
    depth <= 16 ifTrue:[^ Depth16Image].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  2140
    depth <= 24 ifTrue:[^ Depth24Image].
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2141
    depth <= 32 ifTrue:[^ Depth32Image].
5299
6b1d1dcf5c85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5237
diff changeset
  2142
    depth <= 48 ifTrue:[^ Depth48Image].
5313
7c40ea0163ee *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5299
diff changeset
  2143
    depth <= 64 ifTrue:[^ Depth64Image].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2144
    ^ self
1664
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2145
42b1af0353c2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
  2146
    "Modified: 24.4.1997 / 19:04:52 / cg"
1611
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2147
!
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2148
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2149
isImageFileSuffix:aSuffix
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2150
    "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
  2151
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2152
     ^ self imageFileSuffixes includes:(aSuffix asLowercase)
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2153
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2154
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2155
     Image isImageFileSuffix:'gif'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2156
     Image isImageFileSuffix:'xbm'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2157
     Image isImageFileSuffix:'foo'
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2158
    "
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2159
8ec019a529b4 added convenient #isImageFileSuffix:
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
  2160
    "Created: 18.4.1997 / 14:55:28 / cg"
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2161
!
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2162
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2163
mimeTypeFromSuffix:suffix
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2164
    "search my suffix information for a mime type and
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2165
     return it; return nil if unknown"
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2166
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2167
    ^ MIMETypes mimeTypeForSuffix:suffix
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2168
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2169
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2170
     Image mimeTypeFromSuffix:'gif'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2171
     Image mimeTypeFromSuffix:'tiff'
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2172
     Image mimeTypeFromSuffix:'foobar'
1786
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2173
    "
302b8208bf6c more mime stuff
Claus Gittinger <cg@exept.de>
parents: 1785
diff changeset
  2174
1802
9a3d7c669727 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2175
    "Modified: 1.7.1997 / 00:17:27 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2176
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2177
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  2178
!Image class methodsFor:'screen capture'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2179
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2180
fromScreen
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2181
    "return an image of the full screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2182
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2183
	      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
  2184
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2185
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2186
    |display|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2187
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2188
    display := Screen current.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2189
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2190
	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
  2191
	on:display
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2192
	grab:true
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2193
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2194
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2195
     Image fromScreen
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2196
     Image fromScreen inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2197
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2198
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2199
    "Modified: 26.3.1997 / 10:44:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2200
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2201
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2202
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2203
    "return an image of a part of the screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2204
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2205
	      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
  2206
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2207
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2208
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2209
	fromScreen:aRectangle
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2210
	on:Screen current
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2211
	grab:true
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2212
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2213
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2214
     Image fromScreen:(0@0 corner:100@100)
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2215
     (Image fromScreen:(0@0 corner:100@100)) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2216
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2217
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2218
    "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
  2219
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2220
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2221
fromScreen:aRectangle on:aDevice
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2222
    "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
  2223
     another display device.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2224
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2225
	      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
  2226
	      (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
  2227
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2228
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2229
	fromScreen:aRectangle
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2230
	on:aDevice
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2231
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2232
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2233
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2234
     Image fromScreen:(0@0 corner:100@100)
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2235
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2236
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2237
    "get a snapshot of your friends screen ...
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2238
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2239
     |dpy2|
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2240
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2241
     dpy2 := XWorkstation new initializeFor:'idefix:0'.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2242
     (Image fromScreen:(dpy2 bounds) on:dpy2) inspect
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2243
    "
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2244
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2245
    "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
  2246
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2247
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2248
fromScreen:aRectangle on:aDisplay grab:doGrab
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2249
    "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
  2250
     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
  2251
     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
  2252
     shown while the readout is done.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2253
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2254
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2255
	      (use with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2256
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2257
    |depth vis img|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2258
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2259
    depth := aDisplay depth.
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2260
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2261
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2262
    "/ 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
  2263
    "/ (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
  2264
    "/  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
  2265
    "/
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2266
    vis := aDisplay visualType.
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2267
    (vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2268
	depth > 8 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2269
	    depth := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2270
	]
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2271
    ].
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2272
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  2273
    img := self newForDepth:depth.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2274
    ^ img fromScreen:aRectangle on:aDisplay grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2275
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
  2276
    "Modified: / 26.1.1998 / 22:23:08 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2277
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2278
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2279
fromScreenArea
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2280
    "return an image of a part of the screen;
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2281
     let user specify screen area.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2282
     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
  2283
     Use #fromUser for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2284
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2285
	      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
  2286
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2287
2102
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2288
    |r|
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2289
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2290
    [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
  2291
    r := Rectangle fromUser.
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2292
    r width == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2293
    r height == 0 ifTrue:[^ nil].
7c7d11aa956e care for empty rectangle in Image>>fromScreenArea
Claus Gittinger <cg@exept.de>
parents: 2081
diff changeset
  2294
    ^ self fromScreen:r
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2295
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2296
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2297
     Image fromScreenArea
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2298
     Image fromScreenArea inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2299
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2300
2323
bf88727c4dee wait until button is released in #fromUser.
Claus Gittinger <cg@exept.de>
parents: 2311
diff changeset
  2301
    "Modified: / 10.9.1998 / 15:59:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2302
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2303
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2304
fromUser
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2305
    "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
  2306
     Same as fromScreenArea, for ST-80 compatibility.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2307
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2308
	      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
  2309
	      (use #fromScreen:on:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2310
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2311
    ^ self fromScreenArea
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2312
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2313
    "
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
  2314
     Image fromUser
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2315
     Image fromUser inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2316
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2317
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2318
    "Modified: 26.3.1997 / 10:45:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2319
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2320
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2321
fromView:aView
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2322
    "return an image taken from a views contents as currently
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2323
     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
  2324
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2325
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2326
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2327
     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
  2328
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2329
	      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
  2330
	      (use #fromView:grab: with a false grabArg then)."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2331
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2332
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2333
	fromView:aView
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2334
	grab:true
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2335
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  2336
    "
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2337
     Image fromView:(Launcher allInstances first window topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2338
     Image fromView:(BrowserView allInstances first topView)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2339
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2340
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2341
    "get a snapshot from whichever view is active:
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2342
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2343
     |active|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2344
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2345
     active := WindowGroup activeGroup topViews first.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2346
     (Image fromView:active) inspect
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2347
    "
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
  2348
1043
0688425d02c9 Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents: 1041
diff changeset
  2349
    "Modified: 9.9.1996 / 22:41:01 / stefan"
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2350
    "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
  2351
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2352
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2353
fromView:aView grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2354
    "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
  2355
     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
  2356
     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
  2357
     shown while the readout is done.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2358
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2359
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2360
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2361
     the returned Image is NOT correct.
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
  2362
     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
  2363
     WARNING: with doGrab true, this temporarily grabs the display
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2364
	      and it may not work from within a buttonMotion
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2365
	      (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2366
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2367
    ^ self fromView:aView grab:doGrab withDecoration:false
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2368
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2369
    "Created: / 26.3.1997 / 10:34:20 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2370
    "Modified: / 10.10.2001 / 14:13:29 / cg"
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2371
!
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2372
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2373
fromView:aView grab:doGrab withDecoration:withDecoration
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2374
    "return an image taken from a views contents as currently
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2375
     on the screen, optionally with decoration included.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2376
     If the doGrab argument is true, the display
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2377
     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
  2378
     shown while the readout is done.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2379
     The returned image has the same depth and photometric
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2380
     as the Display.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2381
     Notice, that for invisible or partial covered views,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2382
     the returned Image is NOT correct.
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2383
     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
  2384
     WARNING: with doGrab true, this temporarily grabs the display
6370
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2385
              and it may not work from within a buttonMotion
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2386
              (use with a false grabArg then)."
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2387
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2388
    |org ext device cH bW bH|
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2389
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2390
    device := aView graphicsDevice.
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2391
    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
  2392
    ext := aView extent.
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2393
    withDecoration ifTrue:[
6370
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2394
        device isWindowsPlatform ifTrue:[
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2395
            cH := device captionHeight.
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2396
            bW := (device getSystemMetrics: #SM_CXFRAME )
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2397
                  "+ ( device getSystemMetrics: #borderFrameWidth )".
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2398
            bH := (device getSystemMetrics: #SM_CYFRAME )
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2399
                  " + ( device getSystemMetrics: #borderFrameHeight )".
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2400
            org := org - (bW @ (bH + cH)).
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2401
            ext := ext + ((bW + bW) @ (bH+bH+cH)).
9e3a18c732ca class: Image
Claus Gittinger <cg@exept.de>
parents: 6311
diff changeset
  2402
        ].
4540
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2403
    ].
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2404
    ^ self fromScreen:(org extent:ext) on:device grab:doGrab
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2405
abe9a008966e added functionality to grab a window incl. caption-border
ps
parents: 4423
diff changeset
  2406
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2407
     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
  2408
     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
  2409
    "
3518
983e7730a905 use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents: 3507
diff changeset
  2410
4574
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2411
    "Created: / 26-03-1997 / 10:34:20 / cg"
4b65895bbb6b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4565
diff changeset
  2412
    "Modified: / 08-09-2006 / 15:41:41 / cg"
157
claus
parents: 154
diff changeset
  2413
! !
claus
parents: 154
diff changeset
  2414
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2415
!Image methodsFor:'Compatibility-Squeak'!
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2416
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2417
boundingBox
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2418
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2419
    ^ self bounds
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2420
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2421
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2422
colormapIfNeededForDepth:d
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2423
    ^ nil
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2424
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2425
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2426
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2427
6308
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2428
colorsFromArray:anArrayOfRGBTriples
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2429
    "for squeak compatibility with ColorForm:
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2430
     set the colorMap from an array of rgb triples, each value being in 0..1."
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2431
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2432
    |newMap|
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2433
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2434
    newMap := Colormap new:anArrayOfRGBTriples size.
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2435
    anArrayOfRGBTriples doWithIndex:[:rgb :i |
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2436
        newMap at:i putRGBTriple:rgb
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2437
    ].
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2438
    self colorMap:newMap.
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2439
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2440
    "
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2441
     Depth8Image new
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2442
        colorsFromArray:#( (0.5 0.5 0.5) (0.25 0.0 0.0) (0.0 0.25 0.5))
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2443
    "
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2444
!
6e4008b97f64 class: Image
Claus Gittinger <cg@exept.de>
parents: 6305
diff changeset
  2445
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2446
fill:aRectangle fillColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2447
    "fill the rectangular area specified by aRectangle with the given color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2448
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2449
    self fillRectangle:aRectangle withColor:aColor
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2450
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2451
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2452
fillBlack:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2453
    "fill the rectangular area specified by aRectangle with the black color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2454
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2455
    self fillRectangle:aRectangle withColor:Color black
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2456
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2457
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2458
     |img|
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2459
     img := Image extent:100@100 depth:24.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2460
     img photometric:#rgb.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2461
     img data:(ByteArray new:100*100*3).
3475
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2462
     img fillWhite:(0@0 corner:100@100).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2463
     img fillBlack:(10@10 corner:90@90).
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2464
     img inspect.
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2465
    "
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2466
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2467
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2468
fillWhite:aRectangle
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2469
    "fill the rectangular area specified by aRectangle with the white color"
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2470
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2471
    self fillRectangle:aRectangle withColor:Color white
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2472
!
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2473
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2474
isTransparentAt:aPoint
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2475
    mask isNil ifTrue:[ ^ false].
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2476
    ^ (mask pixelAt:aPoint) == 0
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2477
! !
445d02892621 protocol rename
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
  2478
3880
c4c8268a2d9f method category rename
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  2479
!Image methodsFor:'Compatibility-VW'!
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2480
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2481
asCachedImage
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2482
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2483
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2484
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2485
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2486
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2487
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2488
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2489
!
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2490
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2491
asRetainedMedium
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2492
    "return the receiver associated to the current screens device.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2493
     For ST-80 compatibility
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2494
     (ST/X uses Image for both device- and nonDevice-images)"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2495
2832
793500016a2b #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2801
diff changeset
  2496
    ^ self onDevice:Screen current
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2497
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2498
    "Modified: 23.4.1996 / 11:10:32 / cg"
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2499
    "Created: 27.1.1997 / 15:49:08 / cg"
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2500
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2501
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2502
bounds:newBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2503
    ^ self
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2504
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2505
    "Created: 10.2.1997 / 12:44:46 / cg"
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2506
!
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2507
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2508
containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2509
    "in st-80, images are visualComponents ..."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2510
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2511
    ^ self bounds containsPoint:aPoint
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2512
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2513
    "Created: 6.3.1997 / 15:24:12 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2514
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2515
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2516
convertToPalette:aColormap renderedBy:anImageRenderer
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2517
    "this does not really mimicri the corresponding ST-80 functionality"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2518
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2519
    |monoBits convertedImage|
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2520
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2521
    aColormap size == 2 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2522
	anImageRenderer class == OrderedDither ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2523
	    monoBits := self orderedDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2524
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2525
	    monoBits := self floydSteinbergDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2526
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2527
	(((aColormap at:1) = Color black)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2528
	and:[(aColormap at:2) = Color white]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2529
	    "/ ok
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2530
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2531
	    (((aColormap at:1) = Color white)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2532
	    and:[(aColormap at:2) = Color black]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2533
		monoBits invert
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2534
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2535
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2536
	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
  2537
	convertedImage palette:aColormap.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2538
	^ convertedImage
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2539
    ].
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2540
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2541
    self error:'unimplemented operation'.
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2542
    ^ self
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2543
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2544
    "Modified: 1.3.1997 / 17:25:50 / cg"
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2545
!
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
  2546
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2547
paintBasis
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2548
    "huh - whats that;
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2549
     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
  2550
     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
  2551
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2552
    ^ ColorValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2553
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2554
    "Created: 6.3.1997 / 15:24:19 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2555
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  2556
1325
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2557
preferredBounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2558
    ^ self bounds
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2559
3c09b139de30 more st80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1309
diff changeset
  2560
    "Created: 10.2.1997 / 12:42:36 / cg"
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2561
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2562
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2563
tile:bounds from:origin in:tile rule:rule
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2564
    |orgX orgY tW tH|
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2565
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2566
    origin ~= (0@0) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2567
	self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2568
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2569
    bounds ~= self bounds ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2570
	self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2571
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2572
    rule ~= #over ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2573
	self shouldImplement.
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2574
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2575
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2576
    orgX := origin x.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2577
    orgY := origin y.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2578
    tW := tile width.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2579
    tH := tile height.
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2580
    (bounds top) to:(bounds bottom) by:tH do:[:dstY |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2581
	(bounds left) to:(bounds right) by:(tile width) do:[:dstX |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2582
	    self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2583
		copyFrom:tile
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2584
		x:orgX y:orgY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2585
		toX:dstX y:dstY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2586
		width:tW height:tH.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  2587
	].
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2588
    ].
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2589
!
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2590
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2591
valueAtPoint:aPoint put:aColorValue
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2592
    aColorValue isInteger ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2593
	self colorAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2594
    ] ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2595
	self pixelAtX:aPoint x y:aPoint y put:aColorValue
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  2596
    ]
1279
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2597
! !
09eef854916c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1276
diff changeset
  2598
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2599
!Image methodsFor:'accessing'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2600
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2601
bitsARGB32
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2602
    | bitsARGB32 |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2603
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2604
    bitsARGB32 := ByteArray new: width * height * 4.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2605
    self bitsARGB32Into: bitsARGB32.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2606
    ^ bitsARGB32
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2607
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2608
    "Created: / 01-09-2015 / 18:02:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2609
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2610
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2611
bitsARGB32Into: buffer
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2612
    self bitsARGB32Into: buffer startingAt: 1
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2613
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2614
    "Created: / 01-09-2015 / 17:18:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2615
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2616
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2617
bitsARGB32Into: buffer startingAt: first
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2618
    self bitsARGB32Into: buffer startingAt: first stride: width
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2619
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2620
    "Created: / 01-09-2015 / 17:18:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2621
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2622
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2623
bitsARGB32Into: buffer startingAt: first stride: stride
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2624
    "Store each pixel is a 32-bit quantity, with alpha in the upper 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2625
     8 bits, then red, then green, then blue. The 32-bit quantities are 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2626
     stored native-endian. Pre-multiplied alpha is used. (That is, 50% 
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2627
     transparent red is 0x80800000, not 0x80ff0000.)"
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2628
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2629
    mask isNil ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2630
        0 to: height - 1 do:[:y |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2631
            | base |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2632
            base := (first - 1) + (y * stride).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2633
            0 to: width - 1 do:[:x |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2634
                | pixel color offset |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2635
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2636
                offset := base + (x * 4).    
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2637
                pixel := self pixelAtX: x y: y.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2638
                color := self colorFromValue: pixel.
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2639
                buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: color redByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2640
                buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: color greenByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2641
                buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: color blueByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2642
                buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 16rFF.   
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2643
            ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2644
        ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2645
    ] ifFalse:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2646
    mask depth == 1 ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2647
        0 to: height - 1 do:[:y |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2648
            | base |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2649
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2650
            base := (first - 1) + (y * stride).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2651
            0 to: width - 1 do:[:x |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2652
                | pixel color offset |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2653
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2654
                offset := base + (x * 4).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2655
                (mask pixelAtX: x y:y) ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2656
                    pixel := self pixelAtX: x y: y.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2657
                    color := self colorFromValue: pixel.
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2658
                    buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: color redByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2659
                    buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: color greenByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2660
                    buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: color blueByte.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2661
                    buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 16rFF.
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2662
                ] ifFalse:[ 
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2663
                    buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: 0.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2664
                    buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: 0.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2665
                    buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: 0.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2666
                    buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: 0.
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2667
                ].
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2668
            ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2669
        ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2670
    ] ifFalse:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2671
    mask depth == 8 ifTrue:[ 
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2672
        0 to: height - 1 do:[:y |  
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2673
            | base |
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2674
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2675
            base := (first - 1) + (y * stride).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2676
            0 to: width - 1 do:[:x |  
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2677
                | pixel color offset alpha |
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2678
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2679
                offset := base + (x * 4).
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2680
                pixel := self pixelAtX: x y: y.
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2681
                color := self colorFromValue: pixel.
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2682
                alpha := mask pixelAtX: x y:y.
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2683
                buffer at: (offset + ARGB_R_OFFSET_MACHINE) put: (color redByte * alpha) // 16rFF.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2684
                buffer at: (offset + ARGB_G_OFFSET_MACHINE) put: (color greenByte * alpha) // 16rFF.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2685
                buffer at: (offset + ARGB_B_OFFSET_MACHINE) put: (color blueByte * alpha) // 16rFF.  
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2686
                buffer at: (offset + ARGB_A_OFFSET_MACHINE) put: alpha
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2687
            ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2688
        ]
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2689
    ]]].
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2690
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2691
    "Created: / 01-09-2015 / 17:16:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7170
e5374bb05083 Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 7157
diff changeset
  2692
    "Modified: / 28-02-2016 / 14:38:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2693
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
  2694
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2695
bitsPerSample
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2696
    "return the number of bits per sample.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2697
     The return value is an array of bits-per-plane."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2698
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2699
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2700
    ^ Array with:self depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2701
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2702
    "Modified: 10.6.1996 / 18:04:21 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2703
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2704
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2705
colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2706
    "return the colormap"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2707
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2708
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2709
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2710
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2711
colorMap:aColorMap
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2712
    "set the colorMap; this also sets 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
  2713
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2714
    |newSize "{ Class: SmallInteger }"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2715
     oldSize "{ Class: SmallInteger }"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2716
     sameColors|
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2717
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2718
    (aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  2719
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2720
    sameColors := false.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2721
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2722
    photometric == #palette ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2723
        "/ any change at all ?
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2724
        (newSize := aColorMap size) >= (oldSize := colorMap size) ifTrue:[
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2725
            sameColors := true.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2726
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2727
            1 to:oldSize do:[:idx |
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2728
                (aColorMap at:idx) = (colorMap at:idx) ifFalse:[
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2729
                    sameColors := false.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2730
                ]
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2731
            ].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2732
        ].
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2733
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2734
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2735
    self setColorMap:aColorMap.
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2736
    sameColors ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2737
        ^ self
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2738
    ].
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2739
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2740
    colorMap notNil ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2741
        photometric := #palette.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2742
    ] ifFalse:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2743
        (photometric == #palette) ifTrue:[
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2744
            photometric := #blackIs0
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2745
        ]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2746
    ].
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2747
    deviceForm notNil ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  2748
        self release
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2749
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2750
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2751
    "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
  2752
    "Modified: / 22.8.1998 / 12:29:58 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2753
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2754
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2755
colorMapFromArray: anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2756
    "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
  2757
     The (byte-)Array argument should be of the form:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2758
	#( 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
  2759
     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
  2760
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2761
    self colorMap:(MappedPalette rgbBytesVector:anArray)
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2762
!
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2763
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  2764
colorMapFromRGBValueArray:anArray
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2765
    "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
  2766
     The (integer-)Array argument should be of the form:
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2767
	#( rgb0 rgb1  ... rgbN)
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2768
     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
  2769
3876
f4dc6267a30a getting rid of colorMap
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2770
    self colorMap:(MappedPalette rgbValueVector:anArray)
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2771
!
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
  2772
757
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2773
container:aVisualContainer
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2774
    "ignored here - added to allow images to be used like
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2775
     VisualComponents (later, Image should inherit from it)"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2776
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2777
    "Created: 28.5.1996 / 23:43:49 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2778
    "Modified: 29.5.1996 / 10:22:23 / cg"
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2779
!
6c7dc7e05e93 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 748
diff changeset
  2780
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2781
depth
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2782
    "return the depth of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2783
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2784
    ^ self bitsPerPixel
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2785
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2786
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2787
device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2788
    "return the device, the receiver is associated with.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2789
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2790
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2791
    ^ device
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2792
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2793
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2794
extent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2795
    "return the images extent"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2796
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2797
    ^ width@height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2798
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2799
1950
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2800
fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2801
    "return the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2802
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2803
    ^ fileName
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2804
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2805
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2806
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2807
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2808
fileName:something
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2809
    "set the value of the instance variable 'fileName' (automatically generated)"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2810
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2811
    fileName := something.
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2812
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2813
    "Created: / 3.11.1997 / 14:54:46 / cg"
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2814
!
23f49293deb8 access to filename
Claus Gittinger <cg@exept.de>
parents: 1935
diff changeset
  2815
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2816
fullColorId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2817
    "return the id of the full color image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2818
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2819
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2820
    fullColorDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2821
    ^ fullColorDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2822
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2823
728
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2824
graphicsDevice
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2825
    "same as #device - for ST-80 compatibility"
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2826
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2827
    ^ device
04d0a262b82e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  2828
!
744
db883c9b74b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 728
diff changeset
  2829
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2830
height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2831
    "return the height of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2832
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2833
    ^ height
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2834
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2835
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2836
id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2837
    "return the id of the image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2838
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2839
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2840
    deviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2841
    ^ deviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2842
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2843
2081
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2844
imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2845
    "return the frameSequence of which this image is a part of;
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2846
     nil if it is not part of a sequence."
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2847
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2848
    ^ imageSequence
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2849
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2850
    "Created: / 1.4.1998 / 14:43:00 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2851
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2852
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2853
imageSequence:aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2854
    "private entry for imageReaders - set the frameSequence of which
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2855
     this image is a part of"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2856
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2857
    imageSequence := aCollection
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2858
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2859
    "Created: / 1.4.1998 / 14:42:36 / cg"
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2860
!
24f4f3004fe3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2068
diff changeset
  2861
896
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2862
mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2863
    ^ mask
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2864
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2865
    "Created: 21.6.1996 / 12:57:44 / cg"
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2866
!
26cea84f134d mask access
Claus Gittinger <cg@exept.de>
parents: 894
diff changeset
  2867
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2868
mask:anotherImage
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2869
    "set the images mask - currently, this may be nil or a Depth1Image.
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2870
     (it is planned to support alpha information in a Depth8 maskImage in
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2871
      the near future).
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2872
     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
  2873
		       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
  2874
		       0-bit mask pixels lead to transparent pixels.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2875
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2876
     For depth8 masks: (future):
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2877
		       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
  2878
		       which specifies the transparency of that pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2879
		       0 means completely transparent, 255 means completely
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  2880
		       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
  2881
		       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
  2882
		       alpha value of 255."
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2883
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2884
    mask := anotherImage.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2885
    maskedPixelsAre0 := false.
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2886
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2887
    "Created: 27.6.1996 / 17:45:22 / cg"
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2888
    "Modified: 12.4.1997 / 12:04:39 / cg"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2889
!
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2890
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2891
maskedPixelsAre0
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2892
    "return true if masked pixels have been cleared to zero"
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2893
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2894
    ^ maskedPixelsAre0 == true
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2895
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  2896
    "Modified: / 22.8.1998 / 11:27:22 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2897
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2898
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2899
maskedPixelsAre0:aBoolean
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2900
    "set/clear the flag which states if masked pixels
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2901
     have been set to zero. Knowing this to be true allows
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2902
     faster drawing of the image later; (however, not setting
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2903
     it will still produce correct output).
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2904
     This flag is typically set by image readers."
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2905
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2906
    maskedPixelsAre0 := aBoolean
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2907
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2908
    "Modified: 12.4.1997 / 12:08:42 / cg"
1587
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2909
!
4a0b4c864ff0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1586
diff changeset
  2910
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2911
monochromeId
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2912
    "return the id of the monochrome image on the device.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2913
     Return nil, if the image is unassigned."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2914
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2915
    monoDeviceForm isNil ifTrue:[^ nil].
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2916
    ^ monoDeviceForm id
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2917
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2918
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2919
palette
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2920
    "return the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2921
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2922
    ^ colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2923
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2924
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2925
palette:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2926
    "set the colormap; ST-80 compatibility"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2927
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  2928
    self colorMap:aColormap
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2929
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2930
    "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
  2931
    "Modified: 8.6.1996 / 09:54:02 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2932
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2933
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2934
photometric
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2935
    "return the photometric, a symbol such as #palette, #rgb etc.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2936
     This may be a somewhat old leftover from times, when tiff was the first image file type to be read.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2937
     Much better would be to always have some (possibly fake and virtual) colormap around, and ask that one.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2938
     However, in the meantime, many other classes depend on that, so that it should be kept as an API 
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2939
     - even when the internal representation will be replaced by something better in the future."
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  2940
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2941
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2942
    ^ photometric
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2943
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2944
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2945
samplesPerPixel
6840
3dee5e952e94 class: Image
Stefan Vogel <sv@exept.de>
parents: 6831
diff changeset
  2946
    "return the number of samples per pixel in the image."
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2947
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2948
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2949
    ^ 1
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2950
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2951
    "Modified: 10.6.1996 / 18:03:30 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2952
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2953
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2954
setColorMap:aColorMap
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2955
    (aColorMap isNil or:[aColorMap isKindOf:Colormap]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2956
	colorMap := MappedPalette withColors:aColorMap
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2957
    ] ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  2958
	colorMap := aColorMap
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2959
    ]
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2960
!
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  2961
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2962
width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2963
    "return the width of the image"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2964
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2965
    ^ width
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2966
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2967
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  2968
!Image methodsFor:'accessing-pixels'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  2969
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2970
at:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2971
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2972
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2973
     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
  2974
     Use #colorAt: - for future compatibility.
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
     retrieve the pixel at aPoint; return a color.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2977
     Pixels start at 0@0 for upper left pixel, end at
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2978
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  2979
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2980
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  2981
     (it is meant to access individual pixels - for example, in a bitmap editor)"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2982
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2983
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  2984
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2985
    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
  2986
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2987
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  2988
    "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
  2989
    "Modified: / 9.1.1998 / 20:33:52 / stefan"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  2990
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  2991
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2992
at:aPoint put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  2993
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2994
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2995
     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
  2996
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2997
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  2998
     set the pixel at aPoint to aColor.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  2999
     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
  3000
     (width-1)@(height-1) for lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3001
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3002
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3003
     (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
  3004
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3005
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3006
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3007
    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
  3008
    ^ self colorAtX:aPoint x y:aPoint y put:aColor
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3009
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
  3010
    "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
  3011
    "Modified: / 9.1.1998 / 20:34:15 / stefan"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3012
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3013
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3014
atImageAndMask:aPoint put:aColorOrPixelOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3015
    "set the pixel at x/y to aColor.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3016
     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
  3017
     otherwise to 1. Nil is treated like noColor.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3018
     (used by the bitmap editor)"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3019
2523
4c197af8cc50 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2502
diff changeset
  3020
    |maskVal|
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3021
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3022
    (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
  3023
	maskVal := 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3024
	aColorOrPixelOrNil isInteger ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3025
	    self pixelAt:aPoint put:aColorOrPixelOrNil.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3026
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3027
	    self colorAt:aPoint put:aColorOrPixelOrNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3028
	]
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3029
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3030
	maskVal := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3031
	self pixelAt:aPoint put:0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3032
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3033
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3034
	mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3035
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3036
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3037
    "Modified: / 30.9.1998 / 22:42:44 / cg"
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3038
!
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3039
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3040
atImageAndMask:aPoint putValue:aPixelValueOrNil
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3041
    "set the pixel at x/y to aColor.
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3042
     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
  3043
     otherwise to 1. (used by the bitmap editor)"
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3044
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3045
    |pixVal maskVal|
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3046
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3047
    aPixelValueOrNil notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3048
	pixVal := aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3049
	maskVal := 1.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3050
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3051
	pixVal := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3052
	maskVal := 0.
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3053
    ].
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3054
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3055
	mask pixelAt:aPoint put:maskVal
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3056
    ].
2502
ad364776706b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
  3057
    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
  3058
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3059
    "Modified: / 30.9.1998 / 22:42:44 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3060
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  3061
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3062
atPoint:aPoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3063
    "ST-80 compatibility: return the pixelValue at:aPoint."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3064
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3065
    ^ self pixelAtX:aPoint x y:aPoint y
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
    "Modified: 24.4.1997 / 16:18:44 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3068
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3069
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3070
atPoint:aPoint put:aPixelValue
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3071
    "ST-80 compatibility: set the pixelValue at:aPoint."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3072
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3073
    ^ self pixelAtX:aPoint x y:aPoint y put:aPixelValue
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
    "Modified: 24.4.1997 / 17:17:59 / cg"
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3076
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3077
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3078
atX:x y:y
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3079
    "WARNING: for now, this returns a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3080
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3081
     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
  3082
     Use #colorAt: - for future compatibility.
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
     Retrieve a pixel at x/y; return a color.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3085
     Pixels start at 0@0 for upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3086
     (width-1)@(height-1) for lower right pixel.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3087
     You should not use this method for image-processing, its
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3088
     very slow ...
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3089
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3090
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3091
    '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
  3092
    ^ self colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3093
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3094
    "Modified: 21.6.1997 / 13:10:32 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3095
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3096
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3097
atX:x y:y put:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3098
    "WARNING: for now, this expects a pixels color
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3099
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3100
     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
  3101
     Use #colorAt:put: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3102
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3103
     set the pixel at x/y to aColor.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3104
     Pixels start at 0@0 for the upper left pixel, end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3105
     (width-1)@(height-1) for the lower right pixel.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3106
     This method checks if the color can be stored in the image.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3107
     (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
  3108
     You should not use this method for image-processing, it is very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3109
     (it is meant to access individual pixels - for example, in a bitmap editor)"
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3110
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  3111
    aColor isInteger ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3112
	'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
  3113
	^ self pixelAtX:x y:y put:aColor
4380
46328c4ff748 ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 4317
diff changeset
  3114
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3115
    ^ self colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3116
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3117
    "Modified: 21.6.1997 / 13:10:44 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3118
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3119
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3120
atX:x y:y putValue:aPixelValue
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3121
    "set the pixel at x/y to aPixelValue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3122
     The interpretation of the pixelValue depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3123
     and the colormap. (see also: Image>>atX:y:put:)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3124
     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
  3125
     (width-1) @ (height-1) for the lower right pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3126
     You should not use this method for image-processing, its
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3127
     very slow ...
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3128
     (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
  3129
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3130
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3131
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3132
    self obsoleteMethodWarning:'use #pixelAtX:y:put:'.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3133
    ^ self pixelAtX:x y:y put:aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3134
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3135
    "Modified: 24.4.1997 / 17:15:45 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3136
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3137
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3138
bits
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3139
    "return the raw image data (pixel data); 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3140
     depending on the photometric, this has to be interpreted as monochrome, 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3141
     greyscale, palette or rgb data.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3142
     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
  3143
     will store 2 pixels per byte, whereas a 2-bitPerPixel image will store
be0fa075e4c4 comment
Claus Gittinger <cg@exept.de>
parents: 4414
diff changeset
  3144
     4 pixels per byte."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3145
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3146
    bytes isNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3147
        pixelFunction notNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3148
            self createPixelStore.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3149
            0 to:height-1 do:[:y |
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3150
                0 to:width-1 do:[:x |
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3151
                    self pixelAtX:x y:y put:(pixelFunction value:x value:y)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3152
                ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3153
            ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3154
        ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3155
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3156
    ^ bytes
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3157
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3158
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3159
colorAt:aPoint
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3160
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3161
     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
  3162
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3163
     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
  3164
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3165
     (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
  3166
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3167
    ^ self colorAtX:(aPoint x) y:(aPoint y)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3168
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3169
    "Created: 24.4.1997 / 17:02:31 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3170
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3171
1962
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3172
colorAt: aPoint put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3173
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3174
    self colorAtX: aPoint x y: aPoint y put:aColor
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3175
!
8c7377d243f6 save mask in storeOn.
tz
parents: 1950
diff changeset
  3176
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3177
colorAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3178
    "retrieve a pixel at x/y; return a color.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3179
     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
  3180
     (width-1)@(height-1) for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3181
     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
  3182
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3183
     (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
  3184
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3185
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3186
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3187
    pixel := self pixelAtX:x y:y.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3188
    ^ self colorFromValue:pixel
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3189
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3190
    "Modified: 24.4.1997 / 16:18:53 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3191
    "Created: 24.4.1997 / 17:00:52 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3192
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3193
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3194
colorAtX:x y:y put:aColor
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3195
    "set the pixel at x/y to aColor.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3196
     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
  3197
     (width-1)@(height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3198
     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
  3199
     (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
  3200
     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
  3201
     (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
  3202
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3203
    |pixel|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3204
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3205
    pixel := self valueFromColor:aColor.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3206
    pixel isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3207
	^ UnrepresentableColorSignal raiseErrorString:'cannot store color - not in colormap'.
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3208
    ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3209
    self pixelAtX:x y:y put:pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3210
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3211
    "Modified: 24.4.1997 / 17:36:20 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3212
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3213
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3214
data
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3215
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3216
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3217
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  3218
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3219
    self obsoleteMethodWarning:'use #bits'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3220
    ^ self bits
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3221
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3222
    "Modified: 24.4.1997 / 17:37:57 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3223
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3224
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3225
data:aByteArray
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3226
    "for backward compatibility - will vanish"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3227
4175
a9e65365e590 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 4173
diff changeset
  3228
    <resource:#obsolete>
3966
950a2db201c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3964
diff changeset
  3229
    self obsoleteMethodWarning:'use #bits:'.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3230
    self bits:aByteArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3231
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3232
    "Modified: 24.4.1997 / 17:38:18 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3233
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3234
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3235
maskAt:aPoint
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3236
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3237
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3238
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3239
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3240
    ^ self maskAtX:aPoint x y:aPoint y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3241
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3242
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3243
maskAt:aPoint put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3244
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3245
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3246
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3247
    ^ self maskAtX:aPoint x y:aPoint y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3248
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3249
2182
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3250
maskAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3251
    "retrieve the maskValue at aPoint - an integer number which is
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3252
     0 for masked pixels (invisible), 1 for unmasked (visible).
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3253
     For images without mask, 1 is returned for all pixels."
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3254
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3255
    mask isNil ifTrue:[^ 1].
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3256
    ^ mask pixelAtX:x y:y
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3257
!
9ca11fd1d0fb addd maskAt: accessors;
Claus Gittinger <cg@exept.de>
parents: 2113
diff changeset
  3258
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3259
maskAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3260
    "set the maskValue at aPoint - an integer number which is
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3261
     0 for masked pixels (invisible), 1 for unmasked (visible)."
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3262
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3263
    mask isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3264
	maskValue == 1 ifTrue:[^ self].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  3265
	self error:'image has no mask'.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3266
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3267
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3268
    ^ mask pixelAtX:x y:y put:maskValue
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3269
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
  3270
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3271
pixelAt:aPoint
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3272
    "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
  3273
     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
  3274
     (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
  3275
     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
  3276
     very slow ...
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3277
     (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
  3278
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3279
    ^ 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
  3280
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3281
    "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
  3282
!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3283
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3284
pixelAt:aPoint put:aPixelValue
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3285
    "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
  3286
     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
  3287
     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
  3288
     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
  3289
     (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
  3290
     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
  3291
     very slow ...
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3292
     (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
  3293
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3294
    ^ 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
  3295
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3296
    "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
  3297
!
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  3298
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3299
pixelAtX:x y:y
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3300
    "retrieve the pixelValue at aPoint; return an integer number.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3301
     Pixels start at 0/0 for upper left pixel, and end at
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3302
     width-1@height-1 for lower right pixel.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3303
     The returned numbers interpretation depends on the photometric
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3304
     and the colormap. (see also Image>>at: and Image>>atX:y:)
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3305
     You should not use this method for image-processing of
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3306
     big images, its very slow ...
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3307
     (it is meant to access individual pixels - for example, in a bitmap editor)"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3308
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3309
    pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  3310
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3311
    ^ self subclassResponsibility
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3312
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3313
    "Created: 24.4.1997 / 16:06:56 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3314
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3315
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3316
pixelAtX:x y:y put:aPixelValue
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3317
    "set the pixel at x/y to aPixelValue.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3318
     The interpretation of the pixelValue depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3319
     and the colormap. (see also: Image>>atX:y:put:)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3320
     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
  3321
     (width-1) @ (height-1) for the lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3322
     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
  3323
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3324
     (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
  3325
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3326
    ^ self subclassResponsibility
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3327
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3328
    "Created: 24.4.1997 / 17:05:11 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3329
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3330
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3331
rgbValueAt:aPoint
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3332
    "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
  3333
     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
  3334
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3335
    ^ self rgbValueAtX:(aPoint x) y:(aPoint y)
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3336
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3337
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3338
rgbValueAtX:x y:y
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3339
    "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
  3340
     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
  3341
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3342
    |pixel|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3343
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3344
    pixel := self pixelAtX:x y:y.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3345
    ^ self rgbFromValue:pixel
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3346
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
  3347
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3348
rgbValueAtX:x y:y put:newRGBValue
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3349
    |value|
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3350
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3351
    value := self valueFromRGB:newRGBValue.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3352
    self pixelAtX:x y:y put:value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3353
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3354
    "Created: / 15-01-2008 / 15:56:10 / cg"
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3355
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
  3356
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3357
rowAt:y
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3358
    "retrieve an array filled with pixel values from
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3359
     a single row.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3360
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3361
     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
  3362
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3363
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3364
    |pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3365
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3366
    pixelArray := self pixelArraySpecies new:width.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3367
    self rowAt:y into:pixelArray startingAt:1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3368
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3369
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3370
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3371
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3372
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  3373
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3374
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3375
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3376
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3377
     |i|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3378
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3379
     i := Image fromFile:'libtool/bitmaps/SBrowser.xbm'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3380
     (i rowAt:0) inspect
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3381
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3382
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3383
    "Modified: 24.4.1997 / 15:51:24 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3384
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3385
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3386
rowAt:y into:aPixelBuffer
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3387
    "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
  3388
     Notice: row coordinate starts at 0."
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3389
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3390
    ^ self rowAt:y into:aPixelBuffer startingAt:1
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3391
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3392
    "Created: 24.4.1997 / 15:44:46 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3393
    "Modified: 24.4.1997 / 15:51:35 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3394
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3395
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3396
rowAt:y into:aPixelBuffer startingAt:startIndex
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3397
    "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
  3398
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3399
     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
  3400
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3401
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3402
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3403
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3404
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3405
    0 to:w do:[:col |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3406
	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
  3407
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3408
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3409
    "Created: 24.4.1997 / 15:05:21 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3410
    "Modified: 24.4.1997 / 16:52:43 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3411
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3412
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3413
rowAt:y putAll:pixelArray
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3414
    "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
  3415
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3416
     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
  3417
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3418
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3419
    ^ self rowAt:y putAll:pixelArray startingAt:1
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3420
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3421
    "Modified: 24.4.1997 / 15:51:58 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3422
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3423
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3424
rowAt:y putAll:pixelArray startingAt:startIndex
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3425
    "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
  3426
     return the pixelArray.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3427
     Notice: row coordinate starts at 0.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3428
     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
  3429
     concrete image subclasses should redefine this for more performance."
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3430
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3431
    |w "{ Class: SmallInteger }"|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3432
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3433
    w := width-1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3434
    0 to:w do:[:col |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3435
	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
  3436
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3437
    ^ pixelArray
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3438
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3439
    "Modified: 24.4.1997 / 17:05:57 / cg"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3440
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3441
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3442
valueAt:aPoint
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3443
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3444
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3445
     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
  3446
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3447
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3448
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3449
     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
  3450
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3451
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3452
     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
  3453
     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
  3454
     very slow ...
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3455
     (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
  3456
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3457
    '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
  3458
    ^ self pixelAtX:aPoint x y:aPoint y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3459
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3460
    "Modified: 21.6.1997 / 13:11:19 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3461
!
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3462
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3463
valueAtX:x y:y
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3464
    "WARNING: for now, this returns a pixels value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3465
     (backward compatibility with ST/X)
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3466
     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
  3467
     Use #pixelAt: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3468
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3469
     Retrieve the pixelValue at aPoint; return an integer number.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3470
     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
  3471
     width-1@height-1 for lower right pixel.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3472
     The returned numbers interpretation depends on the photometric
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3473
     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
  3474
     You should not use this method for image-processing of
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3475
     big images, its very slow ...
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3476
     (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
  3477
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3478
    '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
  3479
    ^ self pixelAtX:x y:y
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  3480
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
  3481
    "Modified: 21.6.1997 / 13:11:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3482
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3483
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3259
diff changeset
  3484
!Image methodsFor:'accessing-private'!
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3485
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3486
bits:aByteArray
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3487
    "set the raw data.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3488
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3489
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3490
     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
  3491
     existing image may confuse later pixel interpretation
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3492
     (it does not care for colormaps and/or cached device image flushing)."
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3493
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3494
    |expectedSize d|
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3495
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3496
    bytes := aByteArray.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3497
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3498
    "/ sanity check:
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3499
    "/ there seem to be images in some image-resource methods,
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3500
    "/ which were written with an invalid packed pixel string.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3501
    "/ leave this in for a while and watch out for the halt below.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3502
    "/ If you encounter this halt,
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3503
    "/ please edit the image in the image editor and save it back.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3504
    
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3505
    (width notNil and:[height notNil and:[(d := self depth) notNil]]) ifTrue:[
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3506
        (d <= 8) ifTrue:[
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
  3507
            expectedSize := (self bytesPerRow * height).
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3508
            bytes size < expectedSize ifTrue:[
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3509
                Smalltalk isSmalltalkDevelopmentSystem ifTrue:[
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3510
                    self halt:'invalid bytearray size'.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3511
                ].
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3512
                bytes := (ByteArray new:expectedSize) replaceFrom:1 with:bytes; yourself.
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3513
            ].
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3514
        ].
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
  3515
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3516
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3517
    "Modified: 23.4.1996 / 11:08:28 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3518
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3519
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3520
bits:aByteArrayArg colorMap:clrMapArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3521
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3522
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3523
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3524
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3525
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3526
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3527
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3528
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3529
    self colorMap:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3530
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3531
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3532
bits:aByteArrayArg colorMap:clrMapArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3533
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3534
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3535
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3536
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3537
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3538
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3539
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3540
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3541
    self colorMap:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3542
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3543
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3544
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3545
bits:aByteArrayArg colorMapFromArray:clrMapArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3546
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3547
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3548
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3549
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3550
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3551
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3552
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3553
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3554
    self colorMapFromArray:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3555
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3556
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3557
bits:aByteArrayArg colorMapFromArray:clrMapArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3558
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3559
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3560
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3561
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3562
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3563
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3564
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3565
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3566
    self colorMapFromArray:clrMapArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3567
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3568
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3569
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3570
bits:aByteArrayArg mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3571
    "set the raw data.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3572
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3573
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3574
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3575
     existing image may confuse later pixel interpretation
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3576
     (it does not care for colormaps and/or cached device image flushing)."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3577
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3578
    self bits:aByteArrayArg.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3579
    self mask:maskArg
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3580
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3581
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
  3582
bitsPerSample:aCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3583
    "set the number of bits per sample.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3584
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3585
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3586
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3587
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3588
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3589
    "/ the following is a trick to get shared Immutable instances, at least for the
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3590
    "/ most common cases. Prevents writers to do what is described above.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3591
    "/ Just an experiment...
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3592
    aCollection = #( 8 8 8 ) ifTrue:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3593
        bitsPerSample := #( 8 8 8 )
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3594
    ] ifFalse:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3595
        aCollection = #( 8 ) ifTrue:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3596
            bitsPerSample := #( 8 )
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3597
        ] ifFalse:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3598
            bitsPerSample := aCollection
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3599
        ].
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3600
    ].
6899
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  3601
    samplesPerPixel isNil ifTrue:[
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  3602
        samplesPerPixel := bitsPerSample size.
4530c3bfcef8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6896
diff changeset
  3603
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3604
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3605
    "Modified: 23.4.1996 / 11:08:31 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3606
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3607
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3608
depth:d
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3609
    "set the depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3610
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3611
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3612
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3613
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3614
1362
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  3615
    depth := self depth.
454d644f6ff7 set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
  3616
    bitsPerPixel := d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3617
    d == 24 ifTrue:[
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3618
        samplesPerPixel := 3.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3619
        bitsPerSample := #(8 8 8)
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3620
    ] ifFalse:[
6862
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3621
        d == 32 ifTrue:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3622
            samplesPerPixel := 4.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3623
            bitsPerSample := #(8 8 8 8)
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3624
        ] ifFalse:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3625
            d == 16 ifTrue:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3626
                samplesPerPixel := 3.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3627
                bitsPerSample := #(5 5 5)
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3628
            ] ifFalse:[
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3629
                samplesPerPixel := 1.
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3630
                bitsPerSample := ByteArray with:d
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3631
            ]
e9bd4dc536a4 class: Image
Claus Gittinger <cg@exept.de>
parents: 6840
diff changeset
  3632
        ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3633
    ]
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3634
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  3635
    "Modified: / 27-05-2007 / 16:59:47 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3636
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3637
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3638
extent:anExtent
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3639
    "set the images extent.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3640
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3641
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3642
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3643
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3644
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3645
    width := anExtent x.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3646
    height := anExtent y
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3647
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3648
    "Modified: 23.4.1996 / 11:08:38 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3649
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3650
5326
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3651
hasAlphaChannel
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3652
    ^ false
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3653
!
0443d8649cac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5319
diff changeset
  3654
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3655
height:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3656
    "set the height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3657
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3658
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3659
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3660
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3661
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3662
    height := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3663
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3664
    "Modified: 23.4.1996 / 11:08:40 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3665
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3666
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3667
photometric:aSymbol
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3668
    "set the photometric interpretation of the pixel values.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3669
     The argument, aSymbol is one of:
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3670
	#blackIs0, #whiteIs0, #palette, #rgb
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3671
     See TIFF documentation, from which the photometric concept is borrowed.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3672
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3673
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3674
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3675
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3676
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3677
    |b|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3678
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3679
    photometric := aSymbol.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3680
    bitsPerSample isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3681
	photometric == #rgb ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3682
	    b := self class imageDepth // 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3683
	    bitsPerSample := ByteArray with:b with:b with:b
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3684
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3685
	    bitsPerSample := ByteArray with:(self class imageDepth)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3686
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3687
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3688
    samplesPerPixel isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3689
	photometric == #rgb ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3690
	    samplesPerPixel := 3
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3691
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3692
	    samplesPerPixel := 1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3693
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3694
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  3695
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3696
    "Modified: 10.6.1996 / 18:21:29 / cg"
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3697
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3698
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3699
samplesPerPixel:aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3700
    "set the array of samples per pixel.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3701
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3702
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3703
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3704
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3705
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3706
    samplesPerPixel := aNumber
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3707
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3708
    "Modified: 23.4.1996 / 11:08:45 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3709
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3710
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3711
width:aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3712
    "set the width of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3713
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3714
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3715
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3716
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3717
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3718
    width := aNumber
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3719
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3720
    "Modified: 23.4.1996 / 11:08:48 / cg"
100
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3721
!
1b0b86c77397 co !!:*
claus
parents: 89
diff changeset
  3722
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3723
width:w height:h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3724
    "set the width and height of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3725
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3726
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3727
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3728
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3729
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3730
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3731
    height := h
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3732
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3733
    "Modified: 23.4.1996 / 11:08:53 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
  3734
!
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  3735
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3736
width:w height:h depth:d
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3737
    "set the width, height and depth of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3738
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3739
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3740
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3741
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3742
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3743
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3744
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3745
    self depth:d.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3746
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3747
    "Modified: 23.4.1996 / 11:08:56 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3748
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  3749
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3750
width:w height:h depth:d fromArray:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3751
    "set the width, height, depth and pixels of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3752
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3753
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3754
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3755
     existing image may confuse later pixel interpretation."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3756
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3757
    width := w.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3758
    height := h.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  3759
    self depth:d.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3760
    self bits:bits
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3761
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3762
    "Modified: 23.4.1996 / 11:08:59 / cg"
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3763
!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3764
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3765
width:w height:h depth:d palette:aColormap
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3766
    "set the width, height and depth of the image.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3767
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3768
     This interface is only to be used when initializing
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3769
     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
  3770
     existing image may confuse later pixel interpretation."
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3771
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3772
    width := w.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3773
    height := h.
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3774
    self depth:d.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3775
    self setColorMap:aColormap.
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3776
    aColormap notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3777
	photometric := #palette
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3778
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  3779
	photometric := #blackIs0
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  3780
    ].
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3781
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3782
    "Modified: 23.4.1996 / 11:08:56 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3783
    "Created: 6.3.1997 / 15:23:57 / cg"
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3784
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
  3785
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3786
width:w height:h photometric:p
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3787
    "set the width, height and photometric of the image.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3788
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3789
     This interface is only to be used when initializing
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3790
     instances or by image readers. Calling for a change of an
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3791
     existing image may confuse later pixel interpretation."
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3792
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3793
    width := w.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3794
    height := h.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3795
    self photometric:p.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3796
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3797
    "Modified: 23.4.1996 / 11:08:56 / cg"
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3798
!
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
  3799
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3800
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
  3801
    "set all relevant internal state of the image.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3802
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3803
     This interface is only to be used when initializing
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3804
     instances or by image readers. Calling for a change of an
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3805
     existing image may confuse later pixel interpretation."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3806
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3807
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3808
	width:w
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3809
	height:h
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3810
	photometric:p
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3811
	samplesPerPixel:spp
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3812
	bitsPerSample:bps
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3813
	colorMap:cm
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3814
	bits:pixels
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3815
	mask:nil
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3816
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3817
    "Modified: 20.6.1996 / 17:10:24 / cg"
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3818
!
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3819
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3820
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
  3821
    "set all relevant internal state of the image.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3822
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3823
     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
  3824
     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
  3825
     existing image may confuse later pixel interpretation."
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3826
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3827
    width := w.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3828
    height := h.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3829
    photometric := p.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3830
    samplesPerPixel := spp.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3831
    bitsPerSample := bps.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  3832
    self setColorMap:cm.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3833
    self bits:pixels.
894
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3834
    mask := m.
1041c0edbd35 prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents: 891
diff changeset
  3835
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  3836
    "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
  3837
    "Created: 20.6.1996 / 17:09:53 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3838
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  3839
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  3840
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3841
!Image methodsFor:'conversion helpers'!
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3842
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3843
rgbColormapFor:aDevice
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3844
    "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
  3845
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3846
    |nColors    "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3847
     scaleRed scaleGreen scaleBlue
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3848
     redShift   "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3849
     greenShift "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3850
     blueShift  "{ Class: SmallInteger }"
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3851
     colorValues|
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3852
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3853
    "/ 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
  3854
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3855
    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
  3856
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3857
    "/ 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
  3858
    "/ (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
  3859
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3860
    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
  3861
    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
  3862
    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
  3863
    redShift := aDevice shiftRed.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3864
    greenShift := aDevice shiftGreen.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3865
    blueShift := aDevice shiftBlue.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3866
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3867
    colorValues := Array uninitializedNew:nColors.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3868
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3869
    0 to:nColors-1 do:[:pixel |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3870
	|clr rv gv bv v "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3871
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3872
	clr := self colorFromValue:pixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3873
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3874
	rv := (clr red * scaleRed) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3875
	gv := (clr green * scaleGreen) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3876
	bv := (clr blue * scaleBlue) rounded.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3877
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3878
	v := rv bitShift:redShift.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3879
	v := v bitOr:(gv bitShift:greenShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3880
	v := v bitOr:(bv bitShift:blueShift).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3881
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  3882
	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
  3883
"/ clr print. ' ' print.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3884
"/ 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
  3885
"/ ' -> ' print. v printNL.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3886
    ].
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3887
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3888
    ^ colorValues
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3889
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3890
    "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
  3891
! !
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  3892
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  3893
!Image methodsFor:'converting'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  3894
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3895
asBurkesDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3896
    "return a burkes dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3897
     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
  3898
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3899
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3900
     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
  3901
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3902
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3903
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3904
    monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3905
    ^ 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
  3906
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
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3909
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3910
     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
  3911
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3912
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3913
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3914
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3915
    "
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
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3920
     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
  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
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3930
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3931
	     width:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3932
	     height:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3933
	     fromArray:#[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3934
			    16r01 16r23
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3935
			    16r45 16r67
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3936
			    16r89 16rab
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3937
			    16rcd 16ref
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3938
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3939
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3940
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3941
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3942
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3943
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3944
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3945
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3946
    "Created: 10.6.1996 / 12:34:44 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  3947
    "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
  3948
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3949
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3950
asDitheredImageUsing:colors
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3951
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3952
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3953
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3954
    ^ self asDitheredImageUsing:colors depth:self depth
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3955
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3956
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3957
asDitheredImageUsing:colors depth:d
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3958
    "return a dithered image from the picture,
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3959
     using colors in colors for dithering."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3960
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3961
    |newBits|
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3962
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3963
    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
  3964
    newBits isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  3965
	self error:'dithering failed'
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3905
diff changeset
  3966
    ].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  3967
    ^ (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
  3968
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3969
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  3970
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3971
asErrorDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3972
    "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
  3973
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3974
    DitherAlgorithm == #burkes ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3975
	^ self asBurkesDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3976
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3977
    DitherAlgorithm == #stevensonArce ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3978
	^ self asStevensonArceDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3979
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3980
    ^ self asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3981
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3982
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3983
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3984
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3985
     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
  3986
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3987
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3988
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3989
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3990
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3991
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3992
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3993
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  3994
     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
  3995
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3996
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3997
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3998
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  3999
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4000
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4001
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4002
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4003
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4004
	     width:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4005
	     height:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4006
	     fromArray:#[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4007
			    16r01 16r23
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4008
			    16r45 16r67
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4009
			    16r89 16rab
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4010
			    16rcd 16ref
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4011
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4012
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4013
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4014
     i asErrorDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4015
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4016
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4017
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4018
    "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
  4019
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4020
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4021
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4022
    "return a floyd-steinberg dithered pseudoForm from the picture.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4023
     Use the colors in the fixColors array.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4024
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4025
     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
  4026
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4027
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4028
    |pseudoBits f deviceDepth map|
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4029
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4030
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4031
    deviceDepth == 8 ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4032
	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4033
	    ^ nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4034
	]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4035
    ].
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4036
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4037
    pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4038
    pseudoBits isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4039
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4040
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4041
    f isNil ifTrue:[^ nil].
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4042
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4043
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4044
    "/ have to create a funny colorMap, where
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4045
    "/ color at:index == color colorId:index
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4046
    "/
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4047
    map := Array new:256.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4048
    fixColors do:[:clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4049
	map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4050
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4051
    f colorMap:map.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4052
    f initGC.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4053
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4054
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4055
	drawBits:pseudoBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4056
	bitsPerPixel:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4057
	depth:deviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4058
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4059
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4060
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4061
	into:(f id) x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4062
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4063
	with:(f gcId).
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4064
    ^ f
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4065
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4066
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4067
     example:
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4068
	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
  4069
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4070
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4071
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4072
     map := #(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4073
		  (0     0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4074
		  (0     0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4075
		  (0    50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4076
		  (0    50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4077
		  (0   100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4078
		  (0   100 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4079
		  (100   0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4080
		  (100   0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4081
		  (100  50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4082
		  (100  50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4083
		  (100 100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4084
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4085
						      green:(rgb at:2)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4086
						       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4087
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4088
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4089
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4090
		      colors:map
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4091
			nRed:2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4092
		      nGreen:3
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4093
		       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4094
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4095
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4096
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4097
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4098
    "Modified: 14.6.1996 / 16:52:34 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4099
    "Created: 23.6.1997 / 15:25:37 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4100
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4101
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4102
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4103
    "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
  4104
     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
  4105
     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
  4106
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4107
     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
  4108
     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
  4109
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4110
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4111
    |pseudoBits f deviceDepth map|
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4112
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4113
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4114
    deviceDepth == 8 ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4115
	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4116
	    ^ nil
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4117
	]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4118
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4119
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4120
    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
  4121
    pseudoBits isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4122
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4123
    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
  4124
    f isNil ifTrue:[^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4125
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4126
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4127
    "/ have to create a funny colorMap, where
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4128
    "/ color at:index == color colorId:index
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4129
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4130
    map := Array new:256.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4131
    fixColors do:[:clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4132
	map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4133
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4134
    f colorMap:map.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4135
    f initGC.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4136
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4137
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4138
	drawBits:pseudoBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4139
	bitsPerPixel:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4140
	depth:deviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4141
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4142
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4143
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4144
	into:(f id) x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4145
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4146
	with:(f gcId).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4147
    ^ f
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4148
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4149
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4150
     example:
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4151
	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
  4152
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4153
     |img8 reducedImg8 img4 map form|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4154
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4155
     map := #(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4156
		  (0     0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4157
		  (0     0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4158
		  (0    50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4159
		  (0    50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4160
		  (0   100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4161
		  (0   100 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4162
		  (100   0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4163
		  (100   0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4164
		  (100  50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4165
		  (100  50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4166
		  (100 100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4167
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4168
						      green:(rgb at:2)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4169
						       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4170
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4171
     img8 := Image fromFile:'goodies/bitmaps/bf.im8'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4172
     form := img8 paletteImageAsDitheredPseudoFormOn:Display
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4173
		      colors:map
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4174
			nRed:2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4175
		      nGreen:3
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4176
		       nBlue:2.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4177
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4178
     img4 := Depth4Image fromImage:img8.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4179
    "
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4180
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4181
    "Modified: 14.6.1996 / 16:52:34 / cg"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4182
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  4183
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4184
asFloydSteinbergDitheredGrayFormOn:aDevice
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4185
    "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
  4186
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4187
    |depth bits|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4188
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4189
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4190
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4191
    or:[aDevice hasGrayscales not]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4192
	"/ for monochrome, there is specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4193
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4194
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4195
	bits := self floydSteinbergDitheredMonochromeBits.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4196
    ] ifFalse:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4197
	bits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4198
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4199
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4200
    ^ 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
  4201
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4202
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4203
     |i|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4204
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4205
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4206
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4207
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4208
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4209
    "
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4210
     |i|
841
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4211
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4212
     i := Image fromFile:'bitmaps/granite.tiff'.
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4213
     (i asFloydSteinbergDitheredGrayFormOn:Display) inspect
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4214
    "
c6963839573f comment
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
  4215
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4216
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4217
    "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
  4218
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4219
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4220
asFloydSteinbergDitheredGrayImageDepth:depth
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4221
    "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
  4222
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4223
    |ditheredBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4224
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4225
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4226
	^ self asFloydSteinbergDitheredMonochromeImage
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4227
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4228
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1778
diff changeset
  4229
    ditheredBits := self floydSteinbergDitheredGrayBitsDepth:depth.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4230
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4231
	width:width height:height fromArray:ditheredBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4232
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4233
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4234
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4235
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4236
     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
  4237
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4238
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4239
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4240
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4241
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4242
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4243
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4244
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4245
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4246
     i := Depth24Image width:4 height:1
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4247
	  fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4248
	    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
  4249
	    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
  4250
	    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
  4251
	    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
  4252
     i := i magnifiedBy:4@1.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4253
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4254
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4255
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4256
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4257
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4258
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4259
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4260
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4261
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4262
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4263
     i := Depth24Image width:4 height:6
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4264
	  fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4265
	    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
  4266
	    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
  4267
	    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
  4268
	    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
  4269
	    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
  4270
	    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
  4271
     i := i magnifiedBy:30.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4272
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4273
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4274
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4275
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4276
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4277
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4278
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4279
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4280
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4281
     i := Image fromFile:'granite.tiff'.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4282
     i inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4283
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4284
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4285
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4286
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4287
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4288
    "
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4289
     |i|
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  4290
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4291
     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
  4292
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4293
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4294
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4295
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4296
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4297
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4298
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4299
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4300
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4301
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4302
	     width:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4303
	     height:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4304
	     fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4305
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4306
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4307
			    16r89 16rab
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4308
			    16rcd 16ref
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4309
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4310
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4311
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4312
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4313
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4314
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4315
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4316
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4317
    "Created: 10.6.1996 / 12:33:47 / cg"
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  4318
    "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
  4319
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4320
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4321
asFloydSteinbergDitheredMonochromeFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4322
    "return a dithered moncohrome form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4323
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4324
    |monoBits|
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4325
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4326
    monoBits := self floydSteinbergDitheredMonochromeBits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4327
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4328
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4329
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4330
     |i f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4331
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4332
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4333
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4334
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4335
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4336
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4337
     |i f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4338
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4339
     i := Depth2Image width:8 height:8
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4340
	  fromArray:#[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4341
			4r0000 4r0000
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4342
			4r0000 4r0000
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4343
			4r1111 4r1111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4344
			4r1111 4r1111
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4345
			4r2222 4r2222
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4346
			4r2222 4r2222
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4347
			4r3333 4r3333
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4348
			4r3333 4r3333
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4349
		     ].
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4350
     (i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4351
    "
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4352
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4353
    "Created: 10.6.1996 / 14:11:39 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4354
    "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
  4355
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4356
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4357
asFloydSteinbergDitheredMonochromeImage
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4358
    "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
  4359
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4360
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4361
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4362
    monoBits := self floydSteinbergDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4363
    ^ 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
  4364
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4365
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4366
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4367
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4368
     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
  4369
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4370
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4371
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4372
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4373
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4374
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4375
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4376
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4377
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4378
     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
  4379
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4380
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4381
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4382
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4383
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4384
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4385
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4386
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4387
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4388
     i := Depth4Image
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4389
	     width:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4390
	     height:4
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4391
	     fromArray:#[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4392
			    16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4393
			    16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4394
			    16r89 16rab
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4395
			    16rcd 16ref
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4396
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4397
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4398
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4399
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4400
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4401
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4402
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4403
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4404
    "Created: 10.6.1996 / 12:33:47 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  4405
    "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
  4406
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  4407
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4408
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4409
    "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
  4410
     using colors in colors for dithering."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4411
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4412
    |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
  4413
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4414
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4415
    has8BitImage := (deviceDepth == 8)
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4416
		    or:[ (aDevice supportedImageFormatForDepth:8) notNil ].
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4417
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4418
    has8BitImage ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4419
	deviceDepth == 4 ifFalse:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4420
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4421
	pseudoBits8 := self nfloydSteinbergDitheredDepth8BitsColors:colors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4422
	pseudoBits8 isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4423
	"/ convert to devices depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4424
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4425
	pseudoBits := ByteArray new:(width*4+7//8 * height).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4426
	pseudoBits8 compressPixels:4 width:width height:height into:pseudoBits mapping:nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4427
	d := 4.
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4428
    ] ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4429
	pseudoBits := self nfloydSteinbergDitheredDepth8BitsColors:colors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4430
	pseudoBits isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4431
	d := 8.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4432
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4433
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4434
    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
  4435
    f isNil ifTrue:[^ nil].
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4436
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4437
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4438
    "/ have to create a funny colorMap, where
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4439
    "/ color at:index == color colorId:index
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4440
    "/
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4441
    map := Array new:256 withAll:0.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4442
    colors do:[:clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4443
	clr notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4444
	    map at:clr colorId + 1 put:clr
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4445
	]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4446
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4447
    f colorMap:map.
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4448
    f initGC.
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4449
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4450
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4451
	drawBits:pseudoBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4452
	bitsPerPixel:d
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4453
	depth:deviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4454
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4455
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4456
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4457
	into:(f id) x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4458
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4459
	with:(f gcId).
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4460
    ^ f
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4461
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4462
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4463
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4464
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4465
     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
  4466
     (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
  4467
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4468
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4469
     |i|
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4470
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4471
     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
  4472
     (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
  4473
    "
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4474
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4475
    "Created: 17.6.1996 / 12:13:35 / cg"
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4476
    "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
  4477
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  4478
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4479
asFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4480
    "get a device form, with best possible approximation.
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4481
     remember it in case someone asks again."
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4482
1041
30452cf0805b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 942
diff changeset
  4483
    |form visual|
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4484
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4485
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4486
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4487
    mask notNil ifTrue:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4488
        mask := mask onDevice:aDevice
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4489
    ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4490
    bytes isNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4491
        pixelFunction notNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4492
            self computeBitsFromPixelFunction.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4493
        ]
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4494
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
  4495
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4496
    (aDevice depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4497
    or:[aDevice hasGrayscales not]) ifTrue:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4498
        form := self asMonochromeFormOn:aDevice.
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4499
    ] ifFalse:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4500
        ((visual := aDevice visualType) == #StaticGray) ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4501
            form := self asGrayFormOn:aDevice.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4502
        ] ifFalse:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4503
            (visual == #PseudoColor
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4504
             or:[visual == #StaticColor]) ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4505
                form := self asPseudoFormQuickOn:aDevice.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4506
            ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4507
        ]
2212
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4508
    ].
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4509
ddc9cb6aeb73 more caching if device forms.
Claus Gittinger <cg@exept.de>
parents: 2206
diff changeset
  4510
    form isNil ifTrue:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4511
        "/ kludge: repair a 'should not happen' situation...
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4512
        photometric isNil ifTrue:[ self repairPhotometric ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4513
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4514
        (photometric == #palette) ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4515
            form := self paletteImageAsFormOn:aDevice
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4516
        ] ifFalse:[
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
  4517
            (photometric == #rgb or:[photometric == #rgba or:[photometric == #argb]]) ifTrue:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4518
                form := self rgbImageAsFormOn:aDevice
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4519
            ] ifFalse:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4520
                (photometric == #cmy or:[photometric == #cmyk]) ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4521
                    form := self rgbImageAsFormOn:aDevice
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4522
                ] ifFalse:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4523
                    form := self greyImageAsFormOn:aDevice
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4524
                ]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4525
            ]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4526
        ].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4527
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  4528
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4529
    (device isNil or:[aDevice == device]) ifTrue:[
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4530
        "remember this form in the receiver ..."
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4531
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4532
        form notNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4533
            form := form asImageForm.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4534
            deviceForm := form.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4535
            maskedPixelsAre0 := nil.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4536
            device isNil ifTrue:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4537
                device := aDevice.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4538
                Lobby register:self
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4539
            ] ifFalse:[
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4540
                Lobby registerChange:self
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4541
            ].
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  4542
            mask notNil ifTrue:[
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  4543
                self clearMaskedPixels.
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  4544
            ].
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  4545
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4546
            "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4547
             can save space, by not keeping the images data-bits
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4548
             twice (here and in the device form)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4549
            "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4550
            form forgetBits
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
  4551
        ]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4552
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4553
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4554
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4555
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4556
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4557
     |i|
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4558
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4559
     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
  4560
     (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
  4561
    "
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4562
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  4563
    "Modified: / 06-06-2007 / 12:18:43 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4564
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4565
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4566
asGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4567
    "get a gray device form"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4568
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4569
    ^ self asGrayFormOn:aDevice dither:DitherAlgorithm.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4570
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4571
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4572
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4573
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4574
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4575
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4576
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4577
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4578
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4579
    "Created: 10.6.1996 / 18:44:42 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4580
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4581
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4582
asGrayFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4583
    "get a greyscale device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4584
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4585
    |depth|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4586
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4587
    depth := aDevice depth.
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4588
    (depth == 1
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4589
    or:[aDevice hasGrayscales not]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4590
	^ self asMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4591
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4592
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4593
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4594
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4595
	^ self asThresholdGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4596
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4597
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4598
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4599
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4600
	^ self asOrderedDitheredGrayFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4601
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4602
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4603
    ^ self asFloydSteinbergDitheredGrayFormOn:aDevice.
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
    "Created: 10.6.1996 / 18:42:01 / cg"
852
318a6190e31d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  4606
    "Modified: 14.6.1996 / 15:17:28 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4607
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4608
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4609
asGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4610
    "get a gray image from the receiver"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4611
6592
71b6996c8ed8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6586
diff changeset
  4612
    ((self colorMap notNil and:[depth <= 8 and:[depth >= self depth]])
5160
f465233332f1 fixed asGrayImage
sr
parents: 5143
diff changeset
  4613
    or:[ self depth >= 8 "do need for dither" ]) ifTrue:[
6592
71b6996c8ed8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6586
diff changeset
  4614
        ^ self copyWithColorMapProcessing:[:clr | Color brightness:(clr brightness)].
4417
5e5d9b696293 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  4615
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4616
    ^ self asGrayImageDepth:depth dither:DitherAlgorithm.
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|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4620
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4621
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4622
     (i asGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4623
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4624
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4625
    "Modified: 10.6.1996 / 17:39:30 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4626
    "Created: 10.6.1996 / 19:07:08 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4627
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4628
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4629
asGrayImageDepth:depth dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4630
    "get a greyscale image, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4631
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4632
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4633
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4634
	^ self asThresholdGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4635
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4636
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4637
    (aDitherAlgorithm == #pattern
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4638
    or:[aDitherAlgorithm == #ordered]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4639
	^ self asOrderedDitheredGrayImageDepth:depth
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4640
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4641
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4642
    ^ self asFloydSteinbergDitheredGrayImageDepth:depth
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4643
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4644
    "Created: 10.6.1996 / 19:08:21 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4645
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  4646
4423
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4647
asImageWithDepth:depth
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4648
    "return a new image with another depth. Notice that this
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4649
     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
  4650
     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
  4651
     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
  4652
     In the other case, use one of the dithering converters"
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4653
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4654
    |imageClass|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4655
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4656
    imageClass := Image implementorForDepth:depth.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4657
    ^ imageClass fromImage:self
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4658
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4659
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4660
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4661
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4662
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4663
     (i asImageWithDepth:24) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4664
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4665
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4666
     |i|
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4667
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4668
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4669
     (i asImageWithDepth:4) inspect.
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4670
    "
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4671
!
dc94d8e838e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4421
diff changeset
  4672
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4673
asMonochromeFormOn:aDevice
48194c26a46c Initial revision
claus
parents:
diff changeset
  4674
    "get a monochrome device form"
48194c26a46c Initial revision
claus
parents:
diff changeset
  4675
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4676
    |form|
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4677
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4678
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm].
4390
8d752f4cd9e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4380
diff changeset
  4679
    self depth == 1 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4680
	((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4681
	^ self asFormOn:aDevice
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4682
    ].
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4683
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4684
    form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4685
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4686
    (device isNil or:[aDevice == device]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4687
	"remember this form in the receiver ..."
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4688
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4689
	form notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4690
	    form := form asImageForm.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4691
	    monoDeviceForm := form.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4692
	    device isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4693
		device := aDevice.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4694
		Lobby register:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4695
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4696
		Lobby registerChange:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4697
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4698
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4699
	     can save space, by not keeping the images data-bits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4700
	     twice (here and in the device form)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4701
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4702
	    form forgetBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4703
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  4704
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
  4705
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  4706
    ^ form
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4707
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4708
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4709
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4710
4173
100ca435fb0e New class Form::ImageForm for Forms that are created from Images.
Stefan Vogel <sv@exept.de>
parents: 4168
diff changeset
  4711
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4712
     (i asMonochromeFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4713
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4714
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
  4715
    "Modified: 23.10.1997 / 00:44:59 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4716
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4717
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4718
asMonochromeFormOn:aDevice dither:aDitherAlgorithm
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4719
    "get a monochrome device form, using aDitherAlgorithm."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4720
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4721
    |monoBits|
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4722
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4723
    (aDitherAlgorithm isNil
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4724
    or:[aDitherAlgorithm == #threshold]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4725
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4726
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4727
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4728
    aDitherAlgorithm == #burkes ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4729
	monoBits := self burkesDitheredMonochromeBits.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4730
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4731
	aDitherAlgorithm == #stevensonArce ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4732
	    monoBits := self stevensonArceDitheredMonochromeBits.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4733
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4734
	    (aDitherAlgorithm == #pattern
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4735
	    or:[aDitherAlgorithm == #ordered]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4736
		^ self asOrderedDitheredGrayFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4737
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4738
		^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4739
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  4740
	]
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4741
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4742
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4743
    "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4744
    "/ make its pixel interpretation correct for the device
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4745
    "/
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4746
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4747
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4748
    "Modified: 10.6.1996 / 20:18:05 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4749
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  4750
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4751
asNearestPaintDepth8FormOn:aDevice colors:fixColors
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4752
    "return a nearest paint pseudoForm from the palette picture.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4753
     Use the colors in the fixColors array.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4754
     By passing the ditherColors as extra array, this method can
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4755
     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
  4756
     for example to create dithered Depth4Images from Depth8Images."
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4757
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4758
    ^ 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
  4759
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4760
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4761
     example:
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4762
	color reduction from Depth8 to Depth4 can be done by:
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4763
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4764
     |img8 reducedImg8 img4 map form|
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4765
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4766
     map := #(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4767
		  (0     0   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4768
		  (0     0 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4769
		  (0    50   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4770
		  (0    50 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4771
		  (0   100   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4772
		  (0   100 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4773
		  (100   0   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4774
		  (100   0 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4775
		  (100  50   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4776
		  (100  50 100)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4777
		  (100 100   0)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4778
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4779
						      green:(rgb at:2)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4780
						       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4781
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4782
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4783
     form := img8 asNearestPaintDepth8FormOn:Display
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4784
		      colors:map
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4785
			nRed:2
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4786
		      nGreen:3
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4787
		       nBlue:2.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4788
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4789
     img4 := Depth4Image fromImage:img8.
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4790
    "
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4791
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4792
    "Modified: 17.6.1996 / 18:52:47 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4793
    "Created: 23.6.1997 / 15:26:09 / cg"
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4794
!
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  4795
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4796
asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4797
    "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
  4798
     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
  4799
     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
  4800
     Color class.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4801
     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
  4802
     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
  4803
     for example to create dithered Depth4Images from Depth8Images."
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4804
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4805
    |pseudoBits f deviceDepth map|
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4806
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4807
    deviceDepth := aDevice depth.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4808
    deviceDepth == 8 ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4809
	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4810
	    ^ nil
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4811
	]
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  4812
    ].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4813
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4814
    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
  4815
    pseudoBits isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4816
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  4817
    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
  4818
    f isNil ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4819
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4820
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4821
    "/ have to create a funny colorMap, where
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4822
    "/ color at:index == color colorId:index
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4823
    "/
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4824
    map := Array new:256.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4825
    fixColors do:[:clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4826
	map at:clr colorId + 1 put:clr
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4827
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4828
    f colorMap:map.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4829
    f initGC.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4830
    f bits:pseudoBits.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4831
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4832
	drawBits:pseudoBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4833
	bitsPerPixel:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4834
	depth:deviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4835
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4836
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4837
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4838
	into:(f id) x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4839
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4840
	with:(f gcId).
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4841
    ^ f
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4842
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4843
    "
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4844
     example:
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4845
	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
  4846
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4847
     |img8 reducedImg8 img4 map form|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4848
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4849
     map := #(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4850
		  (0     0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4851
		  (0     0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4852
		  (0    50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4853
		  (0    50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4854
		  (0   100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4855
		  (0   100 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4856
		  (100   0   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4857
		  (100   0 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4858
		  (100  50   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4859
		  (100  50 100)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4860
		  (100 100   0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4861
		  (100 100 100)) collect:[:rgb | (Color red:(rgb at:1)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4862
						      green:(rgb at:2)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4863
						       blue:(rgb at:3)) onDevice:Display].
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4864
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4865
     img8 := Image fromFile:'goodies/bitmaps/claus.gif'.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4866
     form := img8 asNearestPaintDepth8FormOn:Display
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4867
		      colors:map
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4868
			nRed:2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4869
		      nGreen:3
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  4870
		       nBlue:2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4871
     img8 := Depth8Image fromForm:form.    'dithered version of original image'.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4872
     img4 := Depth4Image fromImage:img8.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4873
    "
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4874
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4875
    "Created: 17.6.1996 / 18:47:46 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4876
    "Modified: 17.6.1996 / 18:52:47 / cg"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4877
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  4878
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4879
asNearestPaintImageDepth:d colors:colors
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4880
    "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
  4881
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4882
    |newBits|
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4883
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4884
    d ~~ 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  4885
	self error:'unsupported depth'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4886
    ].
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4887
    newBits := self nearestPaintDepth8BitsColors:colors nRed:nil nGreen:nil nBlue:nil.
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4888
    newBits isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  4889
	self error:'conversion failed'
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4890
    ].
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4891
    ^ (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
  4892
!
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  4893
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4894
asOrderedDitheredGrayFormOn:aDevice
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4895
    "return a dithered depth-x grey form from the receiver image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4896
     Uses an 8x8 dithermatrix."
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4897
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  4898
    |depth bits|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4899
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4900
    depth := aDevice depth.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4901
    (depth == 1
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4902
    or:[aDevice hasGrayscales not]) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4903
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4904
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4905
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4906
	^ self asOrderedDitheredMonochromeFormOn:aDevice
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4907
    ].
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4908
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4909
    bits := self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4910
		orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4911
		ditherWidth:8
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  4912
		depth:depth.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4913
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  4914
    ^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4915
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4916
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4917
     |i|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4918
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  4919
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4920
     (i asOrderedDitheredGrayFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4921
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  4922
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4923
    "Modified: 24.6.1997 / 22:19:30 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4924
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  4925
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4926
asOrderedDitheredGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4927
    "return a dithered depth-x grey image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4928
     Uses an 8x8 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4929
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4930
    |dither|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4931
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4932
    dither := self class orderedDitherMatrixOfSize:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4933
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  4934
    (depth == 1) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4935
	"/ for monochrome, there is highly specialized
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4936
	"/ monochrome dither code available
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4937
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4938
	^ Depth1Image
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4939
	    width:width
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4940
	    height:height
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4941
	    fromArray:(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4942
		self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4943
		    orderedDitheredMonochromeBitsWithDitherMatrix:dither
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4944
		    ditherWidth:8)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4945
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4946
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4947
    ^ (self class implementorForDepth:depth)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4948
	width:width
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4949
	height:height
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4950
	fromArray:(
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4951
	    self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4952
		orderedDitheredGrayBitsWithDitherMatrix:dither
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4953
		ditherWidth:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  4954
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4955
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4956
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4957
     |i i1 i2 i4 i8|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4958
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4959
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4960
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4961
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4962
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4963
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4964
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4965
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4966
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4967
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4968
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4969
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4970
     i8 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4971
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4972
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4973
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4974
     |i i1 i2 i4 i8|
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  4975
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4976
     i1 := i asOrderedDitheredGrayImageDepth:1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4977
     i1 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4978
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4979
     i2 := i asOrderedDitheredGrayImageDepth:2.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4980
     i2 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4981
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4982
     i4 := i asOrderedDitheredGrayImageDepth:4.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4983
     i4 inspect.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4984
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4985
     i8 := i asOrderedDitheredGrayImageDepth:8.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4986
     i8 inspect.
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4987
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4988
     i2 := i8 asOrderedDitheredGrayImageDepth:2.
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  4989
     i2 inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4990
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4991
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4992
    "Created: 7.6.1996 / 18:03:54 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  4993
    "Modified: 24.6.1997 / 22:19:36 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4994
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4995
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4996
asOrderedDitheredMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4997
    "return a dithered monochrome form from the grey image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4998
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  4999
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5000
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5001
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5002
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5003
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5004
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5005
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5006
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5007
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5008
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5009
	asOrderedDitheredMonochromeFormOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5010
	ditherMatrix:(self class orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5011
	ditherWidth:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5012
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5013
"/    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5014
"/        asOrderedDitheredMonochromeFormOn:aDevice
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5015
"/        ditherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5016
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5017
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5018
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5019
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5020
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5021
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5022
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5023
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5024
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5025
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5026
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5027
     i := (Image fromFile:'goodies/bitmaps/winBitmaps/a11.ico') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5028
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5029
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5030
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5031
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5032
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5033
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5034
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5035
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5036
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5037
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5038
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5039
     i := (Image fromFile:'doc/online/pictures/PasteButton.gif') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5040
     f := i asOrderedDitheredMonochromeFormOn:Display.
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
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5043
     |i f|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5044
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5045
     i := (Image fromFile:'goodies/bitmaps/gifImages/blue-ball.gif') magnifiedBy:1.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5046
     f := i asOrderedDitheredMonochromeFormOn:Display.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5047
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5048
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5049
    "Created: 7.6.1996 / 14:52:32 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  5050
    "Modified: 17.4.1997 / 01:10:10 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5051
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5052
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5053
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5054
    "return a dithered monochrome form from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5055
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5056
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  5057
    |monoBits|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5058
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5059
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
  5060
    ^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
813
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
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5063
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5064
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5065
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5066
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5067
     (i asOrderedDitheredMonochromeFormOn:Display) inspect
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
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5070
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5071
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5072
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5073
     (i asOrderedDitheredMonochromeFormOn: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 asOrderedDitheredMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5080
    "
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
    "Created: 7.6.1996 / 14:51:42 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
  5083
    "Modified: 17.4.1997 / 01:08:24 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5084
!
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
asOrderedDitheredMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5087
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5088
     Uses a 4x4 dithermatrix."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5089
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5090
    "/ 4x4 seems a good comprimize between:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5091
    "/    number of grey levels (8x8 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5092
    "/    artifacts             (4x4 is better)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5093
    "/
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5094
    "/ could look at the image and decide upon the number of
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5095
    "/ distinct colors present. Use 8x8 for high-number,
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5096
    "/ 4x4 for small number of colors ...
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5097
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5098
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5099
	asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5100
	ditherWidth:4
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5101
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5102
"/    ^ self
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5103
"/        asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5104
"/        ditherWidth:8
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5105
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5106
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5107
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5108
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5109
     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
  5110
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5111
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5112
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5113
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5114
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5115
     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
  5116
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5117
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5118
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5119
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5120
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5121
     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
  5122
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5123
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5124
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5125
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5126
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5127
     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
  5128
     i asOrderedDitheredMonochromeImage inspect
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5129
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5130
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5131
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5132
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5133
     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
  5134
     i asOrderedDitheredMonochromeImage inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5135
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5136
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5137
    "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
  5138
    "Modified: 10.6.1996 / 11:15:09 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5139
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5140
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5141
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5142
    "return a dithered monochrome image from the receiver image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5143
     Uses the passed ditherMatrix and ditherWidth."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5144
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5145
    |monoBits|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5146
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5147
    monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5148
    ^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5149
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5150
    "order-4 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5151
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5152
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5153
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5154
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5155
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5156
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5157
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5158
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5159
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5160
    "order-6 dither:
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5161
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5162
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5163
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5164
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5165
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5166
	asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5167
	ditherWidth:8
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5168
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5169
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5170
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5171
    "thresholding at:0.5 (all above 0.5 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5172
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5173
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5174
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5175
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5176
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5177
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5178
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5179
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5180
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5181
    "thresholding at: 0.25 (all above 0.25 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5182
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5183
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5184
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5185
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5186
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5187
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5188
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5189
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5190
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5191
    "thresholding at: 0.75 (all above 0.75 becomes white):
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5192
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5193
     |i|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5194
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5195
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5196
     i
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5197
	asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5198
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5199
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5200
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5201
    "Modified: 7.6.1996 / 17:23:47 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5202
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5203
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5204
asPseudoFormQuickOn:aDevice
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5205
    "return a pseudo-deviceForm from the image.
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5206
     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
  5207
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5208
    |f d
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5209
     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
  5210
     w            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5211
     h            "{ Class: SmallInteger }"
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5212
     dDev         "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5213
     nClr         "{ Class: SmallInteger }"
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5214
     bytesPerLine "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5215
     usedColors pix fmt bytes|
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5216
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5217
    d := self depth.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5218
    (d == 1
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5219
    or:[d == 2
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5220
    or:[d == 4
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5221
    or:[d == 8]]]) ifFalse:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5222
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5223
    bytes := self bits.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5224
    w := width.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5225
    h := height.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
  5226
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5227
    "/ 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
  5228
    "/ if the padding is not supported: fail
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5229
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5230
    dDev := aDevice depth.
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5231
    (bytesPerLine := dDev) == 8 ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5232
	bytesPerLine := (w * dDev + 7) // 8.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5233
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5234
2532
Claus Gittinger <cg@exept.de>
parents: 2530
diff changeset
  5235
    fmt := aDevice supportedImageFormatForDepth:dDev.
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5236
    fmt isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5237
	"/ cannot draw directly
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5238
	^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5239
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5240
    (bytesPerLine * 8) \\ (fmt at:#padding) == 0 ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5241
	"/ mhmh - ought to repad here;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5242
	"/ however, the nonQuick converter does it.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5243
	^ nil
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5244
    ].
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
  5245
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5246
    "/ see if all of the images colors are representable
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5247
    "/ on the device
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5248
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5249
    bits := self bitsPerPixel.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5250
    nClr := (1 bitShift:bits).
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5251
    cMap := Array new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5252
    idMap := ByteArray new:nClr.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5253
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5254
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5255
	nClr := nClr min:(colorMap size)
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5256
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5257
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5258
    d == 8 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5259
	usedColors := bytes usedValues.    "gets us an array filled with used values"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5260
	1 to:nClr do:[:pixel |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5261
	    (usedColors includes:(pixel - 1)) ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5262
		clr := Color black
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5263
	    ] ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5264
		clr := self colorFromValue:pixel-1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5265
		clr := clr exactOn:aDevice.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5266
		clr isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5267
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5268
	    (pix := clr colorId) isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5269
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5270
	    cMap at:(pixel) put:clr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5271
	    idMap at:(pixel) put:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5272
	].
878
b99add8dc742 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
  5273
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5274
	1 to:nClr do:[:pixel |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5275
	    clr := self colorFromValue:pixel-1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5276
	    clr := clr exactOn:aDevice.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5277
	    clr isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5278
	    (pix := clr colorId) isNil ifTrue:[^ nil].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5279
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5280
	    cMap at:(pixel) put:clr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5281
	    idMap at:(pixel) put:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5282
	].
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5283
    ].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5284
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5285
    "/ got all colors; good - simply change depth & translate pixels
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5286
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5287
    (d == 8 and:[dDev == 8]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5288
	"/ only translate
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5289
	temp := ByteArray uninitializedNew:(w * h).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5290
	bytes expandPixels:8         "xlate only"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5291
		    width:w
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5292
		   height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5293
		     into:temp
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5294
		  mapping:idMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5295
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5296
	"/ stupid: expandPixels can only handle any-to-8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5297
	"/ compressPixels can only handle 8-to-any
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5298
	"/ However, those methods are faster
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5299
	"/ - even if we convert twice.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5300
	"/ Therefore, convert first from myDepth to 8,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5301
	"/ then from 8 to the device depth.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5302
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5303
	d ~~ 8 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5304
	    temp8 := ByteArray uninitializedNew:(w * h).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5305
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5306
	    bytes expandPixels:d
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5307
			 width:w
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5308
			height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5309
			  into:temp8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5310
		       mapping:idMap.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5311
	    idMap := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5312
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5313
	    temp8 := bytes.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5314
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5315
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5316
	dDev ~~ 8 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5317
	    temp := ByteArray uninitializedNew:(bytesPerLine * h).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5318
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5319
	    temp8 compressPixels:dDev
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5320
			 width:w
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5321
			height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5322
			  into:temp
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5323
		       mapping:idMap.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5324
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5325
	    temp := temp8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5326
	].
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5327
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5328
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  5329
    f := Form width:w height:h depth:dDev onDevice:aDevice.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5330
    f isNil ifTrue:[^ nil].
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5331
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5332
    f colorMap:cMap.
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5333
    f initGC.
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5334
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5335
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5336
	drawBits:temp
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5337
	depth:dDev
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5338
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5339
	width:w
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5340
	height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5341
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5342
	into:(f id) x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5343
	width:w
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5344
	height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5345
	with:(f gcId).
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5346
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5347
    ^ f
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5348
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5349
    "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5350
     (
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5351
	(((Depth4Image
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5352
	     width:4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5353
	     height:4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5354
	     fromArray:#[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5355
			    16r01 16r23
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5356
			    16r45 16r67
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5357
			    16r89 16rab
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5358
			    16rcd 16ref
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5359
			]))
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5360
	       magnifiedBy:30
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5361
	 )
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5362
	  asPseudoFormQuickOn:Display
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5363
      ) inspect
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5364
     "
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5365
2113
c64f89f9ffba checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2102
diff changeset
  5366
    "Modified: / 7.5.1998 / 19:40:47 / cg"
873
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5367
!
f44d57cc8d05 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  5368
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5369
asStevensonArceDitheredMonochromeImage
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5370
    "return a stevenson-arce dithered monochrome image from the receiver image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5371
     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
  5372
     a floyd-steinberg dithered image.
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5373
     Notice, that floyd-steinberg dithering is faster; both because less
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5374
     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
  5375
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5376
    |monoBits|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5377
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5378
    monoBits := self stevensonArceDitheredMonochromeBits.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5379
    ^ (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
  5380
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5381
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5382
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5383
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  5384
     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
  5385
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5386
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5387
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5388
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5389
     i asOrderedDitheredMonochromeImage inspect.
5161
d6538957b675 changed #asStevensonArceDitheredMonochromeImage
sr
parents: 5160
diff changeset
  5390
     (i asThresholdMonochromeImage:0.5) inspect
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5391
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5392
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5393
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5394
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5395
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
  5396
     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
  5397
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5398
     i asFloydSteinbergDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5399
     i asBurkesDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5400
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5401
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5402
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5403
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5404
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5405
     |i|
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5406
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5407
     i := Depth4Image
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5408
	     width:4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5409
	     height:4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5410
	     fromArray:#[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5411
			    16r01 16r23
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5412
			    16r45 16r67
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5413
			    16r89 16rab
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5414
			    16rcd 16ref
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  5415
			].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5416
     i := i magnifiedBy:30.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5417
     i inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5418
     i asStevensonArceDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5419
     i asOrderedDitheredMonochromeImage inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5420
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5421
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5422
    "Created: 10.6.1996 / 12:38:29 / cg"
837
eb4ffe2bd008 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 831
diff changeset
  5423
    "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
  5424
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5425
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5426
asThresholdGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5427
    "return a thresholded grey form from the receiver image."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5428
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5429
    |depth|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5430
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5431
    (depth := aDevice depth) == 1 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5432
	^ self asThresholdMonochromeFormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5433
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5434
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5435
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5436
	makeDeviceGrayPixmapOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5437
	depth:depth
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5438
	fromArray:(self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5439
			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
  5440
			ditherWidth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5441
			depth:depth)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5442
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5443
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5444
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5445
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5446
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5447
     (i asThresholdGrayFormOn:Display) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5448
    "
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5449
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5450
    "Created: 10.6.1996 / 18:38:31 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5451
    "Modified: 24.6.1997 / 22:19:46 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5452
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5453
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5454
asThresholdGrayImageDepth:depth
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5455
    "return a thresholded depth-x grey image from the receiver image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5456
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  5457
    (depth == 1) ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5458
	"/ for monochrome, there is highly specialized
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5459
	"/ monochrome dither code available
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5460
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5461
	^ Depth1Image
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5462
	    width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5463
	    height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5464
	    fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5465
		self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5466
		    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
  5467
		    ditherWidth:4)
800
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5468
    ].
0730bb75c28f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  5469
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5470
    ^ (self class implementorForDepth:depth)
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5471
	width:width
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5472
	height:height
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5473
	fromArray:(
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5474
	    self
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5475
		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
  5476
		ditherWidth:4
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5477
		depth:depth)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5478
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5479
    "
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5480
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5481
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5482
     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
  5483
     (i asThresholdGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5484
     (i asThresholdGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5485
     (i asThresholdGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5486
     (i asThresholdGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5487
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5488
     (i asOrderedDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5489
     (i asOrderedDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5490
     (i asOrderedDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5491
     (i asOrderedDitheredGrayImageDepth:8) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5492
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5493
     (i asFloydSteinbergDitheredGrayImageDepth:1) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5494
     (i asFloydSteinbergDitheredGrayImageDepth:2) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5495
     (i asFloydSteinbergDitheredGrayImageDepth:4) inspect.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  5496
     (i asFloydSteinbergDitheredGrayImageDepth:8) inspect.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5497
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5498
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5499
    "Created: 7.6.1996 / 18:13:33 / cg"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  5500
    "Modified: 24.6.1997 / 22:19:52 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5501
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5502
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5503
asThresholdMonochromeFormOn:aDevice
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5504
    "return a threshold monochrome form from the image."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5505
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5506
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  5507
	asOrderedDitheredMonochromeFormOn:aDevice
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5508
	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
  5509
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5510
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5511
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5512
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5513
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5514
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5515
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5516
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5517
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5518
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5519
     |i|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5520
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5521
     i := (Image fromFile:'goodies/bitmaps/a11.ico') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5522
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5523
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5524
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5525
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5526
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5527
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5528
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5529
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5530
     (i asThresholdMonochromeFormOn:Display) inspect
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5531
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5532
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5533
     |i|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5534
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5535
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5536
     i inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5537
     (i asThresholdMonochromeFormOn:Display) inspect
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5538
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5539
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5540
    "Created: 7.6.1996 / 16:15:17 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5541
    "Modified: 10.6.1996 / 17:44:29 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5542
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5543
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5544
asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5545
    "return a threshold monochrome image from the image.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5546
     Threshold means: brightness < 0.5 -> black / otherwise white"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5547
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5548
    ^ self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5549
	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
  5550
	ditherWidth:4
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5551
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5552
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5553
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5554
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5555
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5556
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5557
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5558
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5559
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5560
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5561
     i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5562
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5563
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5564
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5565
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5566
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5567
     i := Image fromFile:'goodies/bitmaps/granite.tiff'.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5568
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5569
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5570
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5571
     |i i2|
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5572
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5573
     i := (Image fromFile:'goodies/bitmaps/PasteButton.tiff') magnifiedBy:10.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5574
     i2 := i asThresholdMonochromeImage
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5575
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5576
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5577
    "Created: 7.6.1996 / 16:15:17 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5578
    "Modified: 7.6.1996 / 17:16:10 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5579
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5580
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5581
asThresholdMonochromeImage:thresholdBrighness
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5582
    "return a threshold monochrome image from the image.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5583
     The argument (0..1) gives the threshold value;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5584
     Threshold means: brightness < threshold -> black / otherwise white"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5585
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5586
    |value ditherMatrix|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5587
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5588
    value := thresholdBrighness * 255.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5589
    ditherMatrix := ByteArray new:256 withAll:(value truncated).
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5590
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5591
    ^ self
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5592
	asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5593
	ditherWidth:16
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5594
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5595
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5596
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5597
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5598
     i := Image width:4 height:4 depth:4
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5599
		fromArray:#[ 16r01 16r23
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5600
			     16r45 16r67
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5601
			     16r89 16rab
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
  5602
			     16rcd 16ref ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5603
     i := i magnifiedBy:30.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5604
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5605
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5606
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5607
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5608
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5609
     (i asThresholdMonochromeImage:1) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5610
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5611
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5612
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5613
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5614
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5615
     i := Image fromFile:'goodies/bitmaps/claus.gif'.
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5616
     i inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5617
     (i asThresholdMonochromeImage:0.125) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5618
     (i asThresholdMonochromeImage:0.25) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5619
     (i asThresholdMonochromeImage:0.5) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5620
     (i asThresholdMonochromeImage:0.625) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5621
     (i asThresholdMonochromeImage:0.75) inspect.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5622
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5623
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5624
    "Created: 7.6.1996 / 16:15:17 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5625
    "Modified: 8.6.1996 / 14:51:57 / cg"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5626
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
  5627
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5628
clearMaskedPixels
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5629
    "assuming that I already have a device representation
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5630
     in deviceForm, clear any masked pixels.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5631
     This will allow faster drawing in the future."
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5632
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5633
    maskedPixelsAre0 == true ifTrue:[^ self].   "/ already cleared
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5634
    mask isNil ifTrue:[^ self].         "/ no mask
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5635
    deviceForm isNil ifTrue:[^ self].   "/ no device rep.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5636
    mask depth ~~ 1 ifTrue:[^ self].    "/ not done with alpha masks
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5637
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5638
    deviceForm 
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5639
        foreground:Color allColor background:Color noColor function:#and;
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5640
        copyPlaneFrom:(mask asFormOn:device) x:0 y:0 toX:0 y:0 width:width height:height.
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5641
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5642
"/    deviceForm clearMaskedPixels:(mask asFormOn:device).
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5643
    maskedPixelsAre0 := true.
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5644
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5645
1591
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5646
    "Created: 12.4.1997 / 12:18:05 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5647
    "Modified: 12.4.1997 / 12:20:19 / cg"
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5648
!
87e1a30150c9 added #clearMaskedPixels.
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  5649
3104
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5650
exactOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5651
    "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
  5652
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5653
    ^ self onDevice:aDevice
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5654
!
edc88b280153 added #exactOn: - for Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3092
diff changeset
  5655
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5656
exactOrNearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5657
    "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
  5658
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5659
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5660
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5661
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5662
fromForm:aForm
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5663
    "setup the receiver from a form"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5664
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5665
    |map c0 c1|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5666
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5667
    width := aForm width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5668
    height := aForm height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5669
    bitsPerSample := self bitsPerSample.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5670
    samplesPerPixel := self samplesPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5671
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5672
    aForm hasBits ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5673
	"/ must read the data from the device
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5674
	self from:aForm in:(0@0 extent:aForm extent).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5675
	^ self
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5676
    ].
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5677
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5678
    "/ the form has all data available
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5679
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5680
    self bits:(aForm bits).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5681
    map := aForm colorMap.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5682
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5683
    aForm depth == 1 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5684
	map isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5685
	    photometric := #whiteIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5686
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5687
	    c0 := map at:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5688
	    c1 := map at:2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5689
	    ((c0 = Color white)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5690
	    and:[c1 = Color black]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5691
		photometric := #whiteIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5692
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5693
		((c0 = Color black)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5694
		and:[c1 = Color white]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5695
		    photometric := #blackIs0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5696
		] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5697
		    photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5698
		    self setColorMap:(Array with:c0 with:c1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5699
		]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5700
	    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5701
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5702
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5703
	map notNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5704
	    photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5705
	    self setColorMap:(map copy).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5706
	] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5707
	    "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5708
	     photometric stays at default
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5709
	     (which is rgb for d24, greyscale for others)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5710
	    "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  5711
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5712
    ].
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  5713
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
  5714
    "Modified: 5.7.1996 / 16:24:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5715
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5716
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5717
fromImage:anImage
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5718
    "setup the receiver from another image.
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5719
     Color precision may be lost, if conversion is from a higher depth image.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5720
     WARNING:
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5721
     This implementation is a slow fallback (the loop over the
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5722
     source pixels is very slow). If this method is used heavily, you
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5723
     may want to redefine it in concrete subclasses for common source images."
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5724
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5725
    ^ 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
  5726
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5727
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5728
fromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5729
    "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
  5730
     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
  5731
     WARNING:
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
  5732
     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
  5733
     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
  5734
     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
  5735
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5736
    |map clr mappedRowPixels samePhotometric
1784
25b96d8904c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  5737
     h "{ Class: SmallInteger }"
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5738
     w "{ Class: SmallInteger }"
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5739
     a r g b rgbPixel|
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5740
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5741
    width := anImage width.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5742
    height := anImage height.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5743
    bitsPerSample := self bitsPerSample.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5744
    samplesPerPixel := self samplesPerPixel.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5745
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5746
    photometricOrNil isNil ifTrue:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5747
        photometric := self class defaultPhotometric
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5748
        "/ photometric := anImage photometric
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5749
    ] ifFalse:[
7156
97b4f12aa796 #BUGFIX
matilk
parents: 7126
diff changeset
  5750
        photometricOrNil == #rgba ifTrue:[
97b4f12aa796 #BUGFIX
matilk
parents: 7126
diff changeset
  5751
            samplesPerPixel == 3 ifTrue:[ photometric := #rgb ]
97b4f12aa796 #BUGFIX
matilk
parents: 7126
diff changeset
  5752
        ] ifFalse:[
97b4f12aa796 #BUGFIX
matilk
parents: 7126
diff changeset
  5753
            photometric := photometricOrNil
97b4f12aa796 #BUGFIX
matilk
parents: 7126
diff changeset
  5754
        ].
4888
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5755
    ].
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5756
7d2d5ef445e3 conversion fixes (palette problem / implizit greyscale conversion)
Claus Gittinger <cg@exept.de>
parents: 4859
diff changeset
  5757
    photometric == #palette ifTrue:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5758
        self colormapFromImage:anImage photometric:photometric.
4859
553f9013f270 only try to fetch colormap for palette images
Claus Gittinger <cg@exept.de>
parents: 4858
diff changeset
  5759
    ].
1374
ab515c0576c6 preserve mask when creating an image from another image.
Claus Gittinger <cg@exept.de>
parents: 1362
diff changeset
  5760
    self mask:anImage mask.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5761
3363
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5762
    samePhotometric := (photometric == anImage photometric).
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5763
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5764
    ((self depth = anImage depth)
de7e8628d329 fixed conversion of 3-3-2 8-bit truecolor images
Claus Gittinger <cg@exept.de>
parents: 3273
diff changeset
  5765
    and:[samePhotometric]) ifTrue:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5766
        self bits:(anImage bits copy).
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5767
        ^ self.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5768
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5769
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  5770
    self bits:(ByteArray uninitializedNew:(self bytesPerRow * height)).
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5771
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5772
    self depth >= anImage depth ifTrue:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5773
        anImage depth <= 12 ifTrue:[
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5774
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5775
            "/ if my depth is greater, all colors can be represented,
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5776
            "/ and the loop can be done over pixel values ...
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5777
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5778
            (colorMap isNil or:[samePhotometric not]) ifTrue:[
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5779
                map := Array new:(1 bitShift:anImage depth).
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5780
                1 to:map size do:[:i |
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5781
                    clr := anImage colorFromValue:(i - 1).
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5782
                    map at:i put:(self valueFromColor:clr).
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5783
                ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5784
            ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5785
            mappedRowPixels := self pixelArraySpecies new:width.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5786
            h := height-1.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5787
            w := width.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5788
            0 to:h do:[:row |
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5789
                anImage rowAt:row into:mappedRowPixels startingAt:1.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5790
                map notNil ifTrue:[
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5791
                    1 to:w do:[:i |
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5792
                        mappedRowPixels at:i put:(map at:(mappedRowPixels at:i)+1)
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5793
                    ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5794
                ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5795
                self rowAt:row putAll:mappedRowPixels
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5796
            ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5797
            ^ self
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5798
        ].
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5799
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5800
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5801
    "/ a hack, for now - alpha is in the low-byte !!!!!!
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5802
    (self depth == 24 and:[anImage depth == 32]) ifTrue:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5803
        (samePhotometric and:[photometric == #rgb]) ifTrue:[
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5804
            "/ can do the bits by simple stripping off the alpha channel
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5805
            anImage valuesFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :pixel |
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5806
                "/ bgra-pixel
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5807
                a := pixel bitAnd:16rFF.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5808
                r := (pixel bitShift:-8) bitAnd:16rFF.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5809
                g := (pixel bitShift:-16) bitAnd:16rFF.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5810
                b := (pixel bitShift:-24) bitAnd:16rFF.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5811
                rgbPixel := r + (g bitShift:8) + (b bitShift:16).
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5812
                self pixelAtX:x y:y put:rgbPixel
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5813
            ].
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5814
            ^ self
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5815
        ].
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5816
    ].
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5817
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5818
    anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr |
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5819
        self colorAtX:x y:y put:clr
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5820
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5821
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5822
    "
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  5823
     |i i2 i4 i8 i16 i24|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5824
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5825
     i := GenericToolbarIconLibrary desktop32x32Icon2.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5826
     i inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5827
     i2 := Depth2Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5828
     i2 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5829
     i4 := Depth4Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5830
     i4 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5831
     i8 := Depth8Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5832
     i8 inspect.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5833
     i16 := Depth16Image fromImage:i.
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  5834
     i16 inspect.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5835
     i24 := Depth24Image fromImage:i.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5836
     i24 inspect.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5837
    "
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5838
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5839
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5840
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5841
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5842
     i := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5843
     Transcript showCR:(
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5844
        Time millisecondsToRun:[
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5845
            i24 := Depth24Image fromImage:i.
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5846
        ]
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5847
     ).
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5848
     i24 inspect.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5849
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5850
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5851
     |i i24|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5852
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5853
     i := Image fromFile:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5854
     MessageTally spyOn:[
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
  5855
        i24 := Depth24Image fromImage:i.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5856
     ]
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5857
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  5858
5712
b4d960599bc8 changed: #fromImage:photometric:
Claus Gittinger <cg@exept.de>
parents: 5710
diff changeset
  5859
    "Modified: / 05-02-2011 / 17:46:58 / cg"
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5860
!
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5861
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5862
fromSubImage:anImage in:aRectangle
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5863
    "setup the receiver from another image, extracting a rectangular area. 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5864
     As with layouts, the rectangle may contain integers (= nr of pixels) or float numbers (= relative size).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5865
     Color precision may be lost, if conversion is from a higher depth image. 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5866
     For palette & rgb images, this may fail if a color cannot be represented."
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5867
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5868
    |w h xL yT imgWidth imgHeight|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5869
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5870
    w := aRectangle width.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5871
    h := aRectangle height.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5872
    xL := aRectangle left.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5873
    yT := aRectangle top.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5874
    imgWidth := anImage width.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5875
    imgHeight := anImage height.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5876
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5877
    xL isFloat ifTrue:[ 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5878
        xL := (imgWidth * xL) rounded min: imgWidth.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5879
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5880
    yT isFloat ifTrue:[ 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5881
        yT := (imgHeight * yT) rounded min:imgHeight.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5882
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5883
    w isFloat ifTrue:[ 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5884
        w := (imgWidth * w) rounded.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5885
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5886
    w := w min:(imgWidth - xL).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5887
    h isFloat ifTrue:[ 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5888
        h := (imgHeight * h) rounded.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5889
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5890
    h := h min:(imgHeight - yT).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5891
    self fromSubImage:anImage inX:xL y:yT width:w height:h
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5892
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5893
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5894
     |i i2 i4 i8 i16 i24|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5895
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5896
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5897
     i inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5898
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5899
     i4 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5900
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5901
     i8 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5902
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5903
     i24 inspect.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5904
    "
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5905
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5906
    "Created: / 20.9.1995 / 01:06:02 / claus"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5907
    "Modified: / 20.9.1995 / 10:15:37 / claus"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5908
    "Modified: / 18.5.1999 / 20:06:55 / cg"
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5909
!
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5910
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5911
fromSubImage:anImage inX:xL y:yT width:w height:h
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5912
    "setup the receiver from another image, extracting a rectangular area. 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5913
     Color precision may be lost, if conversion is from a higher depth image. 
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5914
     For palette & rgb images, this may fail if a color cannot be represented.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5915
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5916
     WARNING:
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5917
       This implementation is a slow fallback (the loop over the
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5918
       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
  5919
       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
  5920
       of creating a subImage with the same depth & palette."
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5921
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5922
    |xR yB imagesMask maskClass|
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5923
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5924
    width := w.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5925
    height := h.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5926
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  5927
    self createPixelStore.
3458
b2e098e6288b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3457
diff changeset
  5928
    depth := self depth.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5929
    bitsPerSample := self bitsPerSample.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5930
    bitsPerPixel := self bitsPerPixel.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5931
    samplesPerPixel := self samplesPerPixel.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5932
    self colormapFromImage:anImage.
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5933
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5934
    xR := xL + w - 1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5935
    yB := yT + h - 1.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5936
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5937
    ((photometric == anImage photometric)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5938
    and:[self bitsPerPixel = anImage bitsPerPixel
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5939
    and:[colorMap = anImage colorMap]]) ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5940
        "/ can do it by value
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5941
        anImage
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5942
            valuesFromX:xL y:yT toX:xR y:yB
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5943
            do:[:x :y :pixelValue | self pixelAtX:x-xL y:y-yT put:pixelValue ]
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5944
    ] ifFalse:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5945
        "/ must do it by colors
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5946
        anImage
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5947
            colorsFromX:xL y:yT toX:xR y:yB
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5948
            do:[:x :y :clr | self colorAtX:x-xL y:y-yT put:clr ]
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5949
    ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5950
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5951
    (imagesMask := anImage mask) notNil ifTrue:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5952
        imagesMask depth == 1 ifTrue:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5953
            maskClass := ImageMask
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5954
        ] ifFalse:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5955
            maskClass := imagesMask class.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5956
        ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
  5957
        mask := maskClass new fromSubImage:imagesMask inX:xL y:yT width:w height:h
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5958
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  5959
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5960
    "
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  5961
     |i i2 i4 i8 i16 i24|
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5962
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
  5963
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
191
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5964
     i inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5965
     i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5966
     i4 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5967
     i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5968
     i8 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5969
     i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200).
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5970
     i24 inspect.
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5971
    "
a81db32ff94b subimage extraction methods
claus
parents: 178
diff changeset
  5972
2678
e12976d7084b raise a query signal when a loadError happens;
Claus Gittinger <cg@exept.de>
parents: 2645
diff changeset
  5973
    "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
  5974
    "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
  5975
    "Modified: / 18.5.1999 / 20:06:55 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5976
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  5977
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5978
monochromeOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5979
    "return a monochrome device image of the receiver for aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5980
     (monochrome, even if device supports colors)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5981
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5982
    ((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5983
    (device notNil and:[aDevice ~~ device]) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5984
	"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
  5985
	 - need a copy ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5986
	"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  5987
	^ self copy monochromeOn:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5988
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5989
    monoDeviceForm := self asMonochromeFormOn:aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5990
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5991
3105
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5992
nearestOn:aDevice
3107
ed51e2c00f1d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3105
diff changeset
  5993
    "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
  5994
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5995
    ^ self onDevice:aDevice
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5996
!
4fb4dcd2b055 more Color-protocol compatibility
Claus Gittinger <cg@exept.de>
parents: 3104
diff changeset
  5997
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5998
on:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  5999
    "return an image with the same pixels as the receiver, but
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6000
     associated to aDevice. If the receiver is not yet bound to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6001
     a device, this will be the receiver. Otherwise, a new image
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6002
     is returned."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6003
3623
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6004
    "/ send out a warning: #on: is typically used to create views
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6005
    "/ operating on a model.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6006
    "/ Please use #onDevice: to avoid confusion.
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6007
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6008
    <resource:#obsolete>
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6009
16665d9b7263 #on: -> #onDevice
Claus Gittinger <cg@exept.de>
parents: 3613
diff changeset
  6010
    self obsoleteMethodWarning:'use #onDevice:'.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6011
    ^ self onDevice:aDevice
1496
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6012
!
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6013
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6014
onDevice:aDevice
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6015
    "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
  6016
     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
  6017
     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
  6018
     is returned."
fc27b03282af added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
  6019
2980
409e9547a45c ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  6020
    aDevice isNil ifTrue:[^ self].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6021
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6022
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6023
    (device notNil and:[aDevice ~~ device]) ifTrue:[
6493
7785d3d8458b class: Image
Stefan Vogel <sv@exept.de>
parents: 6390
diff changeset
  6024
        "oops, I am already associated to another device
7785d3d8458b class: Image
Stefan Vogel <sv@exept.de>
parents: 6390
diff changeset
  6025
         - need a copy ...
7785d3d8458b class: Image
Stefan Vogel <sv@exept.de>
parents: 6390
diff changeset
  6026
        "
7785d3d8458b class: Image
Stefan Vogel <sv@exept.de>
parents: 6390
diff changeset
  6027
        ^ self copy onDevice:aDevice
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6028
    ].
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6029
    deviceForm := self asFormOn:aDevice.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6030
    device := aDevice.
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6031
    maskedPixelsAre0 := nil.
6496
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6032
    mask notNil ifTrue:[
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6033
        self clearMaskedPixels.
614e100374da class: Image
Stefan Vogel <sv@exept.de>
parents: 6493
diff changeset
  6034
    ].
3477
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6035
    Lobby register:self
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6036
9440bfc0768d on: -> onDevice:
Claus Gittinger <cg@exept.de>
parents: 3476
diff changeset
  6037
    "Modified: / 22.8.1998 / 13:34:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6038
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6039
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6040
!Image methodsFor:'converting greyscale images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6041
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6042
greyImageAsFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6043
    "return a grey-deviceForm from the grey image."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6044
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6045
    |pictureDepth nPlanes|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6046
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6047
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6048
    nPlanes := samplesPerPixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6049
    (nPlanes == 2) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6050
	'Image [info]: alpha plane ignored' infoPrintCR.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  6051
    ].
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  6052
    "/ first plane only
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6053
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6054
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6055
    "monochrome is very easy ..."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6056
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6057
    (pictureDepth == 1) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6058
	^ Form width:width height:height fromArray:self bits onDevice:aDevice
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6059
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6060
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6061
    (aDevice visualType == #TrueColor) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6062
	^ self greyImageAsTrueColorFormOn:aDevice
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6063
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6064
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6065
    "/ PseudoColor conversion also works for StaticColor,
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6066
    "/ GrayScale and DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6067
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6068
    ^ self greyImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6069
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6070
    "Modified: 19.10.1997 / 05:17:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6071
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6072
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6073
greyImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6074
    "return an 8-bit pseudo Form from the grey image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6075
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6076
    |wideBits pictureDepth f map
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6077
     colorMap usedColors nUsed aColor
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6078
     nColors "{ Class: SmallInteger }"
1766
08b918d293a6 fixed conversion of greyScale images with colorCube
Claus Gittinger <cg@exept.de>
parents: 1764
diff changeset
  6079
     range id
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6080
     cube nR nG nB grayColors
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6081
     fit|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6082
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6083
    pictureDepth := bitsPerSample at:1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6084
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6085
    (#(2 4 8) includes:pictureDepth) ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6086
	self error:'currently only depth-2, 4 or 8 supported'.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6087
	^ nil
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6088
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6089
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6090
    wideBits := ByteArray uninitializedNew:(width * height).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6091
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6092
    (pictureDepth == 8) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6093
	"for 8bits, we scan for used colors first;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6094
	 to avoid allocating too many colors"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6095
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6096
	(grayColors := aDevice fixGrayColors) notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6097
	    DitherAlgorithm == #floydSteinberg ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6098
		f := self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6099
		       asFloydSteinbergDitheredDepth8FormOn:aDevice
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6100
		       colors:grayColors
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6101
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6102
	    f notNil ifTrue:[^ f].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6103
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6104
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6105
	(cube := aDevice fixColors) notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6106
	    nR := aDevice numFixRed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6107
	    nG := aDevice numFixGreen.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6108
	    nB := aDevice numFixBlue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6109
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6110
	    DitherAlgorithm == #floydSteinberg ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6111
		f := self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6112
		       asFloydSteinbergDitheredDepth8FormOn:aDevice
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6113
		       colors:cube
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6114
		       nRed:nR
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6115
		       nGreen:nG
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6116
		       nBlue:nB.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6117
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6118
		f := self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6119
		       asNearestPaintDepth8FormOn:aDevice
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6120
		       colors:cube
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6121
		       nRed:nR
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6122
		       nGreen:nG
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6123
		       nBlue:nB.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6124
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6125
	    f notNil ifTrue:[^ f].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6126
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6127
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6128
	usedColors := self bits usedValues.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6129
	nUsed := usedColors max + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6130
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6131
	colorMap := Array new:nUsed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6132
	range := 100 / 255.0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6133
	usedColors do:[:grey |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6134
	    colorMap at:(grey + 1) put:(Color gray:(range * grey))
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6135
	].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6136
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6137
	nColors := (1 bitShift:pictureDepth).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6138
	colorMap := Array new:nColors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6139
	range := 100 / (nColors - 1) asFloat.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6140
	1 to:nColors do:[:i |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6141
	    colorMap at:i put:(Color gray:(i - 1) * range).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6142
	].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6143
    ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6144
    photometric ~~ #blackIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6145
	colorMap reverse
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6146
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6147
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6148
    "allocate those colors & setup the translation map"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6149
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6150
    fit := true.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6151
    map := ByteArray uninitializedNew:256.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6152
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6153
    1 to:nColors do:[:i |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6154
	aColor := colorMap at:i.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6155
	aColor notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6156
	    aColor := aColor onDevice:aDevice.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6157
	    colorMap at:i put:aColor.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6158
	    id := aColor colorId.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6159
	    id isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6160
		id := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6161
		fit := false.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6162
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6163
	    map at:i put:id
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6164
	]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6165
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6166
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6167
    fit ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6168
	"/ here comes the hard part - some grey value
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6169
	"/ could not be allocated.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6170
	"/ Must dither.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6171
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6172
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6173
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6174
    "expand & translate"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6175
    self bits
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6176
	expandPixels:pictureDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6177
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6178
	into:wideBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6179
	mapping:map.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6180
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6181
    f := Form width:width height:height depth:8 onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6182
    f isNil ifTrue:[^ nil].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6183
    f colorMap:colorMap.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6184
    f initGC.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6185
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6186
	drawBits:wideBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6187
	depth:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6188
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6189
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6190
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6191
	into:(f id)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6192
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6193
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6194
	with:(f gcId).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6195
    ^ f
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  6196
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1927
diff changeset
  6197
    "Modified: 19.10.1997 / 05:19:44 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6198
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6199
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6200
greyImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6201
    "return a true-color device-form for the grey-image receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6202
     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
  6203
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6204
    |depth
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6205
     myDepth    "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6206
     nColors    "{ Class: SmallInteger }"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6207
     colorValues
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6208
     scaleDown
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6209
     scaleRed   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6210
     scaleGreen "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6211
     scaleBlue  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6212
     redShift   "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6213
     blueShift  "{ Class: SmallInteger }"
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6214
     greenShift "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6215
     form bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
  6216
     greyValue  "{ Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6217
     h          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6218
     w          "{ Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6219
     pixelArray newPixelArray i|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6220
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6221
    "/ this is a slow fallback method; this ought to be
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6222
    "/ redefined in DepthxImage for more performance.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6223
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6224
    depth := aDevice depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6225
    myDepth := self depth.
5315
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  6226
    myDepth > 16 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6227
	self error:'unsupported depth' mayProceed:true.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6228
	^ nil
5315
cbac968cee6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5314
diff changeset
  6229
    ].
5314
517094dfa71c changed #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5313
diff changeset
  6230
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6231
    "/ compute scale to map from my pixels into devices range
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6232
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6233
    scaleDown := 1 bitShift:myDepth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6234
    scaleRed := (1 bitShift:aDevice bitsRed).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6235
    scaleGreen := (1 bitShift:aDevice bitsGreen).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6236
    scaleBlue := (1 bitShift:aDevice bitsBlue).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6237
    redShift := aDevice shiftRed.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6238
    greenShift := aDevice shiftGreen.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6239
    blueShift := aDevice shiftBlue.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6240
1143
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6241
    "/ prepare the map
6aed722d750d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1139
diff changeset
  6242
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6243
    nColors := (1 bitShift:myDepth).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6244
    colorValues := Array new:nColors.
6256
1e510d7aea8e Inline block variable rename to avoid stc bug
Stefan Vogel <sv@exept.de>
parents: 6166
diff changeset
  6245
    1 to:nColors do:[:colorIdx |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6246
	|v gv bv rv nv|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6247
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6248
	"/ scale down to 0..1
6256
1e510d7aea8e Inline block variable rename to avoid stc bug
Stefan Vogel <sv@exept.de>
parents: 6166
diff changeset
  6249
	v := (colorIdx-1) / scaleDown.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6250
	rv := (v * scaleRed) truncated.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6251
	gv := (v * scaleGreen) truncated.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6252
	bv := (v * scaleBlue) truncated.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6253
	nv := rv bitShift:redShift.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6254
	nv := nv bitOr:(gv bitShift:greenShift).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6255
	nv := nv bitOr:(bv bitShift:blueShift).
6256
1e510d7aea8e Inline block variable rename to avoid stc bug
Stefan Vogel <sv@exept.de>
parents: 6166
diff changeset
  6256
	colorValues at:colorIdx put:nv
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6257
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6258
    photometric == #whiteIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6259
	"/ reverse the order; 0 is brightest
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6260
	colorValues reverse
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6261
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6262
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6263
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6264
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6265
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6266
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6267
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6268
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6269
1668
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  6270
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
95dafe4184d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1667
diff changeset
  6271
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6272
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6273
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6274
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6275
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6276
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6277
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6278
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6279
    w := width - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6280
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6281
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6282
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6283
    0 to:h do:[:y |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6284
	self rowAt:y into:pixelArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6285
	0 to:w do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6286
	    greyValue := pixelArray at:(x+1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6287
	    newPixelArray at:(x+1) put:(colorValues at:greyValue + 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6288
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6289
	i rowAt:y putAll:newPixelArray.
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6290
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6291
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6292
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6293
    form isNil ifTrue:[^ nil].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6294
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6295
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6296
    form
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6297
	copyBitsFrom:imageBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6298
	bitsPerPixel:usedDeviceBitsPerPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6299
	depth:usedDeviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6300
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6301
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6302
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6303
	toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6304
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6305
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6306
5710
9928e8b52195 changed: #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5655
diff changeset
  6307
    "Created: / 20-10-1995 / 22:05:10 / cg"
9928e8b52195 changed: #greyImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5655
diff changeset
  6308
    "Modified: / 05-02-2011 / 10:40:13 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6309
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  6310
48194c26a46c Initial revision
claus
parents:
diff changeset
  6311
!Image methodsFor:'converting palette images'!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6312
48194c26a46c Initial revision
claus
parents:
diff changeset
  6313
paletteImageAsFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6314
    "return a device-form for the palette-image receiver"
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6315
380
c5ffc6d48a9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
  6316
    |type ddepth|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6317
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6318
    ddepth := aDevice depth.
379
d74cdaa0adcb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 306
diff changeset
  6319
3940
b1b7dc76d7d7 not ifTrue -> ifFalse
Claus Gittinger <cg@exept.de>
parents: 3939
diff changeset
  6320
    aDevice hasGrayscales ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6321
	^ self asMonochromeFormOn:aDevice
1623
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  6322
    ].
56c2fd4250c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1611
diff changeset
  6323
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6324
    ((type := aDevice visualType) == #StaticGray) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6325
	ddepth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6326
	    ^ self paletteImageAsGray8FormOn:aDevice
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6327
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6328
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6329
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  6330
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6331
    (type == #TrueColor) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6332
	DitherAlgorithm == #floydSteinberg ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6333
	    ddepth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6334
		self depth == 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6335
		    "/ use fixColor dither algorithm
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6336
		    ^ self asDitheredTrueColor8FormOn:aDevice
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6337
		]
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
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6340
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6341
	^ self paletteImageAsTrueColorFormOn:aDevice
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6342
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6343
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6344
    "/ the PseudoColor conversion also works for
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6345
    "/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6346
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6347
    ^ self paletteImageAsPseudoFormOn:aDevice
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6348
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6349
    "Modified: 14.6.1996 / 19:31:01 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6350
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6351
48194c26a46c Initial revision
claus
parents:
diff changeset
  6352
paletteImageAsPseudoFormOn:aDevice
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
  6353
    "return a pseudo-deviceForm from the palette image."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6354
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6355
    |tempImage d temp8|
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6356
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6357
    d := self depth.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6358
    (#(1 2 4 8) includes:d) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6359
	"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6360
	 fallback code for some depth's:
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6361
	 create a temporary Depth8Image and use its conversion method
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6362
	"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6363
	temp8 := ByteArray uninitializedNew:(width * height).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6364
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6365
	self bits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6366
	    expandPixels:d
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6367
	    width:width height:height
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6368
	    into:temp8
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6369
	    mapping:nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6370
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6371
	tempImage := Image width:width height:height depth:8 fromArray:temp8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6372
	tempImage colorMap:colorMap.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6373
	^ tempImage paletteImageAsPseudoFormOn:aDevice
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  6374
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
  6375
    ^ self subclassResponsibility
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6376
!
48194c26a46c Initial revision
claus
parents:
diff changeset
  6377
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6378
paletteImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6379
    "return a true-color device-form for the palette-image receiver."
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6380
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6381
    |depth
209
900757adba7f more truecolor fixes
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
  6382
     nColors "{ Class: SmallInteger }"
1605
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  6383
     h       "{ Class: SmallInteger }"
64151392ff64 added generic #paletteImageAsTrueColorForm implementation
Claus Gittinger <cg@exept.de>
parents: 1595
diff changeset
  6384
     pixel   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6385
     colorValues
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6386
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6387
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6388
     i pixelArray newPixelArray
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6389
     clr r g b rv gv bv v "{ Class: SmallInteger }" |
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6390
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6391
    "/ this is a slow fallback method; this ought to be
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6392
    "/ redefined in DepthxImage for more performance.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6393
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6394
    depth := aDevice depth.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6395
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6396
    bestFormat := self bestSupportedImageFormatFor:aDevice.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6397
    usedDeviceDepth := bestFormat at:#depth.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6398
    usedDeviceDepth == 1 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6399
	^ self asMonochromeFormOn:aDevice.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6400
    ].
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6401
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6402
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6403
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6404
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6405
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 255.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6406
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 255.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6407
    redShift := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6408
    greenShift := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6409
    blueShift := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6410
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6411
    nColors := colorMap size.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6412
    nColors <= 4096 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6413
	"/ precompute scales to map from 0..100 into devices range
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6414
	"/ (this may be different for the individual components)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6415
	colorValues := Array uninitializedNew:nColors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6416
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6417
	1 to:nColors do:[:index |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6418
	    r := colorMap redByteAt:index.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6419
	    g := colorMap greenByteAt:index.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6420
	    b := colorMap blueByteAt:index.
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6421
"/        clr := colorMap at:index.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6422
	    true "clr notNil" ifTrue:[
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6423
"/            r := clr red.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6424
"/            g := clr green.
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6425
"/            b := clr blue.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6426
		rv := (r * scaleRed) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6427
		gv := (g * scaleGreen) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6428
		bv := (b * scaleBlue) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6429
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6430
		v := rv bitShift:redShift.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6431
		v := v bitOr:(gv bitShift:greenShift).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6432
		v := v bitOr:(bv bitShift:blueShift).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6433
		colorValues at:index put:v.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6434
"/ clr print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6435
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6436
"/ ' -> ' print. v printNL.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6437
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6438
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6439
	].
2864
dd151bfdff9d care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents: 2832
diff changeset
  6440
    ].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6441
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6442
    "/ the temporary helper image is only needed to allow
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6443
    "/ the rowAt:putAll: calls below.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6444
1665
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  6445
    i := (Image implementorForDepth:usedDeviceBitsPerPixel) new.
e0329f98904d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1664
diff changeset
  6446
    i width:width height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6447
    i createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
  6448
    imageBits := i bits.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6449
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6450
    "/ now, walk over the image and replace
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6451
    "/ colorMap indices by color values in the bits array
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6452
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6453
    h := height - 1.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6454
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6455
    newPixelArray := i pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  6456
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6457
    colorValues notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6458
	0 to:h do:[:y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6459
	    self rowAt:y into:pixelArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6460
	    1 to:width do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6461
		pixel := pixelArray at:x.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6462
		newPixelArray at:x put:(colorValues at:pixel + 1 ifAbsent:0).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6463
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6464
	    i rowAt:y putAll:newPixelArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6465
	].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  6466
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6467
	0 to:h do:[:y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6468
	    self rowAt:y into:pixelArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6469
	    1 to:width do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6470
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6471
		pixel := pixelArray at:x.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6472
		clr := self colorFromValue:pixel.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6473
		r := clr redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6474
		g := clr greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6475
		b := clr blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6476
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6477
		rv := (r * scaleRed) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6478
		gv := (g * scaleGreen) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6479
		bv := (b * scaleBlue) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6480
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6481
		v := rv bitShift:redShift.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6482
		v := v bitOr:(gv bitShift:greenShift).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6483
		v := v bitOr:(bv bitShift:blueShift).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6484
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6485
		newPixelArray at:x put:v.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6486
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6487
	    i rowAt:y putAll:newPixelArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6488
	].
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6489
    ].
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6490
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
  6491
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6492
    form isNil ifTrue:[^ nil].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6493
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6494
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6495
    form
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6496
	copyBitsFrom:imageBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6497
	bitsPerPixel:usedDeviceBitsPerPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6498
	depth:usedDeviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6499
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6500
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6501
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6502
	toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6503
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6504
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6505
2185
756d58c52113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2182
diff changeset
  6506
    "Modified: / 24.7.1998 / 00:56:14 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6507
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
  6508
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6509
!Image methodsFor:'converting rgb images'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6510
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6511
asDitheredTrueColor8FormOn:aDevice
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6512
    "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
  6513
     Return the device-form.
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6514
     This method is only valid for trueColor displays."
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6515
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6516
    |fixColors pixel
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6517
     dstIdx     "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6518
     shiftRed   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6519
     shiftGreen "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6520
     shiftBlue  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6521
     nRed    "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6522
     nGreen  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6523
     nBlue   "{ Class: SmallInteger }"|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6524
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6525
    shiftRed := aDevice shiftRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6526
    shiftGreen := aDevice shiftGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6527
    shiftBlue := aDevice shiftBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6528
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6529
    nRed := (1 bitShift:aDevice bitsRed).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6530
    nGreen := (1 bitShift:aDevice bitsGreen).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6531
    nBlue := (1 bitShift:aDevice bitsBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6532
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6533
    fixColors := Array new:(nRed * nGreen * nBlue).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6534
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6535
    dstIdx := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6536
    0 to:nRed - 1 do:[:sR |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6537
	0 to:nGreen - 1 do:[:sG |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6538
	    0 to:nBlue - 1 do:[:sB |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6539
		pixel := (sR bitShift:shiftRed)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6540
			 + (sG bitShift:shiftGreen)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6541
			 + (sB bitShift:shiftBlue).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6542
		fixColors at:dstIdx put:(Color colorId:(pixel)).
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6543
		dstIdx := dstIdx + 1
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6544
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6545
	]
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6546
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6547
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6548
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6549
	asFloydSteinbergDitheredDepth8FormOn:aDevice
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6550
	colors:fixColors
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6551
	nRed:nRed nGreen:nGreen nBlue:nBlue
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6552
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6553
    "Created: 14.6.1996 / 17:23:52 / cg"
1771
ee831cb59127 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1766
diff changeset
  6554
    "Modified: 23.6.1997 / 15:22:36 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6555
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6556
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6557
compressColorMap
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6558
    "calculates a new color map for the image, using only used colors"
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6559
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6560
    |depth newColorMap usedColors oldToNew oldBits newBits tmpBits sortBlockForColors|
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6561
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6562
    depth := self depth.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6563
    usedColors := self realUsedColors.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6564
    sortBlockForColors := [:a :b |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6565
	    a redByte == b redByte ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6566
		a greenByte == b greenByte ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6567
		    a blueByte < b blueByte
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6568
		] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6569
		    a greenByte < b greenByte
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6570
		]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6571
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6572
		a redByte < b redByte
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6573
	    ]
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6574
      ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6575
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6576
    "/ translation table
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6577
    oldToNew := ByteArray new:(1 bitShift:depth).
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6578
    newColorMap := usedColors asArray.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6579
    newColorMap sort:sortBlockForColors.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6580
    self colorMap notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6581
	self colorMap asArray keysAndValuesDo:[:oldIdx :clr |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6582
	    |newPixel|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6583
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6584
	    (usedColors includes:clr) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6585
		newPixel := newColorMap indexOf:clr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6586
		oldToNew at:oldIdx put:newPixel-1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6587
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6588
	].
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6589
    ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6590
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6591
    oldBits := self bits.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6592
    newBits := ByteArray new:(oldBits size).
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6593
    depth ~~ 8 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6594
	"/ expand/compress can only handle 8bits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6595
	tmpBits := ByteArray uninitializedNew:(self width*self height).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6596
	oldBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6597
	    expandPixels:depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6598
	    width:self width
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6599
	    height:self height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6600
	    into:tmpBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6601
	    mapping:oldToNew.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6602
	tmpBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6603
	    compressPixels:depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6604
	    width:self width
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6605
	    height:self height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6606
	    into:newBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6607
	    mapping:nil
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6608
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6609
	oldBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6610
	    expandPixels:depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6611
	    width:self width
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6612
	    height:self height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6613
	    into:newBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6614
	    mapping:oldToNew.
5919
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6615
    ].
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6616
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6617
    self bits:newBits.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6618
    self colorMap:newColorMap.
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6619
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6620
    "Created: / 17-07-2012 / 12:13:18 / anwild"
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6621
!
6312700fedb2 added: #compressColorMap
anwild
parents: 5712
diff changeset
  6622
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6623
rgbImageAsFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6624
    "convert am rgb image to a device-form on aDevice.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6625
     Return the device-form."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6626
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6627
    |visual|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6628
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6629
    visual := aDevice visualType.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6630
    (visual == #StaticGray) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6631
	^ self asGrayFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6632
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6633
    (visual == #TrueColor) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  6634
	^ self rgbImageAsTrueColorFormOn:aDevice
0
48194c26a46c Initial revision
claus
parents:
diff changeset
  6635
    ].
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6636
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6637
    "/ PseudoColor conversion also works for StaticColor, GrayScale
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6638
    "/ and DirectColor displays; although possibly with suboptimal results
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6639
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6640
    ^ self rgbImageAsPseudoFormOn:aDevice
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6641
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  6642
    "Modified: 14.6.1996 / 19:30:06 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6643
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6644
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6645
rgbImageAsPseudoFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6646
    "return a pseudocolor form from the rgb-picture"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6647
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6648
    |n     "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6649
     depth "{ Class: SmallInteger }"
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6650
     palette f|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6651
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6652
    (depth := self depth) <= 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6653
	"/ simulate it via a temporary palette image
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6654
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6655
	palette := Array new:(1 bitShift:depth).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6656
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6657
	n := (1 bitShift:depth)-1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6658
	0 to:n do:[:pixelValue |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6659
	    palette at:(pixelValue+1) put:(self colorFromValue:pixelValue)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6660
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6661
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6662
	self setColorMap:palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6663
	photometric := #palette.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6664
	f := self paletteImageAsPseudoFormOn:aDevice.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6665
	self setColorMap:nil.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6666
	photometric := #rgb.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6667
	^ f
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6668
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6669
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6670
    ^ self subclassResponsibility
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6671
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
  6672
    "Modified: 8.6.1996 / 10:58:25 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6673
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6674
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6675
rgbImageAsTrueColorFormOn:aDevice
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6676
    "return a truecolor form from the rgb-picture."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6677
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6678
    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6679
     form|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6680
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6681
    bestFormat := self bestSupportedImageFormatFor:aDevice.
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6682
    usedDeviceDepth := bestFormat at:#depth.
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
  6683
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6684
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  6685
    "/ 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
  6686
    usedDeviceBitsPerPixel == 15 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6687
	usedDeviceBitsPerPixel := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  6688
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
  6689
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6690
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6691
    "/ only the trivial case, where the depths match
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6692
    "/ is handled here; conversions are supposed to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6693
    "/ be done in concrete subclasses (see D24Image)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6694
    "/
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6695
    self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6696
	"/ kludge - convert to a deep image first, then to a form.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6697
	^ ((Image implementorForDepth:usedDeviceBitsPerPixel) fromImage:self) asFormOn:aDevice
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
  6698
"/        '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
  6699
"/        ^ self asMonochromeFormOn:aDevice
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6700
    ].
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6701
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6702
    form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6703
    form isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6704
	'Image [warning]: display bitmap creation failed' errorPrintCR.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6705
	^ nil
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6706
    ].
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6707
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6708
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6709
    form
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6710
	copyBitsFrom:self bits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6711
	bitsPerPixel:usedDeviceBitsPerPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6712
	depth:usedDeviceDepth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6713
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6714
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6715
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6716
	toX:0 y:0.
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6717
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6718
    ^ form
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
  6719
4757
60d27f8e65bb some fixes for depth32
Claus Gittinger <cg@exept.de>
parents: 4745
diff changeset
  6720
    "Modified: / 27-05-2007 / 13:44:26 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6721
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6722
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6723
!Image methodsFor:'copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6724
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6725
postCopy
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6726
    "redefined to also copy the pixels and the colorMap
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6727
     and clear out any device handles in the copy."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
  6728
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6729
    bytes := bytes copy.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6730
    (colorMap isNil or:[colorMap isKindOf:Colormap]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6731
	colorMap := MappedPalette withColors:colorMap.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6732
    ] ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6733
	colorMap := colorMap copy.
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
  6734
    ].
1963
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6735
    device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil.
ab2d96e4e140 care for masks in copy/copySubImage;
tz
parents: 1962
diff changeset
  6736
    mask := mask copy.
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6737
    maskedPixelsAre0 := false.
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6738
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
  6739
    "Modified: / 22.8.1998 / 11:27:09 / cg"
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6740
!
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6741
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6742
skipInstvarIndexInDeepCopy:index
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6743
    "a helper for deepCopy; only indices for which this method returns
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6744
     false are copied in a deep copy."
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6745
5956
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6746
    index == 17 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6747
	^ true "/ skip device
5956
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6748
    ].
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6749
    index == 18 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6750
	^ true "/ skip deviceForm
5956
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6751
    ].
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6752
    index == 19 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6753
	^ true "/ skip monoDeviceForm
5956
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6754
    ].
c46b8003e817 class: Image
Stefan Vogel <sv@exept.de>
parents: 5926
diff changeset
  6755
    index == 20 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6756
	^ true "/ skip fullColorDeviceForm
2947
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6757
    ].
53f0ea77b1e4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
  6758
    ^ false
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6759
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6760
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6761
!Image methodsFor:'displaying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6762
1737
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6763
asImage
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6764
    "ST-80 compatibility
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6765
    "
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6766
    ^ self
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6767
!
30e65b9fee9c ST-80 compatibility
ca
parents: 1733
diff changeset
  6768
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6769
displayFilledOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6770
    "display the receiver as an opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6771
     This allows Images to be wrapped by a FillingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6772
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6773
    aGC displayOpaqueForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6774
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6775
    "Created: 29.5.1996 / 10:34:18 / cg"
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6776
    "Modified: 29.5.1996 / 10:52:36 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6777
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6778
3865
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6779
displayOn:aGC x:x y:y
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6780
    "draw the receiver in the graphicsContext, aGC.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6781
     Smalltalk-80 compatibility"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6782
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6783
    aGC displayForm:self x:x y:y.
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6784
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6785
    "Modified: 23.4.1996 / 11:12:31 / cg"
18532e89cdca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  6786
    "Created: 12.5.1996 / 20:14:31 / cg"
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6787
!
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6788
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6789
displayOn:aGC x:x y:y opaque:opaque
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6790
    "draw the receiver in the graphicsContext, aGC.
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6791
     Smalltalk-80 compatibility"
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6792
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6793
    opaque ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6794
	self displayOpaqueOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6795
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  6796
	self displayOn:aGC x:x y:y .
3729
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6797
    ].
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6798
!
d2cd7d8585a3 *** empty log message ***
penk
parents: 3700
diff changeset
  6799
3379
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6800
displayOpaqueOn:aGC at:aPoint
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6801
    "draw the receiver in the graphicsContext, aGC.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6802
     Smalltalk-80 compatibility"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6803
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6804
    self displayOpaqueOn:aGC x:aPoint x y:aPoint y.
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6805
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6806
    "Modified: 12.5.1996 / 20:16:38 / cg"
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6807
!
0d1d05ddad7c added displayOpaque
martin
parents: 3363
diff changeset
  6808
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6809
displayOpaqueOn:aGC x:x y:y
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6810
    "draw the receiver in the graphicsContext, aGC.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6811
     Smalltalk-80 compatibility"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6812
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6813
    aGC displayOpaqueForm:self x:x y:y.
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6814
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6815
    "Modified: 23.4.1996 / 11:12:31 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6816
    "Created: 22.10.1996 / 16:35:49 / cg"
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6817
!
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
  6818
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6819
displayStrokedOn:aGC
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6820
    "display the receiver as an non opaque image.
758
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6821
     This allows Images to be wrapped by a StrokingWrapper"
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6822
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6823
    aGC displayForm:self x:0 y:0.
51ac65155b96 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
  6824
759
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6825
    "Created: 29.5.1996 / 10:34:18 / cg"
52f5ceda5347 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 758
diff changeset
  6826
    "Modified: 29.5.1996 / 10:52:30 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6827
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  6828
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6829
!Image methodsFor:'dither helpers'!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6830
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6831
burkesDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6832
    "return the bitmap for a dithered monochrome bitmap from the image.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6833
     Works for any source depths / photometric.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6834
     TODO: move to separate dither helper class"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6835
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6836
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6837
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6838
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6839
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6840
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6841
     errorArray1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6842
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6843
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6844
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6845
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6846
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  6847
     grey|
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6848
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6849
    self depth > 12 ifTrue:[
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6850
        ^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6851
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6852
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6853
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6854
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6855
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6856
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6857
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6858
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6859
    errorArray := Array new:(w+4).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6860
    errorArray1 := Array new:(w+4) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6861
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6862
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6863
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6864
    "/ 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
  6865
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6866
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6867
    greyValues := self greyMapForRange:(255*1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6868
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6869
    0 to:(h-1) do:[:y |
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6870
        nextDst := dstIndex + bytesPerMonoRow.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6871
        byte := 0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6872
        bitCnt := 8.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6873
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6874
        t := errorArray.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6875
        errorArray := errorArray1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6876
        errorArray1 := t.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6877
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6878
        errorArray1 atAllPut:0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6879
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6880
        self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6881
            |eP "{Class: SmallInteger }"
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6882
             eD
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6883
             eI "{Class: SmallInteger }"
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6884
             xE "{Class: SmallInteger }"
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6885
             xN "{Class: SmallInteger }" |
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6886
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6887
            "/ get the colors grey value [0 .. 1]
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6888
            grey := greyValues at:(pixel + 1).
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6889
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6890
            "/ adjust error
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6891
            xE := x + 2 + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6892
            grey := (grey + (errorArray at:xE)).
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6893
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6894
            byte := byte bitShift:1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6895
            grey > (127*1024) ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6896
                byte := byte bitOr:1.      "/ white
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6897
                e := grey - (255*1024)
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6898
            ] ifFalse:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6899
                e := grey                  "/ black
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6900
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6901
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6902
            e ~= 0 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6903
                "/ distribute the error:
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6904
                "/                  XX  8  4
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6905
                "/             2  4  8  4  2
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6906
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6907
                eD := e.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6908
                eI := e // 32.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6909
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6910
                eP := eI * 8. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6911
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6912
                xN := xE + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6913
                errorArray at:xN put:(errorArray at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6914
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6915
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6916
                errorArray1 at:xE put:(errorArray1 at:xE) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6917
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6918
                eP := eI * 4. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6919
                xN := xE + 2.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6920
                errorArray at:xN put:(errorArray at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6921
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6922
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6923
                xN := xE - 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6924
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6925
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6926
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6927
                xN := xE + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6928
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6929
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6930
                eP := eI * 2. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6931
                xN := xE - 2.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6932
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6933
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6934
                "/ eD := eD.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6935
                xN := xE + 2.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6936
                errorArray1 at:xN put:(errorArray1 at:xN) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6937
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6938
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6939
            bitCnt := bitCnt - 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6940
            bitCnt == 0 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6941
                monoBits at:dstIndex put:byte.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6942
                dstIndex := dstIndex + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6943
                byte := 0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6944
                bitCnt := 8.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6945
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6946
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6947
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6948
        bitCnt ~~ 8 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6949
            byte := byte bitShift:bitCnt.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6950
            monoBits at:dstIndex put:byte.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6951
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6952
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  6953
        dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6954
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6955
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6956
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6957
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6958
    "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
  6959
    "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
  6960
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  6961
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6962
floydSteinbergDitheredDepth8BitsColors:colors
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6963
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6964
     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
  6965
     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
  6966
     (which need not be a colorCubes colors)."
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  6967
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6968
    ^ self floydSteinbergDitheredDepth8BitsColors:colors map:nil
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6969
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6970
!
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6971
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6972
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6973
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6974
     which must be a depth-24 image.
3157
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6975
     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
  6976
     (which need not be a colorCubes colors)."
f95dc03365da added some dither helpers
Claus Gittinger <cg@exept.de>
parents: 3145
diff changeset
  6977
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  6978
    |pseudoBits
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6979
     ditherRGBBytes ditherColors
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6980
     w       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6981
     h       "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6982
     index   "{Class: SmallInteger }"
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6983
     ditherIds failed lastColor qScramble
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6984
     clrLookup lookupPos
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6985
     error clr|
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6986
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6987
    self depth ~~ 24 ifTrue:[^ nil].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6988
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6989
    "/ collect valid ditherColors ...
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6990
    aMapOrNil isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6991
	ditherColors := colors select:[:clr | clr notNil].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6992
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6993
	ditherColors := colors
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6994
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6995
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6996
    "/ ... and sort by manhatten distance from black
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6997
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  6998
    qScramble := #(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  6999
		"/  2rX00X00X00X00
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7001
		    2r000000000000    "/ 0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7002
		    2r000000000100    "/ 1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7003
		    2r000000100000    "/ 2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7004
		    2r000000100100    "/ 3
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7005
		    2r000100000000    "/ 4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7006
		    2r000100000100    "/ 5
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7007
		    2r000100100000    "/ 6
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7008
		    2r000100100100    "/ 7
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7009
		    2r100000000000    "/ 8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7010
		    2r100000000100    "/ 9
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7011
		    2r100000100000    "/ a
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7012
		    2r100000100100    "/ b
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7013
		    2r100100000000    "/ c
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7014
		    2r100100000100    "/ d
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7015
		    2r100100100000    "/ e
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7016
		    2r100100100100    "/ f
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7017
		  ).
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7018
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7019
    ditherColors := ditherColors sort:[:a :b |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7020
				|cr "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7021
				 cg "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7022
				 cb "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7023
				 i1 "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7024
				 i2 "{Class: SmallInteger }"|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7025
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7026
				cr := a redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7027
				cg := a greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7028
				cb := a blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7029
				i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7030
				i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7031
				i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7032
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7033
				cr := b redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7034
				cg := b greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7035
				cb := b blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7036
				i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7037
				i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7038
				i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7039
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7040
				i1 < i2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7041
		    ].
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7042
    aMapOrNil isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7043
	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
  7044
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7045
	ditherIds := aMapOrNil asByteArray
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7046
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7047
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7048
    "/ 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
  7049
    "/ to the position in the colorList
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7050
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7051
    clrLookup := ByteArray new:(4096).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7052
    index := 0.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7053
    ditherColors keysAndValuesDo:[:clrPosition :clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7054
	|r g b i|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7055
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7056
	r := clr redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7057
	g := clr greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7058
	b := clr blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7059
	i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7060
	i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7061
	i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7062
	lookupPos := i.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7063
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7064
	[index < lookupPos] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7065
	    clrLookup at:(index+1) put:(clrPosition-1-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7066
	    index := index + 1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7067
	]
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7068
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7069
    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
  7070
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7071
"/    [index <= (4095)] whileTrue:[
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7072
"/        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
  7073
"/        index := index + 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7074
"/    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7075
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7076
    "/ collect ditherColor components
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7077
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7078
    lastColor := ditherColors size.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7079
    ditherIds := ByteArray uninitializedNew:lastColor.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7080
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7081
    index := 1.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7082
    1 to:lastColor do:[:pix |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7083
	clr := ditherColors at:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7084
	ditherRGBBytes at:index put:(clr redByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7085
	ditherRGBBytes at:index+1 put:(clr greenByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7086
	ditherRGBBytes at:index+2 put:(clr blueByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7087
	aMapOrNil isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7088
	    ditherIds at:pix put:clr colorId.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7089
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7090
	    ditherIds at:pix put:(aMapOrNil at:pix).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7091
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7092
	index := index + 3.
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7093
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7094
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7095
    pseudoBits := ByteArray uninitializedNew:(width * height).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7096
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7097
    w := width + 2.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7098
    error := ByteArray uninitializedNew:w*(3*2).
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7099
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7100
    w := width.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7101
    h := height.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7102
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7103
    failed := true.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7104
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7105
%{
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7106
    int __x, __y;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7107
    int __eR, __eG, __eB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7108
    unsigned char *srcP, *dstP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7109
    unsigned char *idP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7110
    unsigned char *dp;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7111
    unsigned char *__clrLookup;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7112
    short *errP, *eP;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7113
    int __fR, __fG, __fB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7114
    int iR, iG, iB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7115
    int idx;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7116
    int __w = __intVal(w);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7117
    int __h = __intVal(h);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7118
    int __nColors = __intVal(lastColor);
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7119
    int __wR = -1, __wG, __wB;
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7120
    static int __qScramble[16] = {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7121
		    0x000 /* 2r000000000000    0 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7122
		    0x004 /* 2r000000000100    1 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7123
		    0x020 /* 2r000000100000    2 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7124
		    0x024 /* 2r000000100100    3 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7125
		    0x100 /* 2r000100000000    4 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7126
		    0x104 /* 2r000100000100    5 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7127
		    0x120 /* 2r000100100000    6 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7128
		    0x124 /* 2r000100100100    7 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7129
		    0x800 /* 2r100000000000    8 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7130
		    0x804 /* 2r100000000100    9 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7131
		    0x820 /* 2r100000100000    a */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7132
		    0x824 /* 2r100000100100    b */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7133
		    0x900 /* 2r100100000000    c */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7134
		    0x904 /* 2r100100000100    d */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7135
		    0x920 /* 2r100100100000    e */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7136
		    0x924 /* 2r100100100100    f */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7137
		  };
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7138
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7139
    if (__isByteArrayLike(__INST(bytes))
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7140
     && __isByteArray(pseudoBits)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7141
     && __isByteArray(ditherRGBBytes)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7142
     && __isByteArray(ditherIds)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7143
     && __isByteArray(clrLookup)
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7144
     && __isByteArray(error)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7145
	failed = false;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7146
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7147
	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7148
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7149
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7150
	__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7151
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7152
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7153
	/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7154
	 * clear error accumulator
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7155
	 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7156
	eP = errP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7157
	bzero(eP, (__w+2) * 2 * 3);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7158
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7159
	for (__y=__h; __y>0; __y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7160
	    __eR = __eG = __eB = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7161
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7162
	    eP = &(errP[3]);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7163
	    __eR = eP[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7164
	    __eG = eP[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7165
	    __eB = eP[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7166
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7167
	    for (__x=__w; __x>0; __x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7168
		int __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7169
		int pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7170
		int __wantR, __wantG, __wantB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7171
		int idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7172
		int tR, tG, tB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7173
		int nR, nG, nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7174
		int dR, dG, dB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7175
		int minDelta, bestIdx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7176
		int cnt;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7177
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7178
		__wantR = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7179
		__wantG = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7180
		__wantB = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7181
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7182
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7183
		 * wR, wG and wB is the wanted r/g/b value;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7184
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7185
		__wantR = __wantR + __eR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7186
		__wantG = __wantG + __eG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7187
		__wantB = __wantB + __eB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7188
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7189
#define RED_SCALE 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7190
#define GREEN_SCALE 59
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7191
#define BLUE_SCALE 11
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7192
#define GOOD_DELTA 30
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7193
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7194
#define xRED_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7195
#define xGREEN_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7196
#define xBLUE_SCALE 1
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7197
#define xGOOD_DELTA 3
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7198
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7199
#define FAST_LOOKUP
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7200
/* #define ONE_SHOT */
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7201
#define NPROBE 8
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7202
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7203
#ifndef FAST_LOOKUP
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7204
		if ((__wantR == __wR)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7205
		 && (__wantG == __wG)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7206
		 && (__wantB == __wB)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7207
		    /*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7208
		     * same color again - reuse last bestMatch
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7209
		     */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7210
		} else
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7211
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7212
		{
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7213
		    __wR = __wantR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7214
		    __wG = __wantG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7215
		    __wB = __wantB;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7216
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7217
#ifdef FAST_LOOKUP
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7218
		    if(__wR > 255) __wR = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7219
		    else if (__wR < 0) __wR = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7220
		    if(__wG > 255) __wG = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7221
		    else if (__wG < 0) __wG = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7222
		    if(__wB > 255) __wB = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7223
		    else if (__wB < 0) __wB = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7224
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7225
		    {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7226
			int lookupIndex;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7227
			int idx, idx0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7228
			int d, delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7229
			unsigned char *dp0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7230
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7231
			dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7232
			lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7233
			lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7234
			lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7235
			idx = bestIdx =__clrLookup[lookupIndex];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7236
			dp += (idx+idx+idx);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7237
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7238
			/* try color at lookupIndex */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7239
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7240
			d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7241
			delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7242
			if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7243
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7244
			d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7245
			if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7246
			    delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7247
			else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7248
			    delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7249
			d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7250
			if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7251
			    delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7252
			else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7253
			    delta += (d - __wB) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7254
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7255
			if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7256
			    goto foundBest;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7257
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7258
			minDelta = delta;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7259
# ifndef ONE_SHOT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7260
			idx0 = idx; dp0 = dp;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7261
			cnt = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7262
			while ((++cnt <= NPROBE) && (idx > 0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7263
			    /* try previous color(s) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7264
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7265
			    idx--; dp -= 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7266
			    d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7267
			    delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7268
			    if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7269
			    d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7270
			    if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7271
				delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7272
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7273
				delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7274
			    d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7275
			    if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7276
				delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7277
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7278
				delta += (d - __wB) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7279
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7280
			    if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7281
				bestIdx = idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7282
				if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7283
				    goto foundBest;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7284
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7285
				minDelta = delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7286
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7287
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7288
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7289
			idx = idx0; dp = dp0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7290
			cnt = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7291
			while ((++cnt <= NPROBE) && (++idx < __nColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7292
			    /* try next color */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7293
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7294
			    dp += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7295
			    d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7296
			    delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7297
			    if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7298
			    d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7299
			    if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7300
				delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7301
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7302
				delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7303
			    d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7304
			    if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7305
				delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7306
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7307
				delta += (d - __wB) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7308
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7309
			    if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7310
				bestIdx = idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7311
				if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7312
				    goto foundBest;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7313
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7314
				minDelta = delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7315
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7316
			}
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7317
# endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7318
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7319
	foundBest: ;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7320
#else
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7321
/*
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7322
		    if(__wR > 255) __wR = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7323
		    else if (__wR < 0) __wR = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7324
		    if(__wG > 255) __wG = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7325
		    else if (__wG < 0) __wG = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7326
		    if(__wB > 255) __wB = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7327
		    else if (__wB < 0) __wB = 0;
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7328
*/
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7329
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7330
		    /* find the best matching color */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7331
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7332
		    minDelta = 99999;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7333
		    bestIdx = -1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7334
		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7335
		    for (idx = 0; idx<__nColors; idx++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7336
			int d, delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7337
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7338
			d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7339
			delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7340
			if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7341
			if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7342
			    d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7343
			    if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7344
				delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7345
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7346
				delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7347
			    if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7348
				d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7349
				if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7350
				    delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7351
				else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7352
				    delta += (d - __wB) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7353
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7354
				if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7355
				    bestIdx = idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7356
				    if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7357
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7358
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7359
				    minDelta = delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7360
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7361
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7362
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7363
			dp += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7364
		    }
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7365
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7366
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7367
		dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7368
		dp += bestIdx * 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7369
		dR = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7370
		dG = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7371
		dB = dp[2];
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7372
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7373
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  7374
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7375
		__wantR, __wantG, __wantB,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7376
		__wR, __wG, __wB,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7377
		dR, dG, dB);
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7378
*/
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7379
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7380
		 * store the corresponding dither colors colorId
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7381
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7382
		*dstP++ = idP[bestIdx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7383
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7384
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7385
		 * the new error & distribute the error
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7386
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7387
		__eR = __wantR - dR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7388
		if (__eR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7389
		    tR = __eR >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7390
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7391
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7392
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7393
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7394
		    __eR = nR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7395
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7396
		    __eR = eP[3];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7397
		    eP[0] = eP[-3] = eP[3] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7398
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7399
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7400
		__eG = __wantG - dG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7401
		if (__eG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7402
		    tG = __eG >> 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7403
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7404
		    eP[1] = tG*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7405
		    eP[-2] = tG*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7406
		    eP[4] = __eG - (tG*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7407
		    __eG = nG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7408
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7409
		    __eG = eP[4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7410
		    eP[1] = eP[-2] = eP[4] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7411
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7412
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7413
		__eB = __wantB - dB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7414
		if (__eB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7415
		    tB = __eB >> 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7416
		    nB = eP[5] + (tB * 7);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7417
		    eP[2] = tB*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7418
		    eP[-1] = tB*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7419
		    eP[5] = __eB - (tB*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7420
		    __eB = nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7421
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7422
		    __eB = eP[5];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7423
		    eP[2] = eP[-1] = eP[5] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7424
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7425
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7426
		eP += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7427
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7428
	}
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7429
    }
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7430
%}.
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7431
    failed ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7432
	self primitiveFailed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7433
	^ nil
3908
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7434
    ].
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7435
d39322d668f6 oops - asDitheredImage must return a depth8 image
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  7436
    ^ pseudoBits
874
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7437
!
cce9c1029d38 added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
  7438
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7439
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7440
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7441
     which must be a depth-8 image.
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7442
     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
  7443
     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
  7444
     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
  7445
     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
  7446
     Color class.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7447
     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
  7448
     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
  7449
     for example to create dithered Depth4Images from Depth8Images."
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7450
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7451
    |pseudoBits
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7452
     rgbBytes
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7453
     w       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7454
     h       "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7455
     index   "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7456
     fixR    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7457
     fixG    "{Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7458
     fixB    "{Class: SmallInteger }"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7459
     fixGfixB
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7460
     fixIds failed map lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7461
     rgbIDX  "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7462
     idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7463
     error clr|
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7464
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7465
    self depth ~~ 8 ifTrue:[^ nil].
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 854
diff changeset
  7466
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7467
    fixR := nRed.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7468
    fixR == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7469
    fixG := nGreen.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7470
    fixG == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7471
    fixB := nBlue.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7472
    fixB == 0 ifTrue:[ ^ nil].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7473
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7474
    "/ simple check
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7475
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7476
	self error:'invalid color array passed'.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7477
	^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7478
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7479
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7480
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7481
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7482
    "/ collect color components as integer values (for integer arithmetic)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7483
    "/
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7484
    rgbBytes := ByteArray uninitializedNew:256 * 3.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7485
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7486
    index := 1.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7487
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7488
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7489
	lastColor := colorMap size - 1
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7490
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7491
	lastColor := 255.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7492
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7493
    0 to:lastColor do:[:pix |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7494
	clr := self colorFromValue:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7495
	rgbBytes at:index put:(clr redByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7496
	rgbBytes at:index+1 put:(clr greenByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7497
	rgbBytes at:index+2 put:(clr blueByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7498
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7499
	index := index + 3.
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7500
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7501
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7502
    pseudoBits := ByteArray uninitializedNew:(width * height).
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7503
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7504
    w := width + 2.
1636
c30f6644666e dont use bcopy in #floydSteinbergDitheredDepth8BitsColors
Claus Gittinger <cg@exept.de>
parents: 1630
diff changeset
  7505
    error := ByteArray new:w*(3*2).
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7506
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7507
    w := width.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7508
    h := height.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7509
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7510
    idxAndErrRBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7511
    idxAndErrGBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7512
    idxAndErrBBytes := ByteArray uninitializedNew:256*2.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7513
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7514
    fixGfixB := fixG * fixB.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7515
    index := 1.
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7516
    0 to:255 do:[:i |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7517
	rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7518
	idxAndErrRBytes at:index put:(rgbIDX * fixGfixB).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7519
	idxAndErrRBytes at:index+1 put:i - (rgbIDX * 255 // (fixR-1)) + 128.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7520
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7521
	rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7522
	idxAndErrGBytes at:index put:(rgbIDX * fixB).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7523
	idxAndErrGBytes at:index+1 put:i - (rgbIDX * 255 // (fixG-1)) + 128.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7524
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7525
	rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7526
	idxAndErrBBytes at:index put:(rgbIDX ).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7527
	idxAndErrBBytes at:index+1 put:i - (rgbIDX * 255 // (fixB-1)) + 128.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7528
	index := index + 2.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7529
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7530
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7531
    failed := true.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7532
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7533
%{
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7534
    int __x, __y;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7535
    int __eR, __eG, __eB;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7536
    unsigned char *srcP, *dstP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7537
    unsigned char *rgbP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7538
    unsigned char *idP;
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  7539
    unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes;
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7540
    short *errP, *eP;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7541
    int idx;
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7542
    int __w = __intVal(w);
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7543
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  7544
    if (__isByteArrayLike(__INST(bytes))
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7545
     && __isByteArray(pseudoBits)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7546
     && __isByteArray(rgbBytes)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7547
     && __isByteArray(fixIds)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7548
     && __isByteArray(error)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7549
     && __bothSmallInteger(fixR, fixG)
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7550
     && __isSmallInteger(fixB)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7551
	failed = false;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7552
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7553
	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7554
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7555
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7556
	idP = __ByteArrayInstPtr(fixIds)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7557
	__idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7558
	__idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7559
	__idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7560
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7561
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7562
	eP = errP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7563
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7564
	for (__y=__intVal(h); __y>0; __y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7565
	    __eR = __eG = __eB = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7566
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7567
	    eP = &(errP[3]);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7568
	    __eR = eP[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7569
	    __eG = eP[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7570
	    __eB = eP[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7571
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7572
	    for (__x=__w; __x>0; __x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7573
		int __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7574
		int pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7575
		int idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7576
		int tR, tG, tB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7577
		int nR, nG, nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7578
		int iRGB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7579
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7580
		pix = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7581
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7582
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7583
		 * wR, wG and wB is the wanted r/g/b value;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7584
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7585
		pix = pix+pix+pix;  /* pix * 3 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7586
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7587
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7588
		 * compute indexR/G/B and the new error:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7589
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7590
		__want = rgbP[pix]   + __eR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7591
		if (__want > 255) __want = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7592
		else if (__want < 0) __want = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7593
		__want += __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7594
		idx = __idxAndErrRBytes[__want];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7595
		__eR = __idxAndErrRBytes[__want+1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7596
		__eR -= 128;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7597
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7598
		__want = rgbP[pix+1] + __eG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7599
		if (__want > 255) __want = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7600
		else if (__want < 0) __want = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7601
		__want += __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7602
		idx += __idxAndErrGBytes[__want];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7603
		__eG = __idxAndErrGBytes[__want+1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7604
		__eG -= 128;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7605
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7606
		__want = rgbP[pix+2] + __eB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7607
		if (__want > 255) __want = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7608
		else if (__want < 0) __want = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7609
		__want += __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7610
		idx += __idxAndErrBBytes[__want];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7611
		__eB = __idxAndErrBBytes[__want+1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7612
		__eB -= 128;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7613
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7614
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7615
		 * store the corresponding dither colors colorId
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7616
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7617
		*dstP++ = idP[idx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7618
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7619
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7620
		 * distribute the error
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7621
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7622
		if (__eR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7623
		    tR = __eR >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7624
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7625
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7626
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7627
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7628
		    __eR = nR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7629
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7630
		    __eR = eP[3];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7631
		    eP[0] = eP[-3] = eP[3] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7632
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7633
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7634
		if (__eG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7635
		    tG = __eG >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7636
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7637
		    eP[1] = tG*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7638
		    eP[-2] = tG*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7639
		    eP[4] = __eG - (tG*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7640
		    __eG = nG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7641
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7642
		    __eG = eP[4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7643
		    eP[1] = eP[-2] = eP[4] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7644
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7645
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7646
		if (__eB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7647
		    tB = __eB >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7648
		    nB = eP[5] + (tB * 7);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7649
		    eP[2] = tB*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7650
		    eP[-1] = tB*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7651
		    eP[5] = __eB - (tB*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7652
		    __eB = nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7653
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7654
		    __eB = eP[5];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7655
		    eP[2] = eP[-1] = eP[5] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7656
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7657
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7658
		eP += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7659
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7660
	}
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7661
    }
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7662
%}.
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7663
    failed ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7664
	self primitiveFailed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  7665
	^ nil
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7666
    ].
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7667
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7668
    ^ pseudoBits
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7669
!
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
  7670
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7671
floydSteinbergDitheredGrayBitsDepth:depth
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7672
    "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
  7673
     Works for any source depths / photometric,
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7674
     but possibly slow since each pixel is processed individually.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7675
     Redefined by some subclasses for more performance (D8Image/D24Image)"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7676
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7677
    |dstIndex        "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7678
     nextDst         "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7679
     bytesPerOutRow  "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7680
     outBits greyValues greyErrors greyPixels greyLevels
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7681
     errorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7682
     nextErrorArray
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7683
     t
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7684
     w               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7685
     h               "{Class: SmallInteger }"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7686
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7687
     byte            "{Class: SmallInteger }"
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7688
     grey
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7689
     eR eRB eB eLB |
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7690
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7691
    depth > 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7692
	self error:'unimplemented conversion'.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7693
	^ nil
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7694
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7695
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7696
    w := width.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7697
    h := height.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7698
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7699
    bytesPerOutRow := ((w * depth) + 7) // 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7700
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7701
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7702
    greyLevels := (1 bitShift:depth) - 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7703
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7704
    errorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7705
    nextErrorArray := Array new:w+2.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7706
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7707
    nextErrorArray atAllPut:0.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7708
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7709
    dstIndex := 1.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7710
    bitCnt := 8.
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7711
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7712
    self depth <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7713
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7714
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7715
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7716
	greyValues := self greyMapForRange:(greyLevels).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7717
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7718
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7719
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7720
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7721
						   v truncated]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7722
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7723
	greyPixels := ByteArray withAll:greyPixels.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7724
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7725
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7726
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7727
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7728
						   ((v - v truncated) * 1024) truncated
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7729
					       ]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7730
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7731
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7732
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7733
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7734
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7735
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7736
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7737
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7738
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7739
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7740
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7741
	    self valuesAtY:y from:0 to:(w-1) do:[:x :value |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7742
		|e     "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7743
		 pixel "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7744
		 error "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7745
		 e16   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7746
		 xE    "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7747
		 xN    "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7748
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7749
		pixel := greyPixels at:(value + 1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7750
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7751
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7752
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7753
		error := (greyErrors at:(value + 1)) + (errorArray at:xE).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7754
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7755
		byte := byte bitShift:depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7756
		error > 512 "0.5" ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7757
		    pixel := pixel + 1.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7758
		    e := error - 1024 "1.0"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7759
		] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7760
		    e := error
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7761
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7762
		byte := byte bitOr:pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7763
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7764
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7765
		    e16 := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7766
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7767
		    eR  := e16 * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7768
		    eRB := e16 * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7769
		    eB  := e16 * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7770
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7771
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7772
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7773
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7774
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7775
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7776
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7777
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7778
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7779
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7780
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7781
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7782
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7783
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7784
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7785
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7786
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7787
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7788
		bitCnt := bitCnt - depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7789
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7790
		    outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7791
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7792
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7793
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7794
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7795
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7796
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7797
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7798
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7799
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7800
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7801
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7802
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7803
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7804
	].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7805
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7806
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7807
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7808
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7809
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7810
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7811
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7812
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7813
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7814
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7815
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7816
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7817
		|e     "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7818
		 pixel "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7819
		 error "{ Class: SmallInteger }"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7820
		 e16   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7821
		 xE    "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7822
		 xN    "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7823
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7824
		grey := (clr brightness * greyLevels).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7825
		pixel := grey truncated.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7826
		error := ((grey - pixel) * 1024) truncated.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7827
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7828
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7829
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7830
		error := error + (errorArray at:xE).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7831
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7832
		byte := byte bitShift:depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7833
		error > 512 "0.5" ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7834
		    pixel := pixel + 1.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7835
		    e := error - 1024 "1.0"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7836
		] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7837
		    e := error
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7838
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7839
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7840
		byte := byte bitOr:pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7841
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7842
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7843
		    e16 := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7844
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7845
		    eR  := e16 * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7846
		    eRB := e16 * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7847
		    eB  := e16 * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7848
		    eLB := e - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7849
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7850
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7851
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7852
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7853
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7854
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7855
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7856
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7857
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7858
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7859
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7860
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7861
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7862
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7863
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7864
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7865
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7866
		bitCnt := bitCnt - depth.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7867
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7868
		    outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7869
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7870
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7871
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7872
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7873
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7874
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7875
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7876
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7877
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7878
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7879
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7880
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7881
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7882
	].
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7883
    ].
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7884
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7885
    ^ outBits
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7886
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7887
    "Created: 10.6.1996 / 13:28:22 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7888
    "Modified: 11.6.1996 / 00:13:38 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7889
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  7890
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7891
floydSteinbergDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7892
    "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
  7893
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7894
     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
  7895
     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
  7896
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7897
    |dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7898
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7899
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7900
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7901
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7902
     nextErrorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7903
     e eD t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7904
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7905
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7906
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7907
     byte            "{Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7908
     grey
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7909
     eR eRB eB eLB |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7910
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7911
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7912
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7913
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7914
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7915
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7916
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7917
    errorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7918
    nextErrorArray := Array new:w+2.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7919
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7920
    nextErrorArray atAllPut:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7921
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7922
    dstIndex := 1.
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7923
    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7924
    byte := 0.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7925
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  7926
    self depth <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7927
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7928
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7929
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7930
	greyValues := self greyMapForRange:(255 * 1024).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7931
	greyValues := greyValues collect:[:v | v rounded].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7932
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7933
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7934
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7935
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7936
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7937
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7938
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7939
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7940
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7941
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7942
	    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
  7943
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7944
		int __grey, __e;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7945
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7946
		OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7947
		OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7948
		int __x = __intVal(x);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7949
		int __eR, __eB, __eRB, __eLB, __eI;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7950
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7951
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7952
		__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7953
		__grey += __intVal(__errorArray[__x+1]);
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7954
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7955
		__byte <<= 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7956
		if (__grey > 127*1024) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7957
		    __e = __grey - (255*1024);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7958
		    __byte |= 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7959
		} else {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7960
		    __e = __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7961
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7962
		if (__e) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7963
		    __eI = __e >> 4;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7964
		    __eR  = __eI * 7;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7965
		    __eRB = __eI * 1;
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7966
		    __eB  = __eI * 5;
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7967
		    __eLB = __e - __eR - __eRB - __eB;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7968
		    __errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7969
		    __nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7970
		    __nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7971
		    __nextErrorArray[__x  ] = __MKSMALLINT(__intVal(__nextErrorArray[__x  ]) + __eLB);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7972
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7973
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7974
		__bitCnt--;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7975
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7976
		    int __dstIndex = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7977
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7978
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7979
		    dstIndex = __MKSMALLINT(__dstIndex + 1);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7980
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7981
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7982
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7983
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  7984
		bitCnt = __MKSMALLINT(__bitCnt);
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7985
%}.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7986
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7987
"/                |eI "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  7988
"/                 xE "{ Class: SmallInteger }"
829
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  7989
"/                 xN "{ Class: SmallInteger }" |
d104ec97c38c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 828
diff changeset
  7990
"/
828
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7991
"/                "/ get the colors grey value [0 .. 1]
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7992
"/                grey := greyValues at:(pixel + 1).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7993
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7994
"/                "/ adjust error
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7995
"/                xE := x + 2.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7996
"/                grey := (grey + (errorArray at:xE)).
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7997
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7998
"/                byte := byte bitShift:1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  7999
"/                grey > (127*1024) ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8000
"/                    byte := byte bitOr:1.      "/ white
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8001
"/                    e := grey - (255*1024)
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8002
"/                ] ifFalse:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8003
"/                    e := grey                  "/ black
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8004
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8005
"/                e ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8006
"/                    eD := e.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8007
"/                    eI := e // 16.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8008
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8009
"/                    eR  := eI * 7.              "/ 7/16 to right
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8010
"/                    eRB := eI * 1.              "/ 1/16 to right below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8011
"/                    eB  := eI * 5.              "/ 5/16 to below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8012
"/                    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8013
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8014
"/                    xN := xE + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8015
"/                    eR ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8016
"/                        errorArray     at:xN put:(errorArray at:xN) + eR.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8017
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8018
"/                    eRB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8019
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8020
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8021
"/                    eB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8022
"/                        nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8023
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8024
"/                    eLB ~= 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8025
"/                        xN := xE - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8026
"/                        nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8027
"/                    ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8028
"/                ].
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8029
"/
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8030
"/                bitCnt := bitCnt - 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8031
"/                bitCnt == 0 ifTrue:[
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8032
"/                    monoBits at:dstIndex put:byte.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8033
"/                    dstIndex := dstIndex + 1.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8034
"/                    byte := 0.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8035
"/                    bitCnt := 8.
e5cc03d2c673 integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  8036
"/                ].
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8037
		  0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8038
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8039
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8040
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8041
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8042
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8043
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8044
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8045
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8046
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8047
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8048
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8049
	'Image [info]: slow floydSteinberg dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8050
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8051
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8052
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8053
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8054
	    t := errorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8055
	    errorArray := nextErrorArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8056
	    nextErrorArray := t.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8057
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8058
	    nextErrorArray atAllPut:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8059
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8060
	    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
  8061
		|eI "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8062
		 xE "{ Class: SmallInteger }"
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8063
		 xN "{ Class: SmallInteger }" |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8064
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8065
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8066
		grey := (clr brightness * 255).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8067
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8068
		"/ adjust error
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8069
		xE := x + 2.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8070
		grey := (grey + (errorArray at:xE)) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8071
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8072
		byte := byte bitShift:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8073
		grey > 127 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8074
		    byte := byte bitOr:1.      "/ white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8075
		    e := grey - 255
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8076
		] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8077
		    e := grey                  "/ black
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8078
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8079
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8080
		e ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8081
		    eD := e.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8082
		    eI := e // 16.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8083
		    eR  := eI * 7.              "/ 7/16 to right
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8084
		    eRB := eI * 1.              "/ 1/16 to right below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8085
		    eB  := eI * 5.              "/ 5/16 to below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8086
		    eLB := eD - eR - eRB - eB.  "/ 3/16 to left below
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8087
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8088
		    xN := xE + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8089
		    eR ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8090
			errorArray     at:xN put:(errorArray at:xN) + eR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8091
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8092
		    eRB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8093
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8094
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8095
		    eB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8096
			nextErrorArray at:xE put:(nextErrorArray at:xE) + eB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8097
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8098
		    eLB ~= 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8099
			xN := xE - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8100
			nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8101
		    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8102
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8103
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8104
		bitCnt := bitCnt - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8105
		bitCnt == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8106
		    monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8107
		    dstIndex := dstIndex + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8108
		    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8109
		    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8110
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8111
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8112
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8113
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8114
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8115
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8116
		bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8117
		byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8118
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8119
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8120
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8121
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8122
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8123
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8124
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8125
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8126
    "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
  8127
    "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
  8128
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8129
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8130
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8131
    "return a nearest paint bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8132
     which must be a depth-8 image.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8133
     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
  8134
     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
  8135
     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
  8136
     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
  8137
     Color class."
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8138
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8139
    |pseudoBits
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8140
     fixR    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8141
     fixG    "{Class: SmallInteger }"
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8142
     fixB    "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8143
     fixGfixB
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8144
     r       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8145
     g       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8146
     b       "{Class: SmallInteger }"
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8147
     idx     "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8148
     idMap lastColor
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8149
     clr|
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8150
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8151
    self depth ~~ 8 ifTrue:[^ nil].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8152
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8153
    photometric == #palette ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8154
	lastColor := colorMap size - 1
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8155
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8156
	lastColor := 255.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8157
    ].
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8158
    idMap := ByteArray uninitializedNew:256.
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8159
3915
dd2dae91c068 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3914
diff changeset
  8160
    (nRed isNil or:[nGreen isNil or:[nBlue isNil]]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8161
	0 to:lastColor do:[:pix |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8162
	    |clr repClr|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8163
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8164
	    clr := self colorFromValue:pix.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8165
	    repClr := clr nearestIn:fixColors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8166
	    idMap at:(pix+1) put:(fixColors identityIndexOf:repClr)-1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8167
	].
3914
875c38aa66ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3913
diff changeset
  8168
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8169
	fixR := nRed.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8170
	fixR == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8171
	fixG := nGreen.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8172
	fixG == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8173
	fixB := nBlue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8174
	fixB == 0 ifTrue:[ ^ nil].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8175
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8176
	"/ simple check
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8177
	(fixR * fixG * fixB) ~~ fixColors size ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8178
	    self error:'invalid color array passed'.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8179
	    ^ nil
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8180
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8181
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8182
	"/
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8183
	"/ collect colorIds
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8184
	"/
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8185
	fixGfixB := fixG * fixB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8186
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8187
	0 to:lastColor do:[:pix |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8188
	    clr := self colorFromValue:pix.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8189
	    r := clr redByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8190
	    g := clr greenByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8191
	    b := clr blueByte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8192
	    idx := ((r * (fixR-1) + 128) // 255) * fixGfixB.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8193
	    idx := idx + (((g * (fixG-1) + 128) // 255) * fixB).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8194
	    idx := idx + ((b * (fixB-1) + 128) // 255).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8195
	    idMap at:(pix+1) put:(fixColors at:(idx+1)) colorId.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8196
	].
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8197
    ].
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8198
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8199
    pseudoBits := ByteArray uninitializedNew:(width * height).
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8200
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8201
    "/ translate
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8202
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  8203
    self bits
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8204
	expandPixels:8         "xlate only"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8205
	width:width height:height
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8206
	into:pseudoBits
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8207
	mapping:idMap.
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8208
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8209
    ^ pseudoBits
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8210
884
d7cc8a20505b oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  8211
    "Modified: 18.6.1996 / 09:18:09 / cg"
879
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8212
!
2adf7645e7e6 added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 878
diff changeset
  8213
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8214
nfloydSteinbergDitheredDepth8BitsColors:colors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8215
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8216
     which must be a depth-8 image.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8217
     This method expects an array of colors to be used for dithering
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8218
     (which need not be a colorCubes colors)."
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8219
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8220
    |pseudoBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8221
     rgbBytes
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8222
     ditherRGBBytes ditherColors
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8223
     w       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8224
     h       "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8225
     index   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8226
     numR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8227
     numG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8228
     numB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8229
     bitsR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8230
     bitsG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8231
     bitsB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8232
     maxBits  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8233
     maskR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8234
     maskG    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8235
     maskB    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8236
     shR      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8237
     shG      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8238
     shB      "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8239
     ditherIds failed map lastColor colorsByDistance qScramble
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8240
     clrLookup lookupPos cube nCube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8241
     dR  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8242
     dG  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8243
     dB  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8244
     iR    "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8245
     iRG   "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8246
     iRGB  "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8247
     clr
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8248
     rI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8249
     gI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8250
     bI  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8251
     maxIDX  "{Class: SmallInteger }"
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8252
     subCubeColorCollection
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8253
     error
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8254
     dl "{Class: SmallInteger }"|
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8255
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8256
    self depth ~~ 8 ifTrue:[^ nil].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8257
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8258
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8259
    "/ collect color components as integer values (for integer arithmetic)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8260
    "/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8261
    rgbBytes := ByteArray uninitializedNew:256 * 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8262
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8263
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8264
	lastColor := colorMap size - 1
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8265
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8266
	lastColor := 255.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8267
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8268
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8269
    0 to:lastColor do:[:pix |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8270
	clr := self colorFromValue:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8271
	rgbBytes at:index put:(clr redByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8272
	rgbBytes at:index+1 put:(clr greenByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8273
	rgbBytes at:index+2 put:(clr blueByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8274
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8275
	index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8276
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8277
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8278
    "/ collect valid ditherColors ...
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8279
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8280
    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
  8281
    ditherColors := ditherColors select:[:clr | clr colorId notNil].
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8282
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8283
    "/ collect ditherColor components
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8284
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8285
    lastColor := ditherColors size.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8286
    ditherIds := ByteArray uninitializedNew:lastColor.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8287
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8288
    index := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8289
    1 to:lastColor do:[:pix |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8290
	clr := ditherColors at:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8291
	ditherRGBBytes at:index put:(clr redByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8292
	ditherRGBBytes at:index+1 put:(clr greenByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8293
	ditherRGBBytes at:index+2 put:(clr blueByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8294
	ditherIds at:pix put:clr colorId.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8295
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8296
	index := index + 3.
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8297
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8298
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8299
    "/ place the ditherColor positions into a color cube
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8300
    bitsR := 5.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8301
    bitsG := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8302
    bitsB := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8303
    maxBits := 6.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8304
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8305
"/    bitsR := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8306
"/    bitsG := 4.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8307
"/    bitsB := 3.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8308
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8309
    numR := 1 bitShift:bitsR.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8310
    numG := 1 bitShift:bitsG.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8311
    numB := 1 bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8312
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8313
    maskR := (numR-1) bitShift:(bitsG + bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8314
    maskG := (numG-1) bitShift:bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8315
    maskB := numB-1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8316
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8317
    shR := -16+bitsR+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8318
    shG := -16+bitsG+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8319
    shB := -16+bitsB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8320
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8321
    maxIDX := numR*numG*numB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8322
    cube := Array new:maxIDX.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8323
    1 to:lastColor do:[:clrIdx |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8324
	clr := ditherColors at:clrIdx.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8325
	rI := clr scaledRed. rI := (rI bitShift:shR) bitAnd:maskR.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8326
	gI := clr scaledGreen. gI := (gI bitShift:shG) bitAnd:maskG.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8327
	bI := clr scaledBlue. bI := (bI bitShift:shB) bitAnd:maskB.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8328
	index := rI + gI + bI + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8329
	subCubeColorCollection := cube at:index.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8330
	subCubeColorCollection isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8331
	    subCubeColorCollection := OrderedCollection new.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8332
	    cube at:index put:subCubeColorCollection.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8333
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8334
	subCubeColorCollection add:(clrIdx - 1).
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8335
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8336
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8337
    shR := 1 bitShift:(bitsG+bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8338
    shG := 1 bitShift:(bitsB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8339
    shB := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8340
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8341
    1 to:maxIDX do:[:i |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8342
	subCubeColorCollection := cube at:i.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8343
	subCubeColorCollection notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8344
	    cube at:i put:(subCubeColorCollection asByteArray)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8345
	]
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8346
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8347
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8348
"/    nCube := cube copy.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8349
"/
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8350
"/    cube keysAndValuesDo:[:i :indices |
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8351
"/        indices notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8352
"/            nCube at:i put:(indices asByteArray)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8353
"/        ] ifFalse:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8354
"/            "/ find nearest color
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8355
"/
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8356
"/            dl := 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8357
"/            [dl < maxBits] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8358
"/                dR := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8359
"/                [dR <= dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8360
"/                    iR := i + (dR * shR).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8361
"/                    (iR > 0 and:[iR < maxIDX]) ifTrue:[
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8362
"/                        dG := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8363
"/                        [dG < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8364
"/                            iRG := iR + (dG * shG).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8365
"/                            (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8366
"/                                dB := dl negated.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8367
"/                                [dB < dl] whileTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8368
"/                                    iRGB := iRG + dB.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8369
"/                                    (iRG > 0 and:[iRG < maxIDX]) ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8370
"/                                        (cube at:iRGB) notNil ifTrue:[
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8371
"/                                            nCube at:i put:(cube at:iRGB).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8372
"/                                            dB := dG := dR := dl := 999.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8373
"/                                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8374
"/                                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8375
"/                                    dB := dB + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8376
"/                                ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8377
"/                            ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8378
"/                            dG := dG + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8379
"/                        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8380
"/                    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8381
"/                    dR := dR + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8382
"/                ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8383
"/                dl := dl + 1.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8384
"/            ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8385
"/        ]
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8386
"/    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8387
"/self halt.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8388
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8389
    "/ now, cube contains collections of colors which are
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8390
    "/ positioned in a subCube; quickly accessed by a lookup
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8391
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8392
    pseudoBits := ByteArray uninitializedNew:(width * height).
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8393
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8394
    w := width.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8395
    h := height.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8396
    error := ByteArray new:(w+2)*3*2.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8397
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8398
%{
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8399
#define BITSR   5
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8400
#define BITSG   6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8401
#define BITSB   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8402
#define MAXBITS 6
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8403
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8404
#define xBITSR   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8405
#define xBITSG   4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8406
#define xBITSB   3
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8407
#define xMAXBITS 4
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8408
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8409
#define NR      32 /* (1<<BITSR) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8410
#define NG      64 /* (1<<BITSG) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8411
#define NB      16 /* (1<<BITSB) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8412
#define MAXRGB  64 /* (1<<MAXBITS) */
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8413
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8414
#define SHR     (BITSG+BITSB)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8415
#define SHG     BITSB
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8416
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8417
#define REMEMBER_SEARCH
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8418
#define xNO_FLOYD_STEINBERG
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8419
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8420
    int __x, __y;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8421
    int __eR, __eG, __eB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8422
    unsigned char *srcP, *dstP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8423
    unsigned char *rgbP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8424
    unsigned char *idP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8425
    short *errP, *eP;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8426
    int __fR, __fG, __fB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8427
    int idx;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8428
    int __w = __intVal(w);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8429
    int __h = __intVal(h);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8430
    int __nColors = __intVal(lastColor);
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8431
    int __wR = -1, __wG, __wB;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8432
    OBJ *__cube;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8433
    int cubeIndex, cubeIndex2;
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8434
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
  8435
    if (__isByteArrayLike(__INST(bytes))
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8436
     && __isByteArray(pseudoBits)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8437
     && __isByteArray(rgbBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8438
     && __isByteArray(ditherRGBBytes)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8439
     && __isByteArray(ditherIds)
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8440
     && __isByteArray(error)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8441
	failed = false;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8442
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8443
	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8444
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8445
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8446
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8447
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8448
	__cube = __ArrayInstPtr(cube)->a_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8449
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8450
	eP = errP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8451
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8452
	for (__y=__h; __y>0; __y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8453
	    eP = &(errP[3]);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8454
	    __eR = eP[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8455
	    __eG = eP[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8456
	    __eB = eP[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8457
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8458
	    for (__x=__w; __x>0; __x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8459
		int __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8460
		int pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8461
		int __wantR, __wantG, __wantB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8462
		int idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8463
		int tR, tG, tB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8464
		int nR, nG, nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8465
		int __dR, __dG, __dB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8466
		int minDelta, bestIdx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8467
		int __iR, __iG, __iB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8468
		int cR, cG, cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8469
		int delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8470
		OBJ subCubeColors;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8471
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8472
		pix = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8473
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8474
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8475
		 * wR, wG and wB is the wanted r/g/b value;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8476
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8477
		idx = pix+pix+pix;  /* pix * 3 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8478
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8479
		__wR = __wantR = rgbP[idx] + __eR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8480
		__wG = __wantG = rgbP[idx+1] + __eG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8481
		__wB = __wantB = rgbP[idx+2] + __eB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8482
		if(__wR > 255) __wR = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8483
		else if (__wR < 0) __wR = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8484
		if(__wG > 255) __wG = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8485
		else if (__wG < 0) __wG = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8486
		if(__wB > 255) __wB = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8487
		else if (__wB < 0) __wB = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8488
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8489
		__iR = __wR >> (8-BITSR);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8490
		__iG = __wG >> (8-BITSG);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8491
		__iB = __wB >> (8-BITSB);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8492
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8493
		cubeIndex = (__iR<<SHR) + (__iG<<SHG) + __iB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8494
		subCubeColors = __cube[cubeIndex];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8495
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8496
		if (subCubeColors == nil) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8497
		    /* search around in spirals, for the first match */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8498
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8499
		    delta = 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8500
		    while (delta < MAXRGB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8501
			/* check plane above */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8502
			cR = __iR + delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8503
			if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8504
			    for (cG=__iG-delta; cG<=__iG+delta; cG++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8505
				if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8506
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8507
					if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8508
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8509
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8510
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8511
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8512
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8513
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8514
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8515
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8516
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8517
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8518
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8519
			/* check plane below */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8520
			cR = __iR - delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8521
			if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8522
			    for (cG=__iG-delta; cG<=__iG+delta; cG++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8523
				if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8524
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8525
					if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8526
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8527
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8528
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8529
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8530
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8531
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8532
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8533
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8534
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8535
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8536
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8537
			/* check plane to the right */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8538
			cG = __iG + delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8539
			if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8540
			    for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8541
				if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8542
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8543
					if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8544
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8545
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8546
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8547
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8548
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8549
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8550
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8551
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8552
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8553
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8554
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8555
			/* check plane to the left */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8556
			cG = __iG - delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8557
			if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8558
			    for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8559
				if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8560
				    for (cB=__iB-delta; cB<=__iB+delta; cB++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8561
					if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8562
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8563
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8564
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8565
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8566
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8567
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8568
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8569
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8570
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8571
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8572
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8573
			/* check plane at back */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8574
			cB = __iB + delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8575
			if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8576
			    for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8577
				if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8578
				    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8579
					if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8580
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8581
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8582
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8583
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8584
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8585
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8586
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8587
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8588
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8589
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8590
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8591
			/* check plane at front */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8592
			cB = __iB - delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8593
			if ((unsigned)cB < NB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8594
			    for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8595
				if ((unsigned)cR < NR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8596
				    for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8597
					if ((unsigned)cG < NG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8598
					    cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8599
					    subCubeColors = __cube[cubeIndex2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8600
					    if (__isNonNilObject(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8601
						goto found;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8602
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8603
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8604
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8605
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8606
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8607
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8608
			delta = delta + 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8609
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8610
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8611
		    /* cannot happen - will lead to a segmentation violation ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8612
		    subCubeColors = nil;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8613
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8614
    found:
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8615
		    __iR = cR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8616
		    __iG = cG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8617
		    __iB = cB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8618
		    bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8619
#ifdef REMEMBER_SEARCH
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8620
		    __cube[cubeIndex] = __MKSMALLINT(bestIdx);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8621
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8622
		} else {
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8623
#ifdef REMEMBER_SEARCH
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8624
		    if (__isSmallInteger(subCubeColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8625
			bestIdx = __intVal(subCubeColors);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8626
		    } else
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8627
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8628
		    {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8629
			bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8630
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8631
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8632
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8633
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8634
		 * ok, now, we have found a collection of nearby
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8635
		 * colors in subCubeColors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8636
		 *
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8637
		 * since the error is at most 1/16 (i.e. roughly 6%),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8638
		 * dont care for searching the best - simply take the
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8639
		 * first color found there.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8640
		 * (statistic reduces the error to even a smaller value).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8641
		 * There is no real problem due to that error, since
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8642
		 * it will be diffused anyway ...
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8643
		 */
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8644
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8645
#ifndef NO_FLOYD_STEINBERG
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8646
		{
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8647
		    unsigned char *dp;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8648
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8649
		    /*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8650
		     * fetch that colors r/g/b components
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8651
		     */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8652
		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8653
		    dp += bestIdx * 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8654
		    __dR = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8655
		    __dG = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8656
		    __dB = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8657
		}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8658
#endif
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8659
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8660
/*
4725
c8896df7bd3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4717
diff changeset
  8661
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8662
		__wantR, __wantG, __wantB,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8663
		__wR, __wG, __wB,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8664
		__dR, __dG, __dB);
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8665
*/
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8666
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8667
		 * store the corresponding dither colors colorId
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8668
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8669
		*dstP++ = idP[bestIdx];
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8670
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8671
#ifndef NO_FLOYD_STEINBERG
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8672
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8673
		 * the new error & distribute the error
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8674
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8675
		__eR = __wantR - __dR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8676
		if (__eR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8677
		    tR = __eR >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8678
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8679
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8680
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8681
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8682
		    __eR = nR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8683
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8684
		    __eR = eP[3];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8685
		    eP[0] = eP[-3] = eP[3] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8686
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8687
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8688
		__eG = __wantG - __dG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8689
		if (__eG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8690
		    tG = __eG >> 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8691
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8692
		    eP[1] = tG*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8693
		    eP[-2] = tG*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8694
		    eP[4] = __eG - (tG*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8695
		    __eG = nG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8696
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8697
		    __eG = eP[4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8698
		    eP[1] = eP[-2] = eP[4] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8699
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8700
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8701
		__eB = __wantB - __dB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8702
		if (__eB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8703
		    tB = __eB >> 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8704
		    nB = eP[5] + (tB * 7);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8705
		    eP[2] = tB*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8706
		    eP[-1] = tB*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8707
		    eP[5] = __eB - (tB*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8708
		    __eB = nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8709
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8710
		    __eB = eP[5];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8711
		    eP[2] = eP[-1] = eP[5] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8712
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8713
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8714
		eP += 3;
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8715
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8716
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8717
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8718
	    /*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8719
	     * allow for an interrupt after every row.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8720
	     * but care to refetch C variables
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8721
	     */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8722
	    if (InterruptPending) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8723
		int d_srcP = srcP - __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8724
		int d_dstP = dstP - __ByteArrayInstPtr(pseudoBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8725
		int d_errP = errP - (short *) __ByteArrayInstPtr(error)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8726
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8727
		__interrupt__();
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8728
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8729
		srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element + d_srcP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8730
		dstP = __ByteArrayInstPtr(pseudoBits)->ba_element + d_dstP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8731
		rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8732
		idP = __ByteArrayInstPtr(ditherIds)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8733
		errP = (short *) __ByteArrayInstPtr(error)->ba_element + d_errP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8734
		__cube = __ArrayInstPtr(cube)->a_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8735
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8736
	}
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8737
    }
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8738
%}.
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8739
    failed ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8740
	self primitiveFailed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  8741
	^ nil
903
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8742
    ].
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8743
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8744
    ^ pseudoBits
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8745
!
fcb45024a286 experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents: 901
diff changeset
  8746
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8747
orderedDitheredGrayBitsDepth:depth
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8748
    "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
  8749
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  8750
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8751
	orderedDitheredGrayBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8752
	ditherWidth:8
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8753
	depth:depth.
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8754
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8755
    "Created: 24.6.1997 / 22:20:12 / cg"
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8756
!
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8757
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1781
diff changeset
  8758
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8759
    "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
  8760
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8761
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8762
     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
  8763
     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
  8764
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8765
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8766
     greyLevels greyValues greyPixels greyErrors
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8767
     dstIndex        "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8768
     nextDst
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8769
     bytesPerOutRow  "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8770
     pixelsPerByte   "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8771
     outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8772
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8773
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8774
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8775
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8776
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8777
    depth > 8 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8778
	'IMAGE: unimplemented orderedDither conversion' errorPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8779
	^ nil
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8780
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8781
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8782
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8783
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8784
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8785
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8786
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8787
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8788
    greyLevels := 1 bitShift:depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8789
    pixelsPerByte := 8 / depth.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8790
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8791
    bytesPerOutRow := (w * depth + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8792
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8793
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8794
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8795
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8796
    self bitsPerPixel <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8797
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8798
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8799
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8800
	greyValues := self greyMapForRange:(greyLevels-1).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8801
	greyPixels := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8802
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8803
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8804
						   v truncated]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8805
	greyPixels := ByteArray withAll:greyPixels.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8806
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8807
	greyErrors := greyValues collect:[:v | v isNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8808
						   0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8809
					       ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8810
						   ((v - v truncated) * nDither) rounded
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8811
					       ]].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8812
	greyErrors := ByteArray withAll:greyErrors.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8813
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8814
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8815
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8816
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8817
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8818
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8819
	    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
  8820
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8821
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8822
		int __byte = __intVal(byte);
4745
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8823
		/* 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
  8824
		int __val = __intVal(value);
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8825
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8826
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8827
		int __pixel, __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8828
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8829
		unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8830
		unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8831
4745
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8832
		__pixel = __greyPixels[__val];
778644e0c89b Can compile with MS Visual C++ 8 / 2005
Stefan Vogel <sv@exept.de>
parents: 4725
diff changeset
  8833
		__grey = __greyErrors[__val];
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8834
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8835
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8836
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8837
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8838
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8839
		if (__grey > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8840
		    __pixel++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8841
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8842
		__byte = (__byte << __intVal(depth)) | __pixel;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8843
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8844
		__bitCnt = __bitCnt - __intVal(depth);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8845
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8846
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8847
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8848
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8849
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8850
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8851
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8852
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8853
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8854
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8855
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8856
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8857
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8858
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8859
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8860
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8861
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8862
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8863
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8864
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8865
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8866
	'Image [info]: slow ordered dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8867
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8868
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8869
	    nextDst := dstIndex + bytesPerOutRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8870
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8871
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8872
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8873
	    "/ this is the representaion independent (but slow)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8874
	    "/ inner loop - it extracts colors from the receiver
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8875
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8876
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8877
		|dstClr grey dT pixel|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8878
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8879
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8880
		grey := clr brightness.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8881
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8882
		"/ remap into [0 .. greyLevels-1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8883
		grey := grey * (greyLevels-1).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8884
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8885
		"/ get threshold pixel [0 .. greyLevels-1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8886
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8887
		pixel := grey truncated.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8888
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8889
		"/ compute the error [0..1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8890
		grey := grey - pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8891
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8892
		"/ map into dither space [0 .. nDither]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8893
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8894
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8895
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8896
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8897
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8898
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8899
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8900
		int __pixel;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8901
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8902
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8903
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8904
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8905
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8906
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8907
		__pixel = __intVal(pixel);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8908
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8909
		if (__intVal(grey) > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8910
		    __pixel++;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8911
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8912
		__byte = (__byte << __intVal(depth)) | __pixel;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8913
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8914
		__bitCnt = __bitCnt - __intVal(depth);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8915
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8916
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8917
		    __ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8918
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8919
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8920
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8921
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8922
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8923
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8924
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8925
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8926
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8927
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8928
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8929
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8930
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8931
		outBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8932
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8933
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8934
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8935
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8936
    ^ outBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8937
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8938
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8939
orderedDitheredMonochromeBits
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8940
    "return the bitmap for a dithered monochrome bitmap from the image;
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8941
     using a default ditherMatrix."
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8942
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8943
    ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8944
	orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  8945
	ditherWidth:8
831
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8946
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8947
    "Created: 11.6.1996 / 16:48:57 / cg"
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8948
!
ceb4e9f32262 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  8949
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8950
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8951
    "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
  8952
     with a constant ditherMatrix, this can be used for thresholding.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8953
     Works for any source depths / photometric,
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8954
     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
  8955
     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
  8956
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  8957
    |dH nDither
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8958
     greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8959
     dstIndex        "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8960
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8961
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8962
     monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8963
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8964
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8965
     bitCnt          "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8966
     byte            "{Class: SmallInteger }" |
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8967
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8968
    nDither := ditherMatrix size.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8969
    dH := nDither / dW.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8970
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8971
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8972
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8973
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8974
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8975
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8976
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8977
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8978
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  8979
    self bitsPerPixel <= 12 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8980
	"/ fetch scaled brightness values outside of loop into a table;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8981
	"/ use table-value in loop
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8982
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8983
	greyValues := self greyByteMapForRange:nDither.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8984
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8985
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8986
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8987
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8988
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8989
	    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
  8990
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8991
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8992
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8993
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8994
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8995
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8996
		int __grey;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8997
		unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8998
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  8999
		__grey = __greyValues[__intVal(value)];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9000
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9001
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9002
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9003
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9004
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9005
		__byte = __byte << 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9006
		if (__grey > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9007
		    __byte = __byte | 1;            /* white */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9008
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9009
		__bitCnt = __bitCnt - 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9010
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9011
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9012
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9013
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9014
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9015
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9016
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9017
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9018
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9019
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9020
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9021
		0
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9022
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9023
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9024
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9025
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9026
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9027
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9028
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9029
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9030
	'Image [info]: slow ordered dither ..' infoPrintCR.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9031
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9032
	0 to:(h-1) do:[:y |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9033
	    nextDst := dstIndex + bytesPerMonoRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9034
	    byte := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9035
	    bitCnt := 8.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9036
	    self colorsAtY:y from:0 to:(w-1) do:[:x :clr |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9037
		|dstClr grey dT|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9038
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9039
		"/ get the colors grey value [0 .. 1]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9040
		grey := clr brightness.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9041
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9042
		"/ map into dither space [0 .. nDither]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9043
		grey := (grey * (nDither)) rounded.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9044
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9045
%{
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9046
		int __dW = __intVal(dW);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9047
		int __byte = __intVal(byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9048
		int __dT;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9049
		int __dstIdx;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9050
		int __bitCnt = __intVal(bitCnt);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9051
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9052
		__dT = __ByteArrayInstPtr(ditherMatrix)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9053
			    ->ba_element[__intVal(x) % __dW
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9054
					 + (__intVal(y) % __intVal(dH)) * __dW];
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9055
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9056
		__byte = __byte << 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9057
		if (__intVal(grey) > __dT) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9058
		    __byte = __byte | 1;            /* white */
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9059
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9060
		__bitCnt = __bitCnt - 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9061
		if (__bitCnt == 0) {
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9062
		    __dstIdx = __intVal(dstIndex);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9063
		    __ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9064
		    __dstIdx = __dstIdx + 1;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9065
		    dstIndex = __MKSMALLINT(__dstIdx);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9066
		    __byte = 0;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9067
		    __bitCnt = 8;
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9068
		}
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9069
		byte = __MKSMALLINT(__byte);
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9070
		bitCnt = __MKSMALLINT(__bitCnt);
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9071
%}.
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9072
		0
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9073
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9074
"/                dT := ditherMatrix at:(x \\ dW) + (y \\ dH * dW) + 1.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9075
"/
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9076
"/                byte := byte bitShift:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9077
"/                grey < dT ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9078
"/                    byte := byte bitOr:1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9079
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9080
"/                bitCnt := bitCnt - 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9081
"/                bitCnt == 0 ifTrue:[
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9082
"/                    monoBits at:dstIndex put:byte.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9083
"/                    dstIndex := dstIndex + 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9084
"/                    byte := 0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9085
"/                    bitCnt := 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9086
"/                ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9087
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9088
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9089
	    bitCnt ~~ 8 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9090
		byte := byte bitShift:bitCnt.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9091
		monoBits at:dstIndex put:byte.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9092
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9093
	    dstIndex := nextDst.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
  9094
	].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9095
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9096
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9097
!
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9098
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9099
stevensonArceDitheredMonochromeBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9100
    "return the bitmap for a dithered monochrome bitmap from the image.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9101
     Works for any source depths / photometric.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9102
     TODO: move to separate dither helper class"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9103
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9104
    |dstIndex        "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9105
     nextDst         "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9106
     bytesPerMonoRow "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9107
     monoBits greyValues
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9108
     errorArray
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9109
     errorArray1 errorArray2 errorArray3
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9110
     e t
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9111
     w               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9112
     h               "{Class: SmallInteger }"
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9113
     bitCnt          "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9114
     byte            "{Class: SmallInteger }"
1063
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9115
     grey
ba1bf8091bc1 unused variable cleanup
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  9116
     xE              "{Class: SmallInteger }" |
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9117
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9118
    self depth > 12 ifTrue:[
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9119
        ^ self floydSteinbergDitheredMonochromeBits
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9120
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9121
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9122
    w := width.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9123
    h := height.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9124
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9125
    bytesPerMonoRow := (w + 7) // 8.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9126
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9127
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9128
    errorArray := Array new:(w+6).
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9129
    errorArray1 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9130
    errorArray2 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9131
    errorArray3 := Array new:(w+6) withAll:0.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9132
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9133
    dstIndex := 1.
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9134
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9135
    "/ 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
  9136
    "/ use table-value in loop
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9137
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9138
    greyValues := self greyMapForRange:(255 * 1024).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9139
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9140
    0 to:(h-1) do:[:y |
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9141
        nextDst := dstIndex + bytesPerMonoRow.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9142
        byte := 0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9143
        bitCnt := 8.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9144
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9145
        t := errorArray.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9146
        errorArray := errorArray1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9147
        errorArray1 := errorArray2.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9148
        errorArray2 := errorArray3.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9149
        errorArray3 := t.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9150
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9151
        errorArray3 atAllPut:0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9152
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9153
        self valuesAtY:y from:0 to:(w-1) do:[:x :pixel |
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9154
            |eP eD|
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9155
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9156
            "/ get the colors grey value [0 .. 1]
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9157
            grey := greyValues at:(pixel + 1).
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9158
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9159
            "/ adjust error
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9160
            xE := x + 3 + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9161
            grey := (grey + (errorArray at:xE)).
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9162
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9163
            byte := byte bitShift:1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9164
            grey > (127 * 1024) ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9165
                byte := byte bitOr:1.      "/ white
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9166
                e := grey - (255 * 1024)
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9167
            ] ifFalse:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9168
                e := grey                  "/ black
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9169
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9170
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9171
            e ~= 0 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9172
                "/ distribute the error:
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9173
                "/                  XX    32
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9174
                "/         12    26    30    16
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9175
                "/            12    26    12
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9176
                "/          5    12    12     5
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9177
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9178
                eD := e.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9179
                e := e // 200.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9180
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9181
                eP := e * 32. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9182
                errorArray at:xE+2 put:(errorArray at:xE+2) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9183
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9184
                eP := e * 30. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9185
                errorArray1 at:xE+1 put:(errorArray1 at:xE+1) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9186
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9187
                eP := e * 16. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9188
                errorArray1 at:xE+3 put:(errorArray1 at:xE+3) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9189
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9190
                eP := e * 26. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9191
                errorArray1 at:xE-1 put:(errorArray1 at:xE-1) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9192
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9193
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9194
                errorArray2 at:xE put:(errorArray2 at:xE) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9195
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9196
                eP := e * 12. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9197
                errorArray1 at:xE-3 put:(errorArray1 at:xE-3) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9198
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9199
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9200
                errorArray2 at:xE-2 put:(errorArray2 at:xE-2) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9201
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9202
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9203
                errorArray2 at:xE+2 put:(errorArray2 at:xE+2) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9204
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9205
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9206
                errorArray3 at:xE-1 put:(errorArray3 at:xE-1) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9207
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9208
                eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9209
                errorArray3 at:xE+1 put:(errorArray3 at:xE+1) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9210
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9211
                eP := e * 5. eD := eD - eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9212
                errorArray3 at:xE-3 put:(errorArray3 at:xE-3) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9213
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9214
                eP := eD.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9215
                errorArray3 at:xE+3 put:(errorArray3 at:xE+3) + eP.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9216
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9217
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9218
            bitCnt := bitCnt - 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9219
            bitCnt == 0 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9220
                monoBits at:dstIndex put:byte.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9221
                dstIndex := dstIndex + 1.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9222
                byte := 0.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9223
                bitCnt := 8.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9224
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9225
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9226
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9227
        bitCnt ~~ 8 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9228
            byte := byte bitShift:bitCnt.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9229
            monoBits at:dstIndex put:byte.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9230
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9231
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
  9232
        dstIndex := nextDst.
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9233
    ].
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9234
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9235
    ^ monoBits
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9236
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9237
    "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
  9238
    "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
  9239
! !
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  9240
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9241
!Image methodsFor:'drawing'!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9242
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9243
displayArcOrigin:origin corner:corner from:startAngle angle:angle withColor:aColor
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9244
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9245
     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
  9246
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9247
    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
  9248
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9249
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9250
     |cm i|
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
     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
  9253
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9254
     i := Depth8Image extent:300@400 depth:8 palette:cm.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9255
     i displayArcOrigin:100@100 corner:200@200 from:0 angle:90 withColor:Color red.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9256
     i inspect.
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
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9259
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9260
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
  9261
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9262
     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
  9263
     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
  9264
     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
  9265
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9266
    |tempForm wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9267
     hI "{ Class: SmallInteger }"|
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9268
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9269
    wI := self width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9270
    hI := self height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9271
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9272
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9273
    tempForm clear.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9274
    tempForm paint:(Color colorId:1).
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9275
    tempForm displayArcOrigin:origin corner:corner from:startAngle angle:angle.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9276
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9277
    0 to:hI-1 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9278
	0 to:wI-1 do:[:xRun|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9279
	    (tempForm atX:xRun y:yRun) == 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9280
		self atImageAndMask:(xRun)@(yRun) putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9281
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9282
	].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9283
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9284
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9285
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9286
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9287
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9288
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9289
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9290
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9291
     i := Depth8Image extent:300@400 depth:8 palette:cm.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9292
     i displayArcOrigin:100@100 corner:200@200 from:0 angle:90 withColor:Color red.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9293
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9294
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9295
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9296
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9297
drawEllipse:aRectangle withColor:aColor
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9298
    "draw a circle with some pixel value.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9299
     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
  9300
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9301
    self drawEllipse:aRectangle withValue:(self valueFromColor:aColor)
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
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9305
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9306
     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
  9307
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9308
     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
  9309
     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
  9310
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9311
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9312
!
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
drawEllipse:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9315
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9316
     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
  9317
     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
  9318
     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
  9319
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9320
    |tempForm xI "{ Class: SmallInteger }"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9321
     yI "{ Class: SmallInteger }"
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9322
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9323
     hI "{ Class: SmallInteger }"|
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9324
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9325
    wI := aRectangle width.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9326
    hI := aRectangle height.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9327
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9328
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9329
    tempForm clear.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9330
    tempForm paint:(Color colorId:1).
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9331
    tempForm displayArcIn:(0@0 extent:wI@hI) from:0 angle:360.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9332
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9333
    xI := aRectangle left.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9334
    yI := aRectangle top.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9335
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9336
    0 to:hI-1 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9337
	0 to:wI-1 do:[:xRun|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9338
	    (tempForm atX:xRun y:yRun) == 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9339
		self atImageAndMask: (xI+xRun)@(yI+yRun) putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9340
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9341
	].
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9342
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9343
    self release. "/ device-image is no longer valid
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9344
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9345
    "
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9346
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9347
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9348
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9349
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9350
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9351
     i drawEllipse:(0@0 corner:80@100) withColor:Color red.
4994
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9352
     i inspect.
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9353
    "
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9354
!
2bc5eeefaee9 +drawEllipse
Claus Gittinger <cg@exept.de>
parents: 4972
diff changeset
  9355
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9356
drawLineFrom:startPoint to:endPoint withColor:aColorOrPixelValue
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9357
    "draw a line with some pixel value.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9358
     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
  9359
     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
  9360
     (such as the HumanReadableImageGenerator)"
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9361
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9362
    |pixelValue|
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9363
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9364
    pixelValue := aColorOrPixelValue.
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9365
    pixelValue isInteger ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9366
	pixelValue := self valueFromColor:aColorOrPixelValue
5235
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9367
    ].
e9ab91666ebf *** empty log message ***
sr
parents: 5216
diff changeset
  9368
    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
  9369
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9370
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9371
     |i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9372
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9373
     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
  9374
     i photometric:#blackIs0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9375
     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
  9376
     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
  9377
     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
  9378
     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
  9379
     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
  9380
     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
  9381
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9382
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9383
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9384
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9385
drawLineFrom:startPoint to:endPoint withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9386
    "draw a line with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9387
     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
  9388
     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
  9389
     (such as the HumanReadableImageGenerator).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9390
     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
  9391
     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
  9392
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9393
    |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
  9394
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9395
    x0 := startPoint x.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9396
    y0 := startPoint y.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9397
    x1 := endPoint x.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9398
    y1 := endPoint y.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9399
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9400
    steep := (y1 - y0) abs > (x1 - x0) abs.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9401
    steep ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9402
	t := x0. x0 := y0. y0 := t.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9403
	t := x1. x1 := y1. y1 := t.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9404
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9405
    x0 > x1 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9406
	t := x0. x0 := x1. x1 := t.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9407
	t := y0. y0 := y1. y1 := t.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9408
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9409
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9410
    deltax := x1 - x0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9411
    deltay := (y1 - y0) abs.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9412
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9413
    deltax == 0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9414
	y0 to: y1 do:[:y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9415
	    self atImageAndMask:x0@y putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9416
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9417
	^ self.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9418
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9419
    deltay == 0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9420
	x0 to: x1 do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9421
	    self atImageAndMask:x@y0 putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9422
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9423
	^ self.
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9424
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9425
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9426
    error := 0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9427
    deltaerr := deltay / deltax.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9428
    y := y0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9429
    y0 < y1 ifTrue:[ ystep := 1 ] ifFalse:[ ystep := -1 ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9430
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9431
    x0 to: x1 do:[:x |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9432
	steep ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9433
	    self atImageAndMask:y@x putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9434
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9435
	    self atImageAndMask:x@y putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9436
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9437
	error := error + deltaerr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9438
	error >= 0.5 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9439
	    y := y + ystep.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9440
	    error := error - 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9441
	]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9442
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9443
    self release. "/ device-image is no longer valid
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9444
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9445
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9446
     |i|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9447
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9448
     i := Depth1Image extent:100@100 depth:1 palette:nil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9449
     i photometric:#blackIs0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9450
     i drawLineFrom:5@5 to:94@5 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9451
     i drawLineFrom:94@5 to:94@94 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9452
     i drawLineFrom:94@94 to:5@94 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9453
     i drawLineFrom:5@94 to:5@5 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9454
     i drawLineFrom:10@10 to:90@90 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9455
     i drawLineFrom:90@10 to:10@90 withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9456
     i inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9457
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9458
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9459
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9460
drawRectangle: aRectangle withColor:aColor
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9461
    "draw a rectangle with some pixel value.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9462
     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
  9463
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9464
    self drawRectangle:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9465
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9466
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9467
     |i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9468
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9469
     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
  9470
     i photometric:#blackIs0.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9471
     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
  9472
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9473
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9474
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9475
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9476
drawRectangle: aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9477
    "draw a rectangle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9478
     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
  9479
     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
  9480
     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
  9481
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9482
    |xI "{ Class: SmallInteger }"
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9483
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9484
     wI "{ Class: SmallInteger }"
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9485
     hI "{ Class: SmallInteger }"|
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9486
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9487
    xI := aRectangle left.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9488
    yI := aRectangle top.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9489
    wI := aRectangle width.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9490
    hI := aRectangle height.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9491
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9492
    xI to:xI+wI-1 do:[:xRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9493
	self atImageAndMask: xRun@yI put:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9494
	self atImageAndMask: xRun@(yI+hI-1) put:aPixelValueOrNil
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9495
    ].
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9496
    yI+1 to:yI+hI-2 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9497
	self atImageAndMask: xI@yRun put:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9498
	self atImageAndMask: xI+wI-1@yRun put:aPixelValueOrNil
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9499
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9500
    self release. "/ device-image is no longer valid
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9501
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9502
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9503
     |i|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9504
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9505
     i := Depth1Image extent:100@100 depth:1 palette:nil.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9506
     i photometric:#blackIs0.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9507
     i drawRectangle:(10@10 corner:90@90) withColor:1.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9508
     i inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  9509
    "
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9510
!
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9511
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
  9512
fillAntiAliasedArc:origin radius:r from:startAngle angle:angle withColor:aColor colorDictionary:colorDictionary blendStart:blendStart
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9513
    "draw a circle with some pixel value.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9514
     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
  9515
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9516
    |tempForm wI "{ Class: SmallInteger }"
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9517
     hI "{ Class: SmallInteger }"
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9518
     colorValue|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9519
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9520
    wI := self width.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9521
    hI := self height.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9522
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9523
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9524
    tempForm clear.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9525
    tempForm paint:(Color colorId:1).
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9526
    tempForm fillArc:origin radius:r from:startAngle angle:angle.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9527
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9528
    colorValue := self valueFromColor:aColor.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9529
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
  9530
    0 to:hI-1 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9531
	0 to:wI-1 do:[:xRun|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9532
	    (tempForm atX:xRun y:yRun) == 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9533
		self atImageAndMask:(xRun)@(yRun) putValue:colorValue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9534
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9535
		#(#left right) do:[:aHorizontal |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9536
		    #(#top bottom) do:[:aVertical |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9537
			self vitualAntiAliasedAlongXvertical:aVertical horizontal:aHorizontal form:tempForm color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9538
			self vitualAntiAliasedAlongYhorizontal:aHorizontal vertical:aVertical form:tempForm color:aColor xRun:xRun yRun:yRun colorDictionary:colorDictionary blendStart:blendStart.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9539
		    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9540
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9541
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9542
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9543
    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9544
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9545
    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9546
	|colorMap aaImgArray|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9547
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9548
	colorMap := Array with:Color white with:Color black with:Color red with:Color blue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9549
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9550
	aaImgArray := Depth8Image extent:300@400 depth:8 antiAliasedPalette:colorMap bgColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9551
	aaImgArray last fillAntiAliasedArc:205@195 radius:80 from:0 angle:90 withColor:Color red
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9552
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9553
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9554
	aaImgArray last fillAntiAliasedArc:200@200 radius:80 from:90 angle:270 withColor:Color blue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9555
	    colorDictionary:aaImgArray first
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9556
	    blendStart:aaImgArray second.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9557
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9558
	aaImgArray last inspect.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9559
    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9560
!
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9561
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9562
fillArc:origin radius:r from:startAngle angle:angle withColor:aColorOrIndex
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9563
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9564
     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
  9565
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9566
    |tempForm wI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9567
     hI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9568
     colorValue|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9569
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9570
    wI := self width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9571
    hI := self height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9572
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9573
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9574
    tempForm clear.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9575
    tempForm paint:(Color colorId:1).
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9576
    tempForm fillArc:origin radius:r from:startAngle angle:angle.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9577
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9578
    aColorOrIndex isInteger ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9579
	colorValue := aColorOrIndex.
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9580
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9581
	colorValue := self valueFromColor:aColorOrIndex.
4997
15d53562d4e8 changed #fillArc:radius:from:angle:withColor:
sr
parents: 4996
diff changeset
  9582
    ].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9583
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9584
    0 to:hI-1 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9585
	0 to:wI-1 do:[:xRun|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9586
	    (tempForm atX:xRun y:yRun) == 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9587
		self atImageAndMask:(xRun)@(yRun) putValue:colorValue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9588
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9589
	].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9590
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9591
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9592
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9593
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9594
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9595
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9596
     cm :=  Array with:Color white with:Color black with:Color red with:Color blue.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9597
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9598
     i := Depth8Image extent:300@400 depth:8 palette:cm.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9599
     i fillArc:205@195 radius:80 from:0 angle:90 withColor:Color red.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9600
     i fillArc:200@200 radius:80 from:90 angle:270 withColor:Color blue.
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9601
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9602
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9603
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9604
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9605
fillEllipse:aRectangle withColor:aColor
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9606
    "draw a circle with some pixel value.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9607
     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
  9608
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9609
    self fillEllipse:aRectangle withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9610
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9611
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9612
     |cm i|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9613
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9614
     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
  9615
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9616
     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
  9617
     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
  9618
     i inspect.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9619
    "
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9620
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9621
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9622
fillEllipse:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9623
    "draw a circle with some pixel value.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9624
     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
  9625
     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
  9626
     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
  9627
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9628
    |tempForm xI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9629
     yI "{ Class: SmallInteger }"
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9630
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9631
     hI "{ Class: SmallInteger }"|
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9632
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9633
    wI := aRectangle width.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9634
    hI := aRectangle height.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9635
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9636
    tempForm := Form width:wI height:hI depth:1 onDevice:Screen current.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9637
    tempForm clear.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9638
    tempForm paint:(Color colorId:1).
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9639
    tempForm fillArcIn:(0@0 extent:wI@hI) from:0 angle:360.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9640
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9641
    xI := aRectangle left.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9642
    yI := aRectangle top.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9643
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9644
    0 to:hI-1 do:[:yRun|
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9645
	0 to:wI-1 do:[:xRun|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9646
	    (tempForm atX:xRun y:yRun) == 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9647
		self atImageAndMask:(xI+xRun)@(yI+yRun) putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9648
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9649
	].
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9650
    ].
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9651
    self release. "/ device-image is no longer valid
4996
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9652
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9653
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9654
     |cm i|
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9655
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9656
     cm :=  Array with:Color white with:Color black with:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9657
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9658
     i := Depth8Image extent:300@400 depth:8 palette:cm.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9659
     i fillEllipse:(0@0 corner:80@100) withColor:Color red.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9660
     i inspect.
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9661
    "
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9662
!
933de2d71291 added #fillArc... methode
sr
parents: 4995
diff changeset
  9663
4995
3a5cb7a57b0b changed #fillRectangle:aRectangle withColor:aColor
sr
parents: 4994
diff changeset
  9664
fillRectangle:aRectangle withColor:aColor
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9665
    self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9666
	fillRectangle:aRectangle
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9667
	withValue:(self valueFromColor:aColor)
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9668
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9669
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9670
fillRectangle:aRectangle withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9671
    "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
  9672
     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
  9673
     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
  9674
     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
  9675
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9676
    self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9677
	fillRectangleX:aRectangle left y:aRectangle top
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9678
	width:aRectangle width height:aRectangle height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9679
	withValue:aPixelValueOrNil
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9680
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9681
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9682
fillRectangleX:x y:y width:w height:h with:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9683
    "fill a rectangular area with a aColor"
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9684
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9685
    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
  9686
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9687
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9688
fillRectangleX:x y:y width:w height:h withValue:aPixelValueOrNil
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9689
    "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
  9690
     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
  9691
     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
  9692
     otherwise to 1. (used by the bitmap editor)"
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9693
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9694
    |xI "{ Class: SmallInteger }"
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9695
     yI "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9696
     wI "{ Class: SmallInteger }"
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9697
     hI "{ Class: SmallInteger }"
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9698
     p|
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9699
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9700
    xI := x.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9701
    yI := y.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9702
    wI := w.
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9703
    hI := h.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9704
    p := Point new.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9705
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9706
    yI to:yI+hI-1 do:[:yRun |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9707
	xI to:xI+wI-1 do:[:xRun |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9708
	    p x:xRun y:yRun.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9709
	    self atImageAndMask:p putValue:aPixelValueOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9710
	]
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9711
    ].
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9712
    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
  9713
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
  9714
    "Created: 22.4.1997 / 14:02:14 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
  9715
    "Modified: 24.4.1997 / 17:24:58 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9716
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9717
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9718
floodFillAt: aPoint withColor: aColor
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9719
    "fill a area with aColor like a flood up to surrounded pixels having different colors.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9720
     By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9721
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9722
    self floodFillAt:aPoint withValue:(self valueFromColor:aColor)
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9723
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9724
"/    |surroundingPixelsOfDo detectedPixel processPixelToFill
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9725
"/     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9726
"/     toDo idx pixel w h|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9727
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9728
"/    w := self width.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9729
"/    h := self height.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9730
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9731
"/    surroundingPixelsOfDo :=
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9732
"/        [:pX :pY :fn |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9733
"/            |nX nY|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9734
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9735
"/            nX := pX + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9736
"/            nY := pY + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9737
"/            (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
  9738
"/            (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
  9739
"/            (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
  9740
"/            (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
  9741
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9742
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9743
"/    enumerateDetectedPixelsAndDo :=
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9744
"/        [:detectedPixels :action |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9745
"/            |idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9746
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9747
"/            idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9748
"/            0 to:h-1 do:[:y |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9749
"/                0 to:w-1 do:[:x |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9750
"/                    (detectedPixels at:idx) ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9751
"/                        action value:x value:y
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9752
"/                    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9753
"/                    idx := idx + 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9754
"/                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9755
"/            ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9756
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9757
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9758
"/    processPixelToFill := [:spX :spY |
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9759
"/            |sp idx|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9760
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9761
"/            ((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
  9762
"/            ifTrue: [
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9763
"/                idx := 1 + spX + (spY * w).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9764
"/                (allDetectedPixelCoordinates at:idx) ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9765
"/                    allDetectedPixelCoordinates at:idx put:true.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9766
"/                    toDo add:spX @ spY.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9767
"/                ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9768
"/            ]
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9769
"/        ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9770
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9771
"/    (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
  9772
"/        allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9773
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9774
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9775
"/                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
  9776
"/        ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9777
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9778
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9779
"/    detectedPixel := self pixelAt: aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9780
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9781
"/    allDetectedPixelCoordinates := BooleanArray new:(w * h).
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9782
"/    toDo := OrderedCollection new:1000.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9783
"/    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
  9784
"/    toDo add:aPoint.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9785
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9786
"/    [toDo notEmpty] whileTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9787
"/        |p|
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9788
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9789
"/        p := toDo removeFirst.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9790
"/        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
  9791
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9792
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9793
"/    idx := 1.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9794
"/    aColor redByte notNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9795
"/        pixel := self valueFromColor:aColor.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9796
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9797
"/
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9798
"/    pixel isNil ifTrue:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9799
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9800
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9801
"/                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
  9802
"/    ] ifFalse:[
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9803
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9804
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9805
"/                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
  9806
"/    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9807
"/    ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9808
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9809
    "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
  9810
!
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9811
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9812
floodFillAt:aPoint withValue:aPixelValueOrNil
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9813
    "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
  9814
     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
  9815
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9816
    |surroundingPixelsOfDo detectedPixel detectedMask processPixelToFill
3861
e9cbd4ec6020 flood fill with mask fixed
Claus Gittinger <cg@exept.de>
parents: 3860
diff changeset
  9817
     allDetectedPixelCoordinates enumerateDetectedPixelsAndDo
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9818
     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
  9819
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9820
    w := self width.
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9821
    h := self height.
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9822
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9823
    surroundingPixelsOfDo :=
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9824
	[:pX :pY :fn |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9825
	    |nX nY|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9826
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9827
	    nX := pX + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9828
	    nY := pY + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9829
	    (nY < h) ifTrue: [fn value:pX value:nY].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9830
	    (pY > 0) ifTrue: [fn value:pX value:(pY - 1)].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9831
	    (nX < w) ifTrue: [fn value:nX value:pY].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9832
	    (pX > 0) ifTrue: [fn value:(pX - 1) value:pY].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9833
	].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9834
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9835
    enumerateDetectedPixelsAndDo :=
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9836
	[:detectedPixels :action |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9837
	    |idx|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9838
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9839
	    idx := 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9840
	    0 to:h-1 do:[:y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9841
		0 to:w-1 do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9842
		    (detectedPixels at:idx) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9843
			action value:x value:y
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9844
		    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9845
		    idx := idx + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9846
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9847
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9848
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9849
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9850
    processPixelToFill :=
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9851
	[:spX :spY |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9852
	    |samePixel sp idx|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9853
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9854
	    mask isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9855
		samePixel := (self pixelAtX:spX y:spY) == detectedPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9856
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9857
		detectedMask == 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9858
		    samePixel := (mask pixelAtX:spX y:spY) == 0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9859
		] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9860
		    samePixel := ((self pixelAtX:spX y:spY) == detectedPixel)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9861
				 and:[ (mask pixelAtX:spX y:spY) == detectedMask ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9862
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9863
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9864
	    samePixel ifTrue: [
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9865
		idx := 1 + spX + (spY * w).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9866
		(allDetectedPixelCoordinates at:idx) ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9867
		    allDetectedPixelCoordinates at:idx put:true.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9868
		    toDo add:spX @ spY.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9869
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9870
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9871
	].
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9872
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9873
"/    (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
  9874
"/        allDetectedPixelCoordinates := mask floodFillAt: aPoint withColor: Color white.
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9875
"/        enumerateDetectedPixelsAndDo
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9876
"/                value:allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9877
"/                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
  9878
"/        ^ allDetectedPixelCoordinates
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9879
"/    ].
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9880
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9881
    detectedPixel := self pixelAt: aPoint.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9882
    mask isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9883
	detectedMask := 1
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9884
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9885
	detectedMask := mask pixelAt: aPoint.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9886
    ].
4420
6b8505b72ae6 flood-filling of 24-bit images
Claus Gittinger <cg@exept.de>
parents: 4418
diff changeset
  9887
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  9888
    allDetectedPixelCoordinates := BooleanArray new:(w * h).
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9889
    toDo := OrderedCollection new:1000.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9890
    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
  9891
    toDo add:aPoint.
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9892
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
  9893
    [toDo notEmpty] whileTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9894
	|p|
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9895
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9896
	p := toDo removeLast.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9897
	surroundingPixelsOfDo value:p x value:p y value:processPixelToFill.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9898
    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9899
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9900
    aPixelValueOrNil isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9901
	drawAction := [:x :y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9902
			       mask pixelAtX:x y:y put:0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9903
			       self pixelAtX:x y:y put:0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9904
		      ].
3805
d87c919fb2a7 oops - care for filling a mask
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  9905
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9906
	drawAction := [:x :y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9907
				mask notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9908
				    mask pixelAtX:x y:y put:1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9909
				].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9910
				self pixelAtX:x y:y put:aPixelValueOrNil].
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9911
    ].
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9912
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9913
    enumerateDetectedPixelsAndDo
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9914
	value:allDetectedPixelCoordinates
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9915
	value:drawAction.
5138
4b834640de69 drawing and filling with a mask color
Claus Gittinger <cg@exept.de>
parents: 5135
diff changeset
  9916
5352
82a42045e996 changed:8 methods
Claus Gittinger <cg@exept.de>
parents: 5341
diff changeset
  9917
    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
  9918
    ^ allDetectedPixelCoordinates
2205
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9919
9209bc474af9 provide common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  9920
    "Modified: / 29.7.1998 / 03:09:16 / cg"
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9921
!
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9922
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9923
rectangle: aRectangle withColor:aColor
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
  9924
    <resource: #obsolete>
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9925
    "draw a rectangle with some pixel value.
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9926
    By using #atImageAndMask:put: it also works on images with mono masks."
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9927
2801
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9928
    self obsoleteMethodWarning.
9f71b58c0726 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2772
diff changeset
  9929
    self drawRectangle: aRectangle withColor:aColor
1972
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9930
c7eac5189bf5 additional draw methods.
tz
parents: 1963
diff changeset
  9931
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9932
! !
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  9933
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9934
!Image methodsFor:'enumerating'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9935
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9936
atY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9937
    "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
  9938
     The block is passed the color at each pixel.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9939
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9940
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9941
     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
  9942
     and also the color allocation)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9943
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  9944
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
  9945
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9946
    self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9947
    self colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9948
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9949
    "Modified: 7.6.1996 / 19:13:30 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9950
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9951
5143
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9952
colorsAtX:x from:y1 to:y2 do:aBlock
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9953
    "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
  9954
     The block is passed the color at each pixel.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9955
     The code here provides a generic and slow implementation, and
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9956
     should be redefined in concrete subclasses, to avoid some processing
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9957
     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
  9958
     and also the color allocation)."
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9959
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9960
    |yStart "{Class: SmallInteger }"
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9961
     yEnd   "{Class: SmallInteger }"|
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9962
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9963
    yStart := y1.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9964
    yEnd := y2.
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9965
    yStart to:yEnd do:[:yRun |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
  9966
	aBlock value:yRun value:(self colorAtX:x y:yRun)
5143
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9967
    ]
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9968
!
72147ced8f3c +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 5138
diff changeset
  9969
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9970
colorsAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9971
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9972
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9973
     The code here provides a generic and slow implementation, and
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9974
     should be redefined in concrete subclasses, to avoid some processing
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9975
     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
  9976
     and also the color allocation)."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9977
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9978
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9979
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9980
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9981
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9982
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9983
    xStart to:xEnd do:[:xRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
  9984
	aBlock value:xRun value:(self colorAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9985
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
  9986
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
  9987
    "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
  9988
    "Modified: / 30.9.1998 / 22:14:16 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9989
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9990
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9991
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9992
    "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
  9993
     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
  9994
     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
  9995
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9996
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9997
     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
  9998
     and especially, the color allocations)."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
  9999
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10000
    |yS "{Class: SmallInteger }"
942
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10001
     yE "{Class: SmallInteger }"
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10002
     yR|
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10003
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10004
    yS := yStart.
5e45da3c19d3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 940
diff changeset
 10005
    yE := yEnd.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10006
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10007
    yS to:yE do:[:yRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10008
	yR := yRun.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10009
	self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10010
	    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
 10011
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10012
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10013
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 10014
    "Modified: 11.7.1996 / 19:50:47 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10015
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10016
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10017
valueAtY:y from:x1 to:x2 do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10018
    "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
 10019
     Obsolete - remains for backward compatibility."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10020
3433
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10021
    <resource:#obsolete>
809312fa7e4f Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 3426
diff changeset
 10022
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10023
    self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10024
    self valuesAtY:y from:x1 to:x2 do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10025
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10026
    "Modified: 7.6.1996 / 19:11:06 / cg"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10027
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10028
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10029
valuesAtY:y from:x1 to:x2 do:aBlock
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10030
    "WARNING: for now, this enumerates pixel values
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10031
     (backward compatibility with ST/X)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10032
     In the future, this will enumerate colors
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10033
     Use #pixelAtT:from:to:do: - for future compatibility.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10034
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10035
     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
 10036
     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
 10037
     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
 10038
     (see also Image>>atY:from:to:do:).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10039
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10040
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10041
     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
 10042
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10043
    |xStart "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10044
     xEnd   "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10045
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10046
    xStart := x1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10047
    xEnd := x2.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10048
    xStart to:xEnd do:[:xRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10049
	aBlock value:xRun value:(self pixelAtX:xRun y:y)
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10050
    ]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 10051
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10052
    "Created: 7.6.1996 / 19:09:51 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10053
    "Modified: 24.4.1997 / 16:55:38 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10054
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10055
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10056
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10057
    "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
 10058
     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
 10059
     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
 10060
     The code here provides a generic and slow implementation, and
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10061
     should be redefined in concrete subclasses, to avoid some processing
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10062
     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
 10063
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10064
    |xS "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10065
     xE "{Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10066
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10067
    xS := xStart.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10068
    xE := xEnd.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10069
    yStart to:yEnd do:[:yRun |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10070
	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
 10071
	    aBlock value:xRun value:yRun value:pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10072
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10073
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10074
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 10075
    "Modified: 7.6.1996 / 19:09:29 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10076
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 10077
3613
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10078
!Image methodsFor:'finalization'!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10079
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10080
finalizationLobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10081
    "answer the registry used for finalization.
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10082
     Images have their own Registry"
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10083
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10084
    ^ Lobby
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10085
!
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10086
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10087
finalize
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10088
    "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
 10089
! !
75f91a51b919 Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents: 3611
diff changeset
 10090
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 10091
!Image methodsFor:'image manipulations'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 10092
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10093
applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10094
    "helper for withPixelFunctionAppliedToValues:
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 10095
     enumerate pixelValues and evaluate the block for each.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10096
     Could be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10097
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10098
    |w   "{Class: SmallInteger }"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10099
     h   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10100
     x0  "{Class: SmallInteger }"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10101
     y0  "{Class: SmallInteger }"
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10102
     y   "{Class: SmallInteger }"
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10103
     newPixel newPixelRow pixelRow|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10104
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10105
    x0 := aRectangle left.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10106
    y0 := aRectangle top.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10107
    w := aRectangle width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10108
    h := aRectangle height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10109
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10110
    newPixelRow := Array new:w.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10111
    pixelRow := self pixelArraySpecies new:width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10112
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10113
    (x0 = 0 and:[w = self width]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10114
	"/ slightly faster
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10115
	y := y0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10116
	h timesRepeat:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10117
	    self rowAt:y into:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10118
	    1 to:w do:[:runCol |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10119
		newPixel := pixelFunctionBlock
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10120
				value:self
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10121
				value:(pixelRow at:runCol)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10122
				value:(runCol-1)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10123
				value:y.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10124
		newPixelRow at:runCol put:newPixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10125
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10126
	    newImage rowAt:y putAll:newPixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10127
	    y := y + 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10128
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10129
	^ self.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10130
    ].
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10131
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10132
    y := y0.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10133
    h timesRepeat:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10134
	self rowAt:y into:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10135
	1 to:w do:[:runCol |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10136
	    newPixel := pixelFunctionBlock
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10137
			    value:self
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10138
			    value:(pixelRow at:runCol+x0)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10139
			    value:(runCol+x0-1)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10140
			    value:y.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10141
	    newPixelRow at:runCol put:newPixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10142
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10143
	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
 10144
	newImage rowAt:y putAll:pixelRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10145
	y := y + 1.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10146
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10147
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10148
    "Modified: 24.4.1997 / 16:18:31 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10149
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 10150
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10151
applyPixelValuesTo:pixelFunctionBlock into:newImage
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10152
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10153
     enumerate pixelValues and evaluate the block for each."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10154
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10155
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10156
	applyPixelValuesTo:pixelFunctionBlock
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10157
	in:(0@0 corner:width@height)
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10158
	into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10159
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 10160
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10161
blendWith:aColor
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10162
    "return a new image which is blended with some color.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10163
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10164
     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
 10165
     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
 10166
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10167
     ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10168
	copyWithColorMapProcessing:[:clr | clr blendWith:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10169
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10170
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10171
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10172
     ((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
 10173
     ((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
 10174
     ((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
 10175
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10176
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10177
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10178
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10179
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10180
colorMapProcessing:aBlock
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10181
    "a helper for all kinds of colormap manipulations.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10182
     The argument, aBlock is called for every colormap entry,
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10183
     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
 10184
     This will fail for non-palette images.
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10185
     See examples in Image>>copyWithColorMapProcessing:"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10186
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10187
    |nColors "{ Class: SmallInteger }"|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10188
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10189
    colorMap isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10190
	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
 10191
	    self colorAtX:x y:y put:(aBlock value:clr)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10192
	].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10193
	^ self
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10194
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10195
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10196
    nColors := colorMap size.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10197
    1 to:nColors do:[:index |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10198
	|clr|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10199
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10200
	clr := colorMap at:index.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10201
	clr notNil ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10202
	    colorMap at:index put:(aBlock value:clr)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10203
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10204
    ]
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10205
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 10206
    "Modified: 23.4.1996 / 11:13:55 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10207
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10208
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10209
copyWithColorMapProcessing:aBlock
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10210
    "a helper to create & return new images based on the receiver with
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10211
     some colorMap processing. The receiver is copied, and the copied images
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10212
     colormap is modified by replacing entries with the result of the processing block,
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10213
     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
 10214
     a color.
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10215
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale)"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10216
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10217
    |newImage|
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10218
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10219
    self colorMap isNil ifTrue:[
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10220
        ^ self withPixelFunctionApplied:[:orig :clr :x :y | aBlock  value:clr]
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10221
"/        self error:'no colormap in image'.
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10222
"/        ^ nil
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10223
    ].
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10224
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10225
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10226
     the code below manipulates the colormap.
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10227
     For non-palette images, special code is required
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10228
    "
4414
2c0f2ca53156 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4390
diff changeset
 10229
    newImage := self copy.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10230
    newImage colorMapProcessing:aBlock.
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10231
    ^ newImage
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10232
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10233
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10234
     leave red component only:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10235
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10236
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif')
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10237
        copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10238
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10239
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10240
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10241
     make it reddish:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10242
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10243
     |img imgYellow imgGreen imgBlue|
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10244
     img := (Image fromFile:'../../../expeccoNET/server/data/images/styles/eXept/defects.gif').
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10245
     imgYellow := img copyWithColorMapProcessing:[:clr | Color hue:(clr hue ? 0 + 60) light:clr light saturation:clr saturation].
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10246
     imgGreen := img copyWithColorMapProcessing:[:clr | Color hue:(clr hue ? 0 + 120) light:clr light saturation:clr saturation].
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10247
     imgBlue := img copyWithColorMapProcessing:[:clr | Color hue:(clr hue ? 0 + 240) light:clr light saturation:clr saturation].
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10248
     imgBlue
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10249
    "
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10250
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10251
    "
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10252
     make it reddish:
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10253
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10254
     (Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif')
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10255
        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
 10256
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10257
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10258
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10259
     invert:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10260
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10261
     (Image fromFile:'bitmaps/gifImages/claus.gif')
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10262
        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
 10263
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10264
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10265
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10266
     lighter:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10267
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10268
     (Image fromFile:'bitmaps/gifImages/claus.gif')
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10269
        copyWithColorMapProcessing:[:clr | |r g b|
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10270
                                                r := clr red.  g := clr green.  b := clr blue.
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10271
                                                Color red:(r + (100-r//2))
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10272
                                                      green:(g + (100-g//2))
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10273
                                                      blue:(b + (100-b//2))]
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10274
    "
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 10275
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10276
    "
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10277
     darker:
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10278
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10279
     (Image fromFile:'bitmaps/gifImages/claus.gif')
6653
aa954269f3ce class: Image
Claus Gittinger <cg@exept.de>
parents: 6648
diff changeset
 10280
        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
 10281
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10282
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10283
    "Modified: 24.4.1997 / 18:28:05 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10284
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 10285
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10286
createMask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10287
    |maskArray bytesPerMaskRow|
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10288
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10289
    bytesPerMaskRow := (width+7) // 8.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10290
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10291
    maskArray := ByteArray new:(bytesPerMaskRow * height) withAll:2r11111111.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10292
    mask := ImageMask width:width height:height fromArray:maskArray.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10293
    ^ mask
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10294
!
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 10295
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10296
darkened
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10297
    "return a new image which is slightly darker than the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10298
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10299
     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
 10300
     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
 10301
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 10302
     ^ self copyWithColorMapProcessing:[:clr | clr darkened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10303
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10304
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10305
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 10306
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10307
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10308
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 10309
    "Modified: / 24-11-2010 / 11:06:58 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10310
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10311
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10312
easyRotateBitsInto:destinationImage angle:degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10313
    "helper for rotation - does the actual pixel shuffling.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10314
     by degrees clockwise. Here, only 90, 180 and 270 degrees
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10315
     are implemented. Hard angles are done in #hardRotate:.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10316
     The code here is depth-independent (but not too fast);
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10317
     can be redefined in subclasses for more performance"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10318
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10319
    |w  "{Class: SmallInteger }"
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10320
     h  "{Class: SmallInteger }"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10321
     c2 r2 pixelArray|
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10322
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10323
    w := width - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10324
    h := height - 1.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10325
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10326
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10327
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10328
    degrees = 90 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10329
	0 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10330
	    self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10331
	    c2 := h-row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10332
	    0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10333
		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
 10334
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10335
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10336
	^ self.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10337
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10338
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10339
    degrees = 180 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10340
	0 to:h do:[:row |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10341
	    self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10342
	    r2 := h - row.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10343
	    0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10344
		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
 10345
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10346
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10347
	^ self
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10348
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10349
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10350
    "/ degrees = 270
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10351
    0 to:h do:[:row |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10352
	self rowAt:row into:pixelArray startingAt:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10353
	0 to:w do:[:col |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10354
	    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
 10355
	]
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10356
    ]
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10357
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10358
    "Created: 23.4.1997 / 14:36:45 / cg"
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10359
    "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
 10360
!
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 10361
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10362
flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10363
    "destructively inplace horizontal flip"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10364
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10365
    |h  "{Class: SmallInteger }"
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10366
     pixelArray|
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10367
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10368
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10369
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10370
    pixelArray := self pixelArraySpecies new:width.
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10371
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10372
    0 to:h do:[:row |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10373
	self rowAt:row into:pixelArray.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10374
	pixelArray reverse.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10375
	self rowAt:row putAll:pixelArray.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10376
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10377
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10378
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10379
	mask flipHorizontal
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10380
    ].
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10381
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10382
    "/ flush device info
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10383
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10384
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10385
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10386
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipHorizontal inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10387
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10388
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10389
    "Modified: 24.4.1997 / 18:29:13 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10390
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10391
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10392
flipVertical
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10393
    "inplace vertical flip"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10394
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10395
    |h           "{Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10396
     bytesPerRow "{Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10397
     buffer
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10398
     indexLow    "{Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10399
     indexHi     "{Class: SmallInteger }"
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10400
     bytes|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10401
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10402
    bytes := self bits.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10403
    bytesPerRow := self bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10404
    buffer := ByteArray new:bytesPerRow.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10405
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10406
    h := height - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10407
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10408
    indexLow := 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10409
    indexHi := bytesPerRow * h + 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10410
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10411
    0 to:(h // 2) do:[:row |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10412
	buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10413
	bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10414
	bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10415
	indexLow := indexLow + bytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10416
	indexHi := indexHi - bytesPerRow.
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10417
    ].
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10418
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 10419
	mask flipVertical
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10420
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10421
    "flush device info"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 10422
    self release
1386
51967fde82b7 also flip mask if present
Claus Gittinger <cg@exept.de>
parents: 1385
diff changeset
 10423
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10424
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10425
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') flipVertical inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10426
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10427
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10428
    "Modified: 24.4.1997 / 18:29:36 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10429
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10430
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10431
hardAntiAliasedMagnifiedBy:scalePoint
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10432
    "return a new image magnified and antiAliased by scalePoint, aPoint.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10433
     This converts into a depth24Image before doing the antiAlias-magnify.
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10434
     It is definitely slower than the non antiAliasing/integral magnification methods."
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10435
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10436
    ^ (Depth24Image fromImage:self)
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 10437
	hardAntiAliasedMagnifiedBy:scalePoint
1739
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10438
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10439
    "Modified: 2.6.1997 / 13:19:57 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10440
    "Created: 2.6.1997 / 15:53:34 / cg"
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10441
!
34165a3bb10b antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1737
diff changeset
 10442
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10443
hardMagnifiedBy:scalePoint
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10444
    "return a new image magnified by scalePoint, aPoint.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10445
     This is the general magnification method, handling non-integral values.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10446
     It is slower than the integral magnification method."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10447
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10448
    |mX
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10449
     mY
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10450
     newWidth  "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10451
     newHeight "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10452
     w         "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10453
     h         "{ Class: SmallInteger }"
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10454
     newImage newBits bitsPerPixel newBytesPerRow newMask
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10455
     value
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10456
     srcRow pixelArray|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10457
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10458
    mX := scalePoint x.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10459
    mY := scalePoint y.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10460
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10461
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10462
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10463
    newWidth := (width * mX) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10464
    newHeight := (height * mY) truncated.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10465
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10466
    bitsPerPixel := self depth.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10467
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10468
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10469
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10470
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10471
	newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10472
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 10473
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10474
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10475
    newImage
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10476
	width:newWidth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10477
	height:newHeight
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10478
	photometric:photometric
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10479
	samplesPerPixel:samplesPerPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10480
	bitsPerSample:bitsPerSample
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10481
	colorMap:colorMap copy
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10482
	bits:newBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10483
	mask:newMask.
905
228d503775d9 everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
 10484
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10485
    "walk over destination image fetching pixels from source image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10486
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10487
    w := newWidth - 1.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10488
    h := newHeight - 1.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10489
    pixelArray := newImage pixelArraySpecies new:newWidth.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10490
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10491
    0 to:h do:[:row |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10492
	srcRow := (row // mY).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10493
	0 to:w do:[:col |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10494
	    value := self pixelAtX:(col // mX) y:srcRow.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10495
	    pixelArray at:(col+1) put:value.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10496
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10497
	newImage rowAt:row putAll:pixelArray.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10498
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10499
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10500
    ^ newImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10501
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10502
    "
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10503
     |i|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 10504
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 10505
     Time millisecondsToRun:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10506
	 i := i hardMagnifiedBy:0.5@0.5
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10507
     ].
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10508
     i
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10509
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10510
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 10511
    "Modified: 24.4.1997 / 18:30:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10512
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10513
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 10514
hardRotated:degrees
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10515
    "return a new image from the old one, by rotating the image
4953
b5017336aa26 comment
Claus Gittinger <cg@exept.de>
parents: 4952
diff changeset
 10516
     degrees clockwise (around its center).
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10517
     Warning: the returned image will be larger than the original image."
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10518
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10519
    |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
 10520
     newImage
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10521
     newWidth  "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10522
     newHeight "{ Class: SmallInteger }"
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10523
     newBytesPerRow newBits
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10524
     blackPixel halfW halfH radians m t bad
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10525
     bytesPerRow myDepth maskBits
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10526
     pX pY srcX srcY pix nX nY
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10527
     sinRot cosRot sinPY cosPY|
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10528
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10529
    radians := degrees degreesToRadians.
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10530
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10531
    "/ placing the image at the origin,
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10532
    "/ compute the diagonal and angle.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10533
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10534
    p := (width - 1 / 2) @ (height - 1 / 2).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10535
    r := p r.
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10536
    a := p theta.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10537
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10538
    "/ add the rotation
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10539
    "/ (sight - subtract, we defined things clockwise ...
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10540
    "/  ... in contrast to point which thinks counter-clockwise)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10541
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10542
    aN := a - radians.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10543
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10544
    "/ compute new corner points
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10545
    p1 := Point r:r theta:aN.         "/ rotated topRight
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 10546
    p2 := Point r:r theta:aN-a-a.     "/ rotated bottomRight
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10547
    p3 := p1 * -1.                    "/ rotated bottomLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10548
    p4 := p2 * -1.                    "/ rotated topLeft
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10549
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10550
    "/ compute the boundary of the new image
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10551
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10552
    maxX := minX := p1 x.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10553
    (t := p2 x) > maxX ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10554
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10555
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10556
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10557
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10558
    (t := p3 x) > maxX ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10559
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10560
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10561
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10562
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10563
    (t := p4 x) > maxX ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10564
	maxX := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10565
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10566
	t < minX ifTrue:[minX := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10567
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10568
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10569
    maxY := minY := p1 y.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10570
    (t := p2 y) > maxY ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10571
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10572
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10573
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10574
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10575
    (t := p3 y) > maxY ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10576
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10577
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10578
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10579
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10580
    (t := p4 y) > maxY ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10581
	maxY := t
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10582
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10583
	t < minY ifTrue:[minY := t].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10584
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10585
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10586
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10587
    newWidth := (maxX - minX) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10588
    newHeight := (maxY - minY) rounded + 1.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10589
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10590
    newImage := self species new.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10591
    newImage width:newWidth.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10592
    newImage height:newHeight.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10593
    newBytesPerRow := newImage bytesPerRow.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10594
    newImage createPixelStore.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 10595
    newBits := newImage bits.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10596
    newImage photometric:photometric.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10597
    newImage samplesPerPixel:samplesPerPixel.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10598
    newImage bitsPerSample:bitsPerSample.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10599
    newImage colorMap:colorMap copy.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10600
    newImage maskedPixelsAre0:maskedPixelsAre0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10601
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10602
	newImage mask:(mask rotated:degrees)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10603
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10604
	self isMask ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10605
	    self depth ~~ 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10606
		m := ImageMask width:width height:height.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10607
		m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10608
		maskBits atAllPut:16rFF.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10609
		newImage mask:(m rotated:degrees)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10610
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10611
	]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10612
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10613
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10614
    myDepth := self depth.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10615
    myDepth == 1 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10616
	blackPixel := 0.
4951
325ab0ba9376 background in hardRotated:
Claus Gittinger <cg@exept.de>
parents: 4937
diff changeset
 10617
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10618
	maskedPixelsAre0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10619
	    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10620
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10621
	    blackPixel := self valueFromColor:Color black.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10622
	    blackPixel isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10623
		blackPixel := self valueFromColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10624
		blackPixel isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10625
		    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10626
		]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10627
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10628
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10629
	self isMask ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10630
	    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10631
	].
4951
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
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10634
    newBits atAllPut:0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10635
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10636
    "/ now, walk over destination pixels,
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10637
    "/ fetching from source.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10638
    "/ (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
 10639
    "/  in the destination image ...)
1638
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
    halfW := (width - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10642
    halfH := (height - 1) / 2.0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10643
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10644
    bytesPerRow := self bytesPerRow.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10645
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10646
%{
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10647
    int __newHeight = __intVal(newHeight);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10648
    int __newWidth = __intVal(newWidth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10649
    int __height = __intVal(__INST(height));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10650
    int __width = __intVal(__INST(width));
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10651
    double __minX, __minY, __radians;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10652
    double __halfW, __halfH;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10653
    int __dstX, __dstY;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10654
    int __depth = __intVal(myDepth);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10655
    unsigned char *__srcBytes, *__dstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10656
    unsigned char *__dstPtr, *__dstRowPtr, *__dstEndPtr;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10657
    int __nSrcBytes, __nDstBytes;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10658
    int __srcBytesPerRow = __intVal(bytesPerRow);
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10659
    int __dstBytesPerRow = __intVal(newBytesPerRow);
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10660
    int __dstMask, __blackPixel;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10661
    double __sin, __cos;
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10662
    double sin(), cos();
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10663
#   define Float_PI 3.14159
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10664
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10665
    bad = true;
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10666
    if (1
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 10667
     && __isFloat(minX)
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10668
     && __isFloat(minY)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10669
     && __isFloat(radians)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10670
     && __isFloat(halfW)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10671
     && __isFloat(halfH)
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10672
     && __isByteArray(newBits)
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 10673
     && __isByteArrayLike(__INST(bytes))) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10674
	__srcBytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10675
	__dstBytes = __ByteArrayInstPtr(newBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10676
	__nSrcBytes = __byteArraySize(__INST(bytes));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10677
	__nDstBytes = __byteArraySize(newBits);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10678
	__blackPixel = __intVal(blackPixel);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10679
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10680
	__radians = __floatVal(radians);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10681
	__radians = -__radians; /* sigh: clock-wise */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10682
	__sin = sin(__radians);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10683
	__cos = cos(__radians);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10684
	__minX = __floatVal(minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10685
	__minY = __floatVal(minY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10686
	__halfW = __floatVal(halfW);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10687
	__halfH = __floatVal(halfH);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10688
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10689
	__dstRowPtr = __dstBytes;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10690
	__dstEndPtr = __dstBytes + __nDstBytes;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10691
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10692
#       define EARLY_OUT
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10693
#       define FAST_ADVANCE 5
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10694
#       define FAST_ADVANCE2
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10695
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10696
	switch (__depth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10697
	    case 8:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10698
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10699
		    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10700
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10701
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10702
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10703
		    __pY = (double)(__dstY + __minY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10704
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10705
		    __sinPY = __sin * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10706
		    __cosPY = __cos * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10707
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10708
		    __dstPtr = __dstRowPtr;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10709
		    __dstRowPtr += __dstBytesPerRow;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10710
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10711
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10712
			double __pX, __nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10713
			unsigned __pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10714
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10715
			/* translate X in destination (center to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10716
			__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10717
			/* rotate X */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10718
			__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10719
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10720
			/* translate X in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10721
			__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10722
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10723
			/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10724
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10725
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10726
			    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10727
				break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10728
			    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10729
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10730
#ifdef FAST_ADVANCE
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10731
			    if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10732
				do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10733
				    /* try advance by FAST_ADVANCE pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10734
				    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10735
				    if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10736
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10737
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10738
				    __pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10739
				    __nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10740
				    __nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10741
				} while (__nX < 0);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10742
				__dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10743
			    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10744
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10745
			    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10746
			} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10747
			    int __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10748
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10749
			    __srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10750
			    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10751
			    if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10752
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10753
				if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10754
				    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10755
				}
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10756
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10757
#ifdef FAST_ADVANCE2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10758
				if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10759
				    do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10760
					/* try advance by FAST_ADVANCE pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10761
					__dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10762
					if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10763
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10764
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10765
					__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10766
					__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10767
					__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10768
					__srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10769
				    } while (__srcX >= __width);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10770
				    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10771
				}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10772
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10773
				__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10774
			    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10775
				double __nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10776
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10777
				/* rotate Y */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10778
				__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10779
				/* translate Y in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10780
				__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10781
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10782
				/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10783
				if (__nY < 0) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10784
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10785
				    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10786
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10787
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10788
#endif
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10789
#ifdef FAST_ADVANCE2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10790
				    if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10791
					do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10792
					    /* try advance by FAST_ADVANCE pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10793
					    __dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10794
					    if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10795
						break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10796
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10797
					    __pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10798
					    __nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10799
					    __nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10800
					} while (__nY < 0);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10801
					__dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10802
				    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10803
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10804
				    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10805
				} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10806
				    int __srcY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10807
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10808
				    __srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10809
				    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10810
				    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10811
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10812
					if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10813
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10814
					}
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10815
#endif
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10816
#ifdef FAST_ADVANCE
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10817
					if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10818
					    do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10819
						/* try advance by FAST_ADVANCE pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10820
						__dstX += FAST_ADVANCE; __dstPtr += FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10821
						if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10822
						    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10823
						}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10824
						__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10825
						__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10826
						__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10827
						__srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10828
					    } while (__srcY >= __height);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10829
					    __dstX -= FAST_ADVANCE; __dstPtr -= FAST_ADVANCE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10830
					}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10831
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10832
					__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10833
				    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10834
					/* fetch source pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10835
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10836
					int idx;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10837
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10838
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10839
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10840
					idx = __srcY * __srcBytesPerRow + __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10841
					if ((unsigned)idx < __nSrcBytes) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10842
					    __pix = __srcBytes[idx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10843
					} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10844
					    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10845
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10846
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10847
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10848
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10849
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10850
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10851
			if (__pix != 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10852
			    *__dstPtr = __pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10853
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10854
			__dstPtr++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10855
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10856
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10857
		break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10858
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10859
	    case 1:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10860
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10861
		    double __pY, __sinPY, __cosPY;
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10862
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10863
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10864
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10865
		    __pY = (double)(__dstY + __minY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10866
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10867
		    __sinPY = __sin * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10868
		    __cosPY = __cos * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10869
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10870
		    __dstPtr = __dstRowPtr;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10871
		    __dstMask = 0x80;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10872
		    __dstRowPtr += __dstBytesPerRow;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10873
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10874
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10875
			double __pX, __nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10876
			int __pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10877
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10878
			/* translate X in destination (center to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10879
			__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10880
			/* rotate X */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10881
			__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10882
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10883
			/* translate X in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10884
			__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10885
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10886
			/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10887
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10888
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10889
			    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10890
				break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10891
			    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10892
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10893
#ifdef FAST_ADVANCE
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10894
			    if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10895
				do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10896
				    /* try advance by 8 pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10897
				    __dstX += 8; __dstPtr ++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10898
				    if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10899
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10900
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10901
				    __pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10902
				    __nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10903
				    __nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10904
				} while (__nX < 0);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10905
				__dstX -= 8; __dstPtr--;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10906
			    }
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 10907
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10908
			    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10909
			} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10910
			    int __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10911
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10912
			    __srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10913
			    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10914
			    if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10915
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10916
				if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10917
				    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10918
				}
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10919
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10920
#ifdef FAST_ADVANCE2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10921
				if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10922
				    do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10923
					/* try advance by 8 pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10924
					__dstX += 8; __dstPtr++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10925
					if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10926
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10927
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10928
					__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10929
					__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10930
					__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10931
					__srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10932
				    } while (__srcX >= __width);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10933
				    __dstX -= 8; __dstPtr--;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10934
				}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10935
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10936
				__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10937
			    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10938
				double __nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10939
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10940
				/* rotate Y */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10941
				__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10942
				/* translate Y in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10943
				__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10944
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10945
				/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10946
				if (__nY < 0) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10947
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10948
				    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10949
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10950
				    }
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10951
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10952
#ifdef FAST_ADVANCE2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10953
				    if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10954
					do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10955
					    /* try advance by 8 pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10956
					    __dstX += 8; __dstPtr++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10957
					    if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10958
						break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10959
					    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10960
					    __pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10961
					    __nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10962
					    __nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10963
					} while (__nY < 0);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10964
					__dstX -= 8; __dstPtr--;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10965
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 10966
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10967
				    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10968
				} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10969
				    int __srcY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10970
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10971
				    __srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10972
				    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10973
				    if (__srcY >= __height) {
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 10974
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10975
					if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10976
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10977
					}
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10978
#endif
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 10979
#ifdef FAST_ADVANCE
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10980
					if (__blackPixel == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10981
					    do {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10982
						/* try advance by 8 pixels ... */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10983
						__dstX += 8; __dstPtr++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10984
						if (__dstX >= __newWidth) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10985
						    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10986
						}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10987
						__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10988
						__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10989
						__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10990
						__srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10991
					    } while (__srcY >= __height);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10992
					    __dstX -= 8; __dstPtr--;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10993
					}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 10994
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10995
					__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10996
				    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10997
					/* fetch source pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10998
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 10999
					int idx, pV;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11000
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11001
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11002
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11003
					idx = __srcY * __srcBytesPerRow + (__srcX >> 3);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11004
					if ((unsigned)idx < __nSrcBytes) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11005
					    pV = __srcBytes[idx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11006
					    __pix = (pV & (0x80 >> (__srcX & 7))) ? 1 : 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11007
					} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11008
					    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11009
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11010
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11011
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11012
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11013
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11014
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11015
			/* store pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11016
			if (__pix != 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11017
			    *__dstPtr |= __dstMask;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11018
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11019
			__dstMask >>= 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11020
			if (__dstMask == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11021
			    __dstMask = 0x80;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11022
			    __dstPtr++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11023
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11024
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11025
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11026
		break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11027
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11028
	    case 24:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11029
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11030
		    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11031
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11032
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11033
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11034
		    __pY = (double)(__dstY + __minY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11035
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11036
		    __sinPY = __sin * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11037
		    __cosPY = __cos * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11038
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11039
		    __dstPtr = __dstRowPtr;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11040
		    __dstRowPtr += __dstBytesPerRow;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11041
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11042
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11043
			double __pX, __nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11044
			unsigned __pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11045
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11046
			/* translate X in destination (center to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11047
			__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11048
			/* rotate X */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11049
			__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11050
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11051
			/* translate X in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11052
			__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11053
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11054
			/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11055
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11056
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11057
			    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11058
				break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11059
			    }
1639
c47081269ada faster rotation - early break from loop
Claus Gittinger <cg@exept.de>
parents: 1638
diff changeset
 11060
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11061
			    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11062
			} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11063
			    int __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11064
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11065
			    __srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11066
			    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11067
			    if (__srcX >= __width) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11068
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11069
				if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11070
				    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11071
				}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11072
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11073
				__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11074
			    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11075
				double __nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11076
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11077
				/* rotate Y */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11078
				__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11079
				/* translate Y in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11080
				__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11081
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11082
				/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11083
				if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11084
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11085
				    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11086
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11087
				    }
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11088
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11089
				    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11090
				} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11091
				    int __srcY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11092
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11093
				    __srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11094
				    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11095
				    if (__srcY >= __height) {
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11096
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11097
					if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11098
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11099
					}
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11100
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11101
					__pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11102
				    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11103
					/* fetch source pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11104
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11105
					int idx;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11106
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11107
					didFetchInRow = 1;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11108
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11109
					idx = __srcY * __srcBytesPerRow + __srcX + __srcX + __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11110
					if ((unsigned)idx < __nSrcBytes) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11111
					    __pix = __srcBytes[idx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11112
					    __pix = (__pix<<8) | __srcBytes[idx+1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11113
					    __pix = (__pix<<8) | __srcBytes[idx+2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11114
					} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11115
					    __pix = __blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11116
					}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11117
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11118
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11119
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11120
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11121
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11122
			/* store pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11123
			if (__pix != 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11124
			    __dstPtr[0] = (__pix >> 16 & 0xFF);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11125
			    __dstPtr[1] = (__pix >> 8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11126
			    __dstPtr[2] = __pix & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11127
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11128
			__dstPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11129
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11130
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11131
		break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11132
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11133
	    default:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11134
		for (__dstY = 0; __dstY < __newHeight; __dstY++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11135
		    double __pY, __sinPY, __cosPY;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11136
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11137
		    int didFetchInRow = 0;
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11138
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11139
		    __pY = (double)(__dstY + __minY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11140
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11141
		    __sinPY = __sin * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11142
		    __cosPY = __cos * __pY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11143
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11144
		    __dstPtr = __dstRowPtr;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11145
		    __dstMask = 0x80;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11146
		    __dstRowPtr += __dstBytesPerRow;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11147
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11148
		    for (__dstX = 0; __dstX < __newWidth; __dstX++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11149
			double __pX, __nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11150
			OBJ __pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11151
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11152
			/* translate X in destination (center to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11153
			__pX = (double)(__dstX + __minX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11154
			/* rotate X */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11155
			__nX = (__cos * __pX) - __sinPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11156
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11157
			/* translate X in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11158
			__nX = __nX + __halfW + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11159
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11160
			/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11161
			if (__nX < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11162
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11163
			    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11164
				break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11165
			    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11166
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11167
			    __pix = blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11168
			} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11169
			    int __srcX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11170
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11171
			    __srcX = (int)__nX;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11172
			    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11173
			    if (__srcX >= __width) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11174
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11175
				if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11176
				    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11177
				}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11178
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11179
				__pix = blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11180
			    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11181
				double __nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11182
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11183
				/* rotate Y */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11184
				__nY = (__sin * __pX) + __cosPY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11185
				/* translate Y in source (origin to 0/0) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11186
				__nY = __nY + __halfH + 0.5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11187
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11188
				/* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11189
				if (__nY < 0) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11190
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11191
				    if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11192
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11193
				    }
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11194
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11195
				    __pix = blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11196
				} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11197
				    int __srcY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11198
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11199
				    __srcY = (int)__nY;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11200
				    /* inside ? */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11201
				    if (__srcY >= __height) {
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11202
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11203
					if (didFetchInRow) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11204
					    break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11205
					}
1642
c14ef12246aa improved hardRotate
Claus Gittinger <cg@exept.de>
parents: 1640
diff changeset
 11206
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11207
					__pix = blackPixel;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11208
				    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11209
					/* fetch source pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11210
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11211
					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
 11212
#ifdef EARLY_OUT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11213
					didFetchInRow = 1;
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11214
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11215
					__pix = (*valAt.ilc_func)(self,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11216
							      @symbol(pixelAtX:y:),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11217
							      nil, &valAt,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11218
							      __MKSMALLINT(__srcX),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11219
							      __MKSMALLINT(__srcY));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11220
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11221
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11222
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11223
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11224
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11225
			/* store pixel */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11226
			{
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11227
			    static struct inlineCache atPutVal = _ILC3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11228
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11229
			    if (__pix != __MKSMALLINT(0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11230
				(*atPutVal.ilc_func)(newImage,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11231
						      @symbol(pixelAtX:y:put:),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11232
						      nil, &atPutVal,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11233
						      __MKSMALLINT(__dstX),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11234
						      __MKSMALLINT(__dstY),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11235
						      __pix
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11236
						     );
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11237
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11238
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11239
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11240
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11241
		break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11242
	}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11243
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11244
	bad = false;
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11245
    }
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11246
%}.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11247
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11248
    bad ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11249
	"/ should not happen
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11250
	self primitiveFailed
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11251
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11252
"/        sinRot := radians negated sin.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11253
"/        cosRot := radians negated cos.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11254
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11255
"/        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
 11256
"/            pY := (dstY + minY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11257
"/            sinPY := (sinRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11258
"/            cosPY := (cosRot * pY).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11259
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11260
"/            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
 11261
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11262
"/                "/ translate center to origin
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11263
"/                pX := (dstX + minX).
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11264
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11265
"/                nX := (cosRot * pX) - sinPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11266
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11267
"/                "/ translate in source
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11268
"/                srcX := nX + halfW.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11269
"/                srcX := srcX rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11270
"/                "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11271
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11272
"/                (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
 11273
"/                    nY := (sinRot * pX) + cosPY.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11274
"/                    srcY := nY + halfH.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11275
"/                    srcY := srcY rounded.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11276
"/
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11277
"/                    "/ inside ?
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11278
"/                    (srcY >= 0 and:[srcY < height]) ifTrue:[
1660
67a3a6eab23a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1653
diff changeset
 11279
"/                        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
 11280
"/                    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11281
"/                        pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11282
"/                    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11283
"/                ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11284
"/                    pix := blackPixel.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11285
"/                ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11286
"/                pix ~~ blackPixel ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11287
"/                    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
 11288
"/                ]
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11289
"/            ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 11290
"/        ].
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11291
    ].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11292
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11293
    ^ newImage
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11294
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11295
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11296
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11297
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11298
     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
 11299
     i inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11300
     (i rotated:45) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11301
     (i rotated:90) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11302
     (i rotated:91) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11303
     (i rotated:95) inspect.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11304
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11305
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11306
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11307
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11308
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11309
     i := Depth24Image fromImage:i.
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11310
     (i rotated:200) inspect
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11311
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11312
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11313
     |i|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11314
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11315
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11316
     Transcript showCR:(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11317
	Time millisecondsToRun:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11318
	   i rotated:45.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11319
	]
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11320
     ).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11321
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11322
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11323
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11324
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11325
     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
 11326
     v := View new extent:(i width max:100)@(i height max:100).
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11327
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11328
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11329
     [true] whileTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11330
	rI := i rotated:rot.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11331
	rI := rI onDevice:v device.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11332
	v clear.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11333
	v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11334
	rot := rot + 5.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11335
	rI close.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11336
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11337
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11338
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11339
     |v i rI rot|
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11340
4108
117f170e2122 Use #theta inseat of obsolete #angle.
Stefan Vogel <sv@exept.de>
parents: 4033
diff changeset
 11341
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/claus.gif' inPackage:'stx:goodies'.
1653
7ab13998d4cd d24 rotation fixed
Claus Gittinger <cg@exept.de>
parents: 1650
diff changeset
 11342
     v := View new extent:400@400.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11343
     v openAndWait.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11344
     rot := 0.
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11345
     [true] whileTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11346
	rI := i rotated:rot.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11347
	rI := rI onDevice:v device.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11348
	v clear.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11349
	v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11350
	rot := rot + 5.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11351
	rI close.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11352
     ]
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11353
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11354
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11355
     |v i rI rot|
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11356
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11357
     i := Form width:200 height:100 onDevice:Screen current.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11358
     i clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11359
     i displayLineFrom:(0@0) to:(199@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11360
     i displayLineFrom:(199@0) to:(199@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11361
     i displayLineFrom:(199@99) to:(0@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11362
     i displayLineFrom:(0@99) to:(0@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11363
     i displayLineFrom:(0@0) to:(199@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11364
     i displayLineFrom:(199@0) to:(0@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11365
     i := Image fromForm:i.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11366
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11367
     v := View new extent:400@400.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11368
     v openAndWait.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11369
     rot := 0.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11370
     [true] whileTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11371
	rI := i rotated:rot.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11372
	rI := rI onDevice:v device.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11373
	v clear.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11374
	v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11375
	rot := rot + 5.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11376
	rI close.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11377
	Delay waitForSeconds:0.1.
4952
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11378
     ]
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11379
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11380
    "
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11381
     |v i rI rot|
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11382
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11383
     i := Form width:200 height:100 onDevice:Screen current.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11384
     i clear.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11385
     i displayLineFrom:(0@0) to:(199@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11386
     i displayLineFrom:(199@0) to:(199@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11387
     i displayLineFrom:(199@99) to:(0@99).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11388
     i displayLineFrom:(0@99) to:(0@0).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11389
     i displayLineFrom:(0@0) to:(199@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11390
     i displayLineFrom:(199@0) to:(0@100).
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11391
     i := Image fromForm:i.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11392
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11393
     v := View new extent:400@400.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11394
     v openAndWait.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11395
     rot := 0.
5ff75dd16301 comment in hardRotated
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
 11396
     [true] whileTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11397
	rI := i rotated:rot.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11398
	rI := rI onDevice:v device.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11399
	v clear.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11400
	v displayForm:rI x:(v width-rI width)//2 y:(v height-rI height)//2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11401
	rot := rot + 30.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11402
	rI close.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11403
	Delay waitForSeconds:0.3.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11404
     ]
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11405
    "
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11406
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11407
    "Modified: 22.4.1997 / 17:36:37 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11408
!
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11409
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11410
lightened
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11411
    "return a new image which is slightly brighter than the receiver.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11412
     The receiver must be a palette image (currently).
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11413
     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
 11414
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11415
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 11416
    ^ self copyWithColorMapProcessing:[:clr | clr lightened]
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11417
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11418
    "
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11419
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11420
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11421
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11422
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11423
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11424
5655
37bd5c7eb765 comment/format in:
Claus Gittinger <cg@exept.de>
parents: 5643
diff changeset
 11425
    "Modified: / 24-11-2010 / 11:17:55 / cg"
54
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11426
!
29a6b2f8e042 *** empty log message ***
claus
parents: 46
diff changeset
 11427
134
claus
parents: 132
diff changeset
 11428
magnifiedBy:scale
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11429
    "return a new image magnified by scalePoint, aPoint.
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 11430
     If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:'
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
 11431
     while simple (integral) magnifications are handled here."
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11432
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11433
    |scalePoint mX mY
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11434
     magX      "{ Class: SmallInteger }"   "new version of stc can find this out itself..."
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11435
     magY      "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11436
     srcOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11437
     dstOffset "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11438
     w         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11439
     h         "{ Class: SmallInteger }"
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11440
     first
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11441
     newWidth newHeight newImage newBits newMask
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11442
     bitsPerPixel newBytesPerRow oldBytesPerRow
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11443
     bytes|
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11444
81
4ba554473294 *** empty log message ***
claus
parents: 77
diff changeset
 11445
    scalePoint := scale asPoint.
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11446
    mX := scalePoint x.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11447
    mY := scalePoint y.
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11448
    ((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11449
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
48194c26a46c Initial revision
claus
parents:
diff changeset
 11450
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11451
    ((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11452
	^ self hardMagnifiedBy:scalePoint
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11453
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11454
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 11455
    bytes := self bits.
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11456
    bitsPerPixel := self depth.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11457
    oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 11458
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11459
    w := width.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11460
    h := height.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11461
    magX := mX.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11462
    magY := mY.
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11463
2772
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11464
    newWidth := w * magX.
e8ceedf9aeab code cleanup & a few more SmallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2760
diff changeset
 11465
    newHeight := h * magY.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11466
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
48194c26a46c Initial revision
claus
parents:
diff changeset
 11467
    newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight).
48194c26a46c Initial revision
claus
parents:
diff changeset
 11468
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11469
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11470
	newMask := (mask magnifiedBy:scalePoint)
906
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11471
    ].
628a0e73b570 comment & mask:
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
 11472
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11473
    newImage := self species new.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11474
    newImage
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11475
	width:newWidth
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11476
	height:newHeight
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11477
	photometric:photometric
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11478
	samplesPerPixel:samplesPerPixel
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11479
	bitsPerSample:bitsPerSample
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11480
	colorMap:colorMap copy
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11481
	bits:newBits
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11482
	mask:newMask.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11483
48194c26a46c Initial revision
claus
parents:
diff changeset
 11484
    mX = 1 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11485
	"expand rows only"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11486
	srcOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11487
	dstOffset := 1.
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
	1 to:h do:[:row |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11490
	    1 to:magY do:[:i |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11491
		newBits replaceFrom:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11492
			to:(dstOffset + oldBytesPerRow - 1)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11493
			with:bytes
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11494
			startingAt:srcOffset.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11495
		dstOffset := dstOffset + newBytesPerRow
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11496
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11497
	    srcOffset := srcOffset + oldBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11498
	].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11499
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11500
	"expand cols"
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11501
	(mX > 1) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11502
	    dstOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11503
	    srcOffset := 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11504
	    1 to:h do:[:row |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11505
		self magnifyRowFrom:bytes
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11506
		     offset:srcOffset
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11507
		     into:newBits
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11508
		     offset:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11509
		     factor:mX.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11510
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11511
		first := dstOffset.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11512
		dstOffset := dstOffset + newBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11513
		" and copy for row expansion "
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11514
		2 to:magY do:[:i |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11515
		    newBits replaceFrom:dstOffset
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11516
			    to:(dstOffset + newBytesPerRow - 1)
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11517
			    with:newBits
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11518
			    startingAt:first.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11519
		    dstOffset := dstOffset + newBytesPerRow
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11520
		].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11521
		srcOffset := srcOffset + oldBytesPerRow.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11522
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11523
	]
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 11524
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
 11525
    ^ newImage
48194c26a46c Initial revision
claus
parents:
diff changeset
 11526
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11527
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11528
     ((Image fromFile:'goodies/bitmaps/gifImages/claus.gif') magnifiedBy:1@2)
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11529
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11530
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11531
    "Modified: 24.4.1997 / 18:32:04 / cg"
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11532
!
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 11533
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11534
magnifiedPreservingRatioTo:anExtent
154
claus
parents: 153
diff changeset
 11535
    "return a new image magnified to fit into anExtent,
claus
parents: 153
diff changeset
 11536
     preserving the receivers width/height ratio.
claus
parents: 153
diff changeset
 11537
     (i.e. not distorting the image).
claus
parents: 153
diff changeset
 11538
     See also #magnifiedTo: and #magnifiedBy:"
claus
parents: 153
diff changeset
 11539
claus
parents: 153
diff changeset
 11540
    |rX rY|
claus
parents: 153
diff changeset
 11541
claus
parents: 153
diff changeset
 11542
    rX := anExtent x / self width.
claus
parents: 153
diff changeset
 11543
    rY := anExtent y / self height.
claus
parents: 153
diff changeset
 11544
    ^ self magnifiedBy:(rX min:rY)
claus
parents: 153
diff changeset
 11545
claus
parents: 153
diff changeset
 11546
    "
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11547
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
154
claus
parents: 153
diff changeset
 11548
claus
parents: 153
diff changeset
 11549
    in contrast to:
claus
parents: 153
diff changeset
 11550
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11551
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11552
    "
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11553
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 11554
    "Modified: 22.4.1997 / 12:33:46 / cg"
154
claus
parents: 153
diff changeset
 11555
!
claus
parents: 153
diff changeset
 11556
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11557
magnifiedTo:anExtent
154
claus
parents: 153
diff changeset
 11558
    "return a new image magnified to have the size specified by extent.
claus
parents: 153
diff changeset
 11559
     This may distort the image if the arguments ratio is not the images ratio.
claus
parents: 153
diff changeset
 11560
     See also #magnifiedPreservingRatioTo: and #magnifiedBy:"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11561
134
claus
parents: 132
diff changeset
 11562
    ^ self magnifiedBy:(anExtent / self extent)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11563
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11564
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11565
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedTo:100@100)
154
claus
parents: 153
diff changeset
 11566
claus
parents: 153
diff changeset
 11567
    in contrast to:
claus
parents: 153
diff changeset
 11568
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 11569
     ((Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') magnifiedPreservingRatioTo:100@100)
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11570
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11571
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 11572
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11573
mixed:amount with:aColor
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11574
    "return a new image which is blended with some color;
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11575
     amount determines how much of the blending color is applied (0..)
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11576
     where 0 means: blending color pure.
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11577
     The receiver must be a palette image (currently).
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11578
     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
 11579
     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
 11580
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11581
     ^ self
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 11582
	copyWithColorMapProcessing:[:clr | clr mixed:amount with:aColor]
3256
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11583
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11584
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11585
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11586
     ((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
 11587
     ((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
 11588
     ((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
 11589
     ((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
 11590
     ((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
 11591
     ((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
 11592
     ((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
 11593
    "
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11594
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11595
    "Modified: 24.4.1997 / 18:31:23 / cg"
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11596
!
77bb9ec36221 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3157
diff changeset
 11597
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11598
negative
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11599
    "return a new image which is a negative of the receiver.
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11600
     The receiver must be a palette image (currently)."
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11601
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11602
    |newImage|
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11603
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11604
    colorMap isNil ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11605
	photometric == #blackIs0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11606
	    newImage := self copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11607
	    newImage photometric:#whiteIs0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11608
	    ^ newImage
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11609
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11610
	photometric == #whiteIs0 ifTrue:[
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11611
	    newImage := self copy.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11612
	    newImage photometric:#blackIs0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11613
	    ^ newImage
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11614
	].
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11615
	^ nil
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11616
    ].
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11617
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11618
     ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11619
	copyWithColorMapProcessing:[:clr |
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11620
		|newColor|
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11621
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11622
		newColor := Color
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11623
				redByte:(255 - clr redByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11624
				greenByte:(255 - clr greenByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11625
				blueByte:(255 - clr blueByte)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 11626
	]
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11627
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11628
    "
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11629
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') inspect
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11630
     (Image fromFile:'goodies/bitmaps/gifImages/claus.gif') negative inspect
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11631
    "
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11632
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11633
    "Created: 20.6.1997 / 13:13:41 / cg"
1763
761b4d05ac99 more #negative
Claus Gittinger <cg@exept.de>
parents: 1762
diff changeset
 11634
    "Modified: 20.6.1997 / 13:17:50 / cg"
1762
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11635
!
061f5a57000a added #negative
Claus Gittinger <cg@exept.de>
parents: 1746
diff changeset
 11636
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11637
rotated:degrees
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11638
    "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
 11639
     degrees clockwise.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11640
     Notice, that the resulting image has a different extent.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11641
     If rotation is heavily used, the workHorse methods
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11642
     (#easyRotateBitsInto:angle: and #hardRotateBitsInto:angle) may
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11643
     be redefined in concrete image subclasses."
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11644
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11645
    |nW nH newImage d|
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11646
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11647
    d := degrees.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11648
    [d < 0] whileTrue:[d := d + 360].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11649
    d >= 360 ifTrue:[d := d \\ 360].
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 11650
    d := d truncated.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11651
    d = 0 ifTrue:[^ self].
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11652
    ((d ~= 90) and:[(d ~= 270) and:[d ~= 180]]) ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11653
	^ self hardRotated:d
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11654
    ].
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11655
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11656
    d = 180 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11657
	nW := width.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11658
	nH := height.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11659
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11660
	nW := height.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11661
	nH := width.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11662
    ].
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11663
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11664
    newImage := self species new.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11665
    newImage width:nW.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11666
    newImage height:nH.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11667
    newImage createPixelStore.
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11668
    newImage photometric:photometric.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11669
    newImage samplesPerPixel:samplesPerPixel.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11670
    newImage bitsPerSample:bitsPerSample.
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11671
    newImage colorMap:colorMap copy.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11672
    mask notNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11673
	newImage mask:(mask rotated:degrees)
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11674
    ].
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11675
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11676
    self easyRotateBitsInto:newImage angle:d.
1638
a673a91d4ca1 added hardRotation.
Claus Gittinger <cg@exept.de>
parents: 1636
diff changeset
 11677
12
9f0995fac1fa *** empty log message ***
claus
parents: 6
diff changeset
 11678
    ^ newImage
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 11679
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11680
    "
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11681
     |i|
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11682
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 11683
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11684
     i inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11685
     (i rotated:45) inspect.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11686
     (i rotated:90) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11687
     (i rotated:180) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11688
     (i rotated:270) inspect.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11689
    "
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11690
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11691
     |i|
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11692
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 11693
     i := Image fromFile:'goodies/bitmaps/xpmBitmaps/misc_icons/BOOK.xpm'.
1646
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11694
     i inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11695
     (i rotated:90) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11696
     (i rotated:180) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11697
     (i rotated:270) inspect.
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11698
    "
48ab44c4664f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1644
diff changeset
 11699
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11700
    "Modified: 24.4.1997 / 18:33:42 / cg"
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11701
!
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11702
6624
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11703
slightlyDarkened
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11704
    "return a new image which is slightly darker than the receiver.
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11705
     The receiver must be a palette image (currently).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11706
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11707
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11708
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11709
    ^ self copyWithColorMapProcessing:[:clr | clr slightlyDarkened]
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11710
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11711
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11712
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11713
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11714
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11715
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11716
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11717
!
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11718
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11719
slightlyLightened
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11720
    "return a new image which is slightly brighter than the receiver.
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11721
     The receiver must be a palette image (currently).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11722
     CAVEAT: this only works with palette images (i.e. not for rgb or greyScale).
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11723
     CAVEAT: Need an argument, which specifies by how much it should be lighter."
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11724
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11725
    ^ self copyWithColorMapProcessing:[:clr | clr slightlyLightened]
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11726
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11727
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11728
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11729
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') lightened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11730
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11731
     (Smalltalk bitmapFromFileNamed:'gifImages/claus.gif' inPackage:'stx:goodies') darkened darkened inspect
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11732
    "
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11733
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11734
    "Modified: / 24-11-2010 / 11:17:55 / cg"
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11735
!
b5ea9d6b515b class: Image
Claus Gittinger <cg@exept.de>
parents: 6613
diff changeset
 11736
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11737
threeDProjected:fraction1 and:fraction2
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11738
    "return a 3D-projected version"
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11739
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11740
    |dx1 dx2 newImage newBytesPerRow newBits
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11741
     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
 11742
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11743
    newImage := self species new.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11744
    newImage width:width.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11745
    newImage height:height.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11746
    newBytesPerRow := newImage bytesPerRow.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11747
    newImage createPixelStore.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11748
    newBits := newImage bits.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11749
    newImage photometric:photometric.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11750
    newImage samplesPerPixel:samplesPerPixel.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11751
    newImage bitsPerSample:bitsPerSample.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11752
    newImage colorMap:colorMap copy.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11753
    newImage maskedPixelsAre0:maskedPixelsAre0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11754
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11755
	newImage mask:(mask threeDProjected:fraction1 and:fraction2)
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11756
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11757
	self isMask ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11758
	    self depth ~~ 1 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11759
		m := ImageMask width:width height:height.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11760
		m bits:(maskBits := ByteArray new:(m bytesPerRow * height)).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11761
		maskBits atAllPut:16rFF.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11762
		newImage mask:(m threeDProjected:fraction1 and:fraction2)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11763
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11764
	]
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11765
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11766
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11767
    myDepth := self depth.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11768
    myDepth == 1 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11769
	blackPixel := 0.
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11770
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11771
	maskedPixelsAre0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11772
	    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11773
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11774
	    blackPixel := self valueFromColor:Color black.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11775
	    blackPixel isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11776
		blackPixel := self valueFromColor:Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11777
		blackPixel isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11778
		    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11779
		]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11780
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11781
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11782
	self isMask ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11783
	    blackPixel := 0.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11784
	].
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11785
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11786
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11787
    newBits atAllPut:0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11788
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11789
    "/ now, walk over destination pixels,
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11790
    "/ fetching from source.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11791
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11792
    halfW := (width - 1) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11793
    halfH := (height - 1) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11794
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11795
    "/  --------------------------------------------------------------
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11796
    "/  |**************                                              |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11797
    "/  |              ************                                  | dx1
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11798
    "/  |                          *************                     |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11799
    "/  |                                       **********           |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11800
    "/  |fl                          fy                   ***********|
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11801
    "/  |                                                            | fr
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11802
    "/  |                                                            | Mr  (!!= Ml)      |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11803
    "/  |Ml                          my                              | fr               | dm (=Mr-Ml)
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11804
    "/  |                                                     *******|                  |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11805
    "/  |                            fy              *********       |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11806
    "/  |fl                                 *********                |
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11807
    "/  |                          *********                         | dx2
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11808
    "/  |                 *********                                  |
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11809
    "/  |        *********                                           |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11810
    "/  |********                                                    |
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11811
    "/  --------------------------------------------------------------
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11812
    dx1 := height * fraction1.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11813
    dx2 := height * fraction2.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11814
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11815
    fr := (height - dx1 - dx2) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11816
    fl := (height) / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11817
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11818
    ml := height / 2.0.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11819
    mr := dx1+fr.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11820
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11821
    dm := mr-ml.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11822
    df := fr-fl.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11823
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11824
    0 to:width-1 do:[:srcX |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11825
	fractX := srcX / width.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11826
	my := ml + (dm * fractX).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11827
	fy := fl + (df * fractX).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11828
	o1 := dx1 * fractX.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11829
	o2 := dx2 * fractX.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11830
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11831
	0 to:height-1 do:[:srcY |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11832
	    srcY < halfH ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11833
		dstY := o1 + (fy * (srcY / halfH)).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11834
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11835
		dstY := my + (fy * ((srcY-halfH) / halfH)).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11836
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11837
	    pix := self pixelAtX:srcX y:srcY.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11838
	    dstY < 0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11839
		ifTrue:[dstY := 0]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11840
		ifFalse:[ dstY >= height ifTrue:[dstY := height-1]].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11841
	    newImage pixelAtX:srcX y:dstY truncated put:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 11842
	].
4972
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11843
    ].
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11844
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11845
    ^ newImage
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11846
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11847
    "
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11848
     |i|
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11849
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11850
     i := Smalltalk imageFromFileNamed:'bitmaps/gifImages/garfield.gif' inPackage:'stx:goodies'.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11851
     i := Depth24Image fromImage:i.
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11852
     (i threeDProjected:0.1 and:0.3) inspect
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11853
     (i threeDProjected:0.1 and:0.1) inspect
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11854
    "
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11855
!
0191acd468c3 3d projection (first attempt)
Claus Gittinger <cg@exept.de>
parents: 4955
diff changeset
 11856
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11857
withColorResolutionReducedBy:numBits
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11858
    "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
 11859
     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
 11860
     If anything fails, return nil."
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11861
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11862
    |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
 11863
     newColors newColorArray newImage extMask extBits newPixelValue|
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11864
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11865
    numBits > 7 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11866
	^ nil
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11867
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11868
    mask := (16rFF bitShift:numBits) bitAnd:16rFF.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11869
    extMask := (1 bitShift:numBits).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11870
    extBits := extMask - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11871
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11872
    anyChange := false.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11873
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11874
    newColors := Set new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11875
    newColorArray := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11876
    map := Array new:256.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11877
    revMap := OrderedCollection new.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11878
4317
a24172a52a76 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
 11879
    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
 11880
    newImage photometric:photometric.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11881
    newImage colorMap:(self colorMap copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11882
    newImage bits:(self bits copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11883
    newImage mask:(self mask copy).
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11884
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11885
    xMax := width - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11886
    yMax := height - 1.
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11887
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11888
    newPixelValue :=
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11889
	[:image :pixelValue |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11890
	    |r g b nR nG nB|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11891
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11892
	    r := image redBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11893
	    g := image greenBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11894
	    b := image blueBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11895
	    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
 11896
	    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
 11897
	    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
 11898
	    image valueFromRedBits:nR greenBits:nG blueBits:nB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11899
	].
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11900
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11901
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11902
    photometric == #palette ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11903
	"/ direct manipulation of the pixels
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11904
	0 to:yMax do:[:y |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11905
	    0 to:xMax do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11906
		pix := self pixelAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11907
		n_pix := newPixelValue value:self value:pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11908
		n_pix ~= pix ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11909
		    newImage pixelAtX:x y:y put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11910
		    anyChange := true.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11911
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11912
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11913
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11914
	anyChange ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11915
	    ^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11916
	].
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11917
    ] ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11918
	"/ manipulate the colormap
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11919
	0 to:yMax do:[:y |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11920
	    0 to:xMax do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11921
		pix := self pixelAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11922
		(n_pix := map at:pix+1) isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11923
		    clr := self colorAtX:x y:y.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11924
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11925
		    r := clr redByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11926
		    g := clr greenByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11927
		    b := clr blueByte.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11928
		    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
 11929
		    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
 11930
		    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
 11931
		    n_clr := Color redByte:nR greenByte:nG blueByte:nB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11932
		    (newColors includes:n_clr) ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11933
			newColors add:n_clr.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11934
			newColorArray add:n_clr.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11935
			revMap add:pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11936
			map at:pix+1 put:(n_pix := revMap size - 1).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11937
		    ] ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11938
			"/ mhmh - multiple pixels mapped to the same color
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11939
			n_pix := (newColorArray indexOf:n_clr) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11940
			map at:pix+1 put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11941
		    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11942
		].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11943
		newImage pixelAtX:x y:y put:n_pix.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11944
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11945
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11946
	revMap size == self colorMap size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11947
	    revMap = (0 to:revMap size-1) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11948
		^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11949
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11950
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11951
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11952
	newImage colorMap:(MappedPalette withColors:newColorArray).
3905
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11953
    ].
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11954
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11955
    ^ newImage
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11956
!
bc5f7af0d9d9 colorreduction code moved from imageEditView
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
 11957
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11958
withPixelFunctionApplied:pixelFunctionBlock
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11959
    "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
 11960
     on the pixel colors.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11961
     Notice: this method is very slow - either apply pixel values
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11962
     (#withPixelFunctionAppliedToPixels:) or redefine this method in
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 11963
     a concrete subclass.
3860
571f1cd259f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3855
diff changeset
 11964
     (read `Beyond photography, by Gerard J. Holzmann;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11965
	   ISBM 0-13-074410-7)
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11966
     See blurred / oilPointed as examples ...)"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11967
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11968
    |w  "{Class: SmallInteger }"
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11969
     h  "{Class: SmallInteger }"
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 11970
     newImage "newBits newBytesPerRow"|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11971
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11972
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11973
    newImage depth:self depth.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11974
    newImage width:width.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11975
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11976
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11977
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 11978
    newImage createPixelStore. "/ bits:newBits.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11979
    newImage photometric:photometric.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11980
    newImage samplesPerPixel:samplesPerPixel.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11981
    newImage bitsPerSample:bitsPerSample.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11982
    newImage colorMap:colorMap copy.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11983
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11984
    w := width - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11985
    h := height - 1.
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11986
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11987
    0 to:h do:[:y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11988
	0 to:w do:[:x |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11989
	    newImage colorAtX:x y:y put:(pixelFunctionBlock
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11990
						value:self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11991
						value:(self colorAtX:x y:y)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11992
						value:x
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11993
						value:y)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 11994
	]
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11995
    ].
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11996
    ^ newImage
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 11997
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11998
    "black out everything except for some rectangle:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 11999
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12000
     |i black|
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12001
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12002
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
692
d3af7ac649de fixed #rotated:180
Claus Gittinger <cg@exept.de>
parents: 680
diff changeset
 12003
     i inspect.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12004
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12005
     black := Color black.
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12006
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12007
			((x between:100 and:200)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12008
			and:[y between:100 and:200]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12009
			    oldColor
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12010
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12011
			    black.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12012
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12013
		     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12014
    "
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12015
    "brighten a frame:
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12016
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12017
     |i black w h|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12018
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12019
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12020
     i inspect.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12021
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12022
     w := i width.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12023
     h := i height.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12024
     (i withPixelFunctionApplied:[:oldImage :oldColor :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12025
			((x between:0 and:10)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12026
			or:[(y between:0 and:10)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12027
			or:[(x between:w-10 and:w)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12028
			or:[y between:h-10 and:h]]]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12029
			    oldColor lightened nearestIn:i colorMap
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12030
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12031
			    oldColor.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12032
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12033
		     ]) inspect.
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 12034
    "
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12035
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12036
    "Modified: 24.4.1997 / 18:36:59 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12037
!
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12038
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12039
withPixelFunctionAppliedToPixels:pixelFunctionBlock
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12040
    "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
 12041
     on the pixel values.
4296
240f73781089 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4226
diff changeset
 12042
     (read `Beyond photography, by Gerard J. Holzmann;
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12043
	   ISBM 0-13-074410-7)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12044
     See blurred / oilPointed as examples ...)"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12045
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12046
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12047
	withPixelFunctionAppliedToPixels:pixelFunctionBlock
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12048
	in:(0@0 corner:width@height)
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12049
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12050
    "oil painting effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12051
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12052
     |i w h|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12053
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12054
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12055
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12056
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12057
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12058
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12059
			|b p max xMin xMax yMin yMax|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12060
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12061
			b := Bag identityNew:10.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12062
			xMin := x-3 max:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12063
			xMax := x+3 min:w.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12064
			yMin := y-3 max:0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12065
			yMax := y+3 min:h.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12066
			xMin to:xMax do:[:tx|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12067
			  yMin to:yMax do:[:ty|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12068
			    b add:(oldImage pixelAtX:tx y:ty)
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12069
			  ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12070
			].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12071
			max := 0.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12072
			b contents keysAndValuesDo:[:pixel :n |
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12073
			    n > max ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12074
				p := pixel.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12075
				max := n
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12076
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12077
			].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12078
			p
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12079
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12080
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12081
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12082
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12083
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12084
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12085
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12086
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12087
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12088
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12089
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12090
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12091
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12092
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12093
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12094
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12095
			|p r a nR nP nX nY|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12096
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12097
			p := (x-w2)@(y-h2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12098
			r := p r.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12099
			a := p theta.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12100
			nR := r * r / R.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12101
			nP := Point r:nR theta:a.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12102
			nX := ((nP x+w2) rounded max:0) min:w.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12103
			nY := ((nP y+h2) rounded max:0) min:h.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12104
			(nX > w or:[nX < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12105
			    white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12106
			] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12107
			    (nY > h or:[nY < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12108
				white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12109
			    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12110
				oldImage pixelAtX:nX y:nY
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12111
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12112
			]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12113
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12114
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12115
    "fisheye effect:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12116
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12117
     |i w h w2 h2 R white|
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12118
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12119
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12120
     i inspect.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12121
     w := i width - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12122
     h := i height - 1.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12123
     w2 := w // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12124
     h2 := h // 2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12125
     R := w2.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12126
     white := i valueFromColor:Color white.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12127
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12128
			|p r a nR nP nX nY|
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12129
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12130
			p := (x-w2)@(y-h2).
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12131
			r := p r.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12132
			a := p theta.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12133
			nR := r * r / R.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12134
			nP := Point r:nR theta:a.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12135
			nX := (nP x+w2) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12136
			nY := (nP y+h2) rounded.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12137
			(nX > w or:[nX < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12138
			    white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12139
			] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12140
			    (nY > h or:[nY < 0]) ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12141
				white
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12142
			    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12143
				oldImage pixelAtX:nX y:nY
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12144
			    ]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12145
			]
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12146
		     ]) inspect.
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12147
    "
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12148
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12149
    "Created: 24.4.1997 / 18:37:17 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12150
    "Modified: 24.4.1997 / 18:40:02 / cg"
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12151
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12152
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12153
withPixelFunctionAppliedToPixels:pixelFunctionBlock in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12154
    "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
 12155
     on the pixel values.
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12156
     (read `Beyond photography, by Gerard J. Holzmann;
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12157
	   ISBM 0-13-074410-7)
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12158
     See blurred / oilPointed as examples ...)"
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12159
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 12160
    |newImage "newBits newBytesPerRow"|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12161
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12162
    newImage := self species new.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12163
    newImage depth:self depth.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12164
    newImage width:width.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12165
    newImage height:height.
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12166
"/    newBytesPerRow := ((width * self depth) + 7) // 8.
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12167
"/    newBits := ByteArray uninitializedNew:(newBytesPerRow * height).
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12168
    newImage createPixelStore. "/ bits:newBits
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12169
    newImage photometric:photometric.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12170
    newImage samplesPerPixel:samplesPerPixel.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12171
    newImage bitsPerSample:bitsPerSample.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12172
    newImage colorMap:colorMap copy.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12173
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12174
    self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12175
    ^ newImage
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12176
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12177
    "oil painting effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12178
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12179
     |i w h|
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12180
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12181
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12182
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12183
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12184
     h := i height - 1.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12185
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12186
			|b p max xMin xMax yMin yMax|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12187
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12188
			b := Bag identityNew:10.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12189
			xMin := x-3 max:0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12190
			xMax := x+3 min:w.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12191
			yMin := y-3 max:0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12192
			yMax := y+3 min:h.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12193
			xMin to:xMax do:[:tx|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12194
			  yMin to:yMax do:[:ty|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12195
			    b add:(oldImage pixelAtX:tx y:ty)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12196
			  ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12197
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12198
			max := 0.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12199
			b contents keysAndValuesDo:[:pixel :n |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12200
			    n > max ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12201
				p := pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12202
				max := n
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12203
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12204
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12205
			p
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12206
		     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12207
    "
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12208
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12209
    "fisheye effect:
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12210
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12211
     |i w h w2 h2 R white|
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12212
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12213
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12214
     i inspect.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12215
     w := i width - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12216
     h := i height - 1.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12217
     w2 := w // 2.
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12218
     h2 := h // 2.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12219
     R := w2.
1570
1aeaa96fa6fb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
 12220
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12221
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12222
			|p r a nR nP nX nY|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12223
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12224
			p := (x-w2)@(y-h2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12225
			r := p r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12226
			a := p theta.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12227
			nR := r * r / R.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12228
			nP := Point r:nR theta:a.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12229
			nX := ((nP x+w2) rounded max:0) min:w.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12230
			nY := ((nP y+h2) rounded max:0) min:h.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12231
			(nX > w or:[nX < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12232
			    white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12233
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12234
			    (nY > h or:[nY < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12235
				white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12236
			    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12237
				oldImage pixelAtX:nX y:nY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12238
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12239
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12240
		     ]) inspect.
1509
096ed5c04883 pixel processing
Claus Gittinger <cg@exept.de>
parents: 1496
diff changeset
 12241
    "
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12242
    "fisheye effect:
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12243
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12244
     |i w h w2 h2 R white|
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12245
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12246
     i := Image fromFile:'goodies/bitmaps/gifImages/claus.gif'.
1510
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12247
     i inspect.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12248
     w := i width - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12249
     h := i height - 1.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12250
     w2 := w // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12251
     h2 := h // 2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12252
     R := w2.
8b56c96a9e9d pixel processing
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
 12253
     white := i valueFromColor:Color white.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12254
     (i withPixelFunctionAppliedToPixels:[:oldImage :oldPixel :x :y |
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12255
			|p r a nR nP nX nY|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12256
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12257
			p := (x-w2)@(y-h2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12258
			r := p r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12259
			a := p theta.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12260
			nR := r * r / R.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12261
			nP := Point r:nR theta:a.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12262
			nX := (nP x+w2) rounded.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12263
			nY := (nP y+h2) rounded.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12264
			(nX > w or:[nX < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12265
			    white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12266
			] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12267
			    (nY > h or:[nY < 0]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12268
				white
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12269
			    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12270
				oldImage pixelAtX:nX y:nY
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12271
			    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12272
			]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12273
		     ]) inspect.
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12274
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12275
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12276
    "Created: 24.4.1997 / 18:37:17 / cg"
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 12277
    "Modified: 24.4.1997 / 18:40:02 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12278
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12279
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12280
!Image methodsFor:'initialization'!
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12281
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12282
createPixelStore
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12283
    |bytesPerRow|
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12284
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12285
    bytesPerRow := self bytesPerRow.
5643
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12286
    self bits:(ByteArray new:(bytesPerRow * self height)).
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12287
bf38d077884a changed:
Claus Gittinger <cg@exept.de>
parents: 5533
diff changeset
 12288
    "Modified: / 02-11-2010 / 20:57:11 / cg"
3912
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12289
!
a16c7edceb0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
 12290
3871
a7867fb8d880 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
 12291
initialize
3870
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12292
    self photometric:(self class defaultPhotometric)
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12293
! !
8245e3f37feb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
 12294
5037
2e515c9ee849 changed #valueFromColor:
Claus Gittinger <cg@exept.de>
parents: 4998
diff changeset
 12295
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12296
!Image methodsFor:'instance release'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12297
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12298
close
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12299
    "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
 12300
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12301
    deviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12302
	deviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12303
	deviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12304
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12305
    monoDeviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12306
	monoDeviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12307
	monoDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12308
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12309
    fullColorDeviceForm notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12310
	fullColorDeviceForm destroy.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12311
	fullColorDeviceForm := nil.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12312
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12313
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12314
    device := nil.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12315
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12316
	mask close.
1650
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12317
    ].
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12318
    Lobby unregister:self.
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12319
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12320
    "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
 12321
    "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
 12322
!
eb56b36925fc skip leading empty space in hardRotated (10-20% speedup);
Claus Gittinger <cg@exept.de>
parents: 1646
diff changeset
 12323
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12324
release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12325
    "release device resources"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12326
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12327
    device := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12328
    deviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12329
    monoDeviceForm := nil.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12330
    fullColorDeviceForm := nil.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12331
    mask notNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12332
	mask release.
901
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12333
    ].
6cacd0f4eef0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 896
diff changeset
 12334
    Lobby unregister:self.
1746
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12335
    super release.
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12336
72a583dd30bd must not forget super release
Claus Gittinger <cg@exept.de>
parents: 1739
diff changeset
 12337
    "Modified: 11.6.1997 / 13:20:04 / cg"
46
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 12338
!
7b331e9012fd *** empty log message ***
claus
parents: 35
diff changeset
 12339
4226
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12340
releaseFromDevice
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12341
    "release device resources"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12342
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12343
    device := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12344
    deviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12345
    monoDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12346
    fullColorDeviceForm := nil.
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12347
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12348
    "Modified: 16.1.1997 / 19:33:01 / cg"
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12349
!
dcd06fa84d2c *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4187
diff changeset
 12350
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12351
restored
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12352
    "flush device specifics after a snapin or binary restore"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12353
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12354
    self release
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12355
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12356
2227
7aa9e2a8d321 added #edit - to open an image editor.
Claus Gittinger <cg@exept.de>
parents: 2212
diff changeset
 12357
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12358
!Image methodsFor:'obsolete'!
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12359
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12360
applyPixelValuesTo:pixelFunctionBlock into:newImage in:aRectangle
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12361
    "helper for withPixelFunctionAppliedToValues:
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12362
     enumerate pixelValues and evaluate the block for each.
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12363
     To be redefined by subclasses for better performance."
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12364
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12365
    ^ self applyPixelValuesTo:pixelFunctionBlock in:aRectangle into:newImage
3911
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12366
!
a3c84de217fe pixel function application refactored
Claus Gittinger <cg@exept.de>
parents: 3908
diff changeset
 12367
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12368
magnifyBy:scale
5216
f7ec910cfce1 Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 5200
diff changeset
 12369
    <resource: #obsolete>
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12370
    "obsolete: has been renamed to magnifiedBy: for ST-80 compatibility
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12371
     and name consistency ..."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12372
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12373
    self obsoleteMethodWarning.
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12374
    ^ self magnifiedBy:scale
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12375
! !
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12376
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12377
!Image methodsFor:'pixel copying'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12378
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12379
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
 12380
    "replace a rectangular area by pixels from another image.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12381
     The sources colors must be present in the destinations
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12382
     colorMap - otherwise, an error will be reported.
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12383
     Any mask is copied from the source.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12384
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12385
     WARNING:
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12386
       This implementation is a very slow fallback general algorithm
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12387
       (the loop over the source pixels is very slow).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12388
       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
 12389
       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
 12390
       with the same depth & palette.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12391
       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
 12392
       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
 12393
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12394
    |dX dY|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12395
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12396
    dX := srcX-dstX.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12397
    dY := srcY-dstY.
1248
6afcdec18986 commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
 12398
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12399
    ((photometric == anImage photometric)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12400
     and:[self bitsPerPixel == anImage bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12401
     and:[colorMap = anImage colorMap]]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12402
	"/ can loop over values
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12403
	anImage valuesFromX:srcX  y:srcY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12404
			toX:srcX+w-1 y:srcY+h-1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12405
			 do:[:x :y :pixelValue |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12406
	    self pixelAtX:x-dX y:y-dY put:pixelValue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12407
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12408
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12409
	"/ must loop over colors - horribly slow
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12410
	anImage colorsFromX:srcX  y:srcY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12411
			toX:srcX+w-1 y:srcY+h-1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12412
			 do:[:x :y :clr |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12413
	    self colorAtX:x-dX y:y-dY put:clr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12414
	]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12415
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12416
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12417
    (mask isNil and:[anImage mask notNil]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12418
	"/ I have no mask; copied image has
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12419
	self createMask.
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12420
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12421
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12422
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12423
	anImage mask notNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12424
	    "/ both have a mask
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12425
	    mask copyFrom:anImage mask x:srcX y:srcY toX:dstX y:dstY width:w height:h
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12426
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12427
	    "/ I have a mask - copied image has not
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12428
	    mask fillRectangleX:dstX y:dstY width:w height:h withValue:1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12429
	]
3457
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12430
"/    ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12431
"/        anImage mask notNil ifTrue:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12432
"/            "/ I have no mask; copied image has (already handled)
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12433
"/        ] ifFalse:[
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12434
"/            "/ none has a mask - nothing to do.
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12435
"/        ]
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12436
    ].
9b8d928f53df *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3448
diff changeset
 12437
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12438
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12439
     |i1 i8 i4|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12440
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 12441
     i8 := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12442
     i8 inspect.
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12443
     i1 := Image fromFile:'libtool/bitmaps/SBrowser.xbm'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12444
     i1 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12445
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12446
     i4 := Depth4Image fromImage:i8.
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12447
     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
 12448
     i4 inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12449
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12450
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12451
    "Created: 20.9.1995 / 10:14:01 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12452
    "Modified: 20.9.1995 / 10:25:31 / claus"
1764
01101be8bd5c obsolete warning messages
Claus Gittinger <cg@exept.de>
parents: 1763
diff changeset
 12453
    "Modified: 21.6.1997 / 13:15:31 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12454
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12455
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12456
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
 12457
    "replace a rectangular area by pixels from another image.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12458
     The sources colors must be present in the destinations
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12459
     colorMap - otherwise, an error will be reported.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12460
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12461
     WARNING:
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12462
       This implementation is a very slow fallback general algorithm
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12463
       (the loop over the source pixels is very slow).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12464
       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
 12465
       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
 12466
       with the same depth & palette.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12467
       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
 12468
       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
 12469
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12470
    maskedCopy ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12471
	self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12472
	    copyMaskedFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12473
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12474
	self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12475
	    copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12476
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12477
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12478
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12479
     |i1 i8 i4|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12480
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12481
     i8 := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12482
     i8 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12483
     i1 := Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm'.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12484
     i1 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12485
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12486
     i4 := Depth4Image fromImage:i8.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12487
     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
 12488
     i4 inspect.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12489
    "
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12490
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12491
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12492
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
 12493
    "replace a rectangular area by pixels from another image.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12494
     The sources colors must be present in the destinations
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12495
     colorMap - otherwise, an error will be reported.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12496
     Only unmasked pixels are copied from the source.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12497
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12498
     WARNING:
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12499
       This implementation is a very slow fallback general algorithm
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12500
       (the loop over the source pixels is very slow).
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12501
       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
 12502
       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
 12503
       with the same depth & palette.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12504
       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
 12505
       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
 12506
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12507
    |dX dY|
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12508
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12509
    dX := srcX-dstX.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12510
    dY := srcY-dstY.
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12511
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12512
    ((photometric == anImage photometric)
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12513
     and:[self bitsPerPixel == anImage bitsPerPixel
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12514
     and:[colorMap = anImage colorMap]]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12515
	"/ can loop over values
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12516
	anImage valuesFromX:srcX  y:srcY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12517
			toX:srcX+w-1 y:srcY+h-1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12518
			 do:[:x :y :pixelValue |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12519
	    (anImage maskAtX:x y:y) ~~ 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12520
		self pixelAtX:x-dX y:y-dY put:pixelValue.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12521
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12522
	]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12523
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12524
	"/ must loop over colors - horribly slow
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12525
	anImage colorsFromX:srcX  y:srcY
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12526
			toX:srcX+w-1 y:srcY+h-1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12527
			 do:[:x :y :clr |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12528
	    (anImage maskAtX:x y:y) ~~ 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12529
		self colorAtX:x-dX y:y-dY put:clr.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12530
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12531
	]
4955
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12532
    ].
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12533
!
663362ee10e4 line drawing, masked copying
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
 12534
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12535
subImageIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12536
    "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
 12537
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12538
    ^ self class fromSubImage:self in:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12539
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12540
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12541
     |i|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12542
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 12543
     i := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12544
     i inspect.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12545
     (i subImageIn:(300@160 corner:340@200)) inspect
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12546
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12547
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12548
    "Created: 20.9.1995 / 01:24:20 / claus"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12549
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12550
6305
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12551
!Image methodsFor:'pixel functions'!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12552
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12553
computeBitsFromPixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12554
    "compute the bits from the pixelfunction"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12555
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12556
    |bpr idx|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12557
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12558
    bpr := self bytesPerRow.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12559
    bytes := ByteArray new:(bpr * height).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12560
    idx := 1.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12561
    0 to:height-1 do:[:y |
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12562
        0 to:width-1 do:[:x |
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12563
            self pixelAtX:x y:y put:(pixelFunction value:x value:y).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12564
        ]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12565
    ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12566
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12567
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12568
pixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12569
    ^ pixelFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12570
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12571
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12572
pixelFunction:aTwoArgFunction
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12573
    "set the pixel function. This is used to define a functional image,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12574
     where pixel values are computed via a function instead of coming
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12575
     from a bits array (although a pixel array could also be seen as
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12576
     a pixel function).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12577
     The pixelFunction will map (x E [0 .. width]) x (y E [0 .. height]) -> pixel"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12578
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12579
    pixelFunction := aTwoArgFunction.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12580
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12581
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12582
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12583
     i := Depth1Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12584
     i pixelFunction:[:x :y | ((x // 16) bitXor:(y // 16)) odd asInteger].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12585
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12586
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12587
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12588
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12589
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12590
     i := Depth8Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12591
     i photometric:#blackIs0.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12592
     i pixelFunction:[:x :y | x  ].
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12593
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12594
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12595
!
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12596
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12597
pixelFunction:aTwoArgFunction inX:xInterval y:yInterval
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12598
    "set the pixel function and a viewport. 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12599
     This is used to define a functional image,
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12600
     where pixel values are computed via a function instead of coming
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12601
     from a bits array. 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12602
     The pixelFunction will map (x E xInterval) x (y E yInterval) -> pixel"
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12603
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12604
    |sX sY tX tY|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12605
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12606
    "/ intervals are typically 0..1
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12607
    sX := (xInterval stop - xInterval start) asFloat / width.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12608
    sY := (yInterval stop - yInterval start) asFloat / height.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12609
    tX := xInterval start.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12610
    tY := yInterval start.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12611
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12612
    pixelFunction := 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12613
        [:x :y | 
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12614
            aTwoArgFunction value:(x * sX + tX) value:(y * sY + tY)
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12615
        ]
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12616
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12617
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12618
     |i|
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12619
     i := Depth8Image extent:256@256.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12620
     i photometric:#blackIs0.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12621
     i pixelFunction:[:x :y | ((x@y) r * 255) truncated min:255] inX:(-1 to:1) y:(-1 to:1).
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12622
     i inspect.
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12623
    "
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12624
! !
f95708ed5bcb functional images
Claus Gittinger <cg@exept.de>
parents: 6284
diff changeset
 12625
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12626
!Image methodsFor:'printing & storing'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12627
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12628
storeOn:aStream
592
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12629
    "append a printed representation of the receiver to aStream,
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12630
     from which a copy of it can be reconstructed."
7fdd92afbbce commentary
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
 12631
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12632
    |colors usedValues colorMapArray needBPS needSemi|
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12633
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12634
    needSemi := false.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12635
    aStream nextPutAll:('(%1 width:%2 height:%3' 
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12636
                            bindWith:self class name
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12637
                            with:width 
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12638
                            with:height).
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12639
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12640
    "/ avoiding some unneeded stuff here makes object files with many images a bit smaller.
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12641
    "/ no need for the photometric, if it's the default anyway
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12642
    photometric ~= self class defaultPhotometric ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12643
        (colorMap isNil or:[photometric ~~ #palette]) ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12644
            aStream nextPutAll:' photometric:('. photometric storeOn:aStream. aStream nextPutAll:')'.
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 12645
            needSemi := false.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12646
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12647
    ].
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12648
    aStream nextPutAll:')'.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12649
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12650
    "/ no need to store bitPerSample/samplesPerPixel in all situations
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12651
    needBPS := true.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12652
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12653
    self depth == 1 
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12654
        ifTrue:[ needBPS := false ]
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12655
        ifFalse:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12656
            ((photometric == #palette) 
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12657
                and:[ (bitsPerSample size == 1)
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12658
                and:[ ((bitsPerSample at:1) == self depth)
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12659
                and:[ samplesPerPixel == 1 ]]])
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12660
            ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12661
                needBPS := false.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12662
            ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12663
        ].
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12664
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12665
    needBPS ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12666
        needSemi ifTrue:[aStream nextPutAll:';'].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12667
        aStream nextPutAll:' bitsPerSample:('. bitsPerSample storeOn:aStream. aStream nextPutAll:')'.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12668
        samplesPerPixel ~= bitsPerSample size ifTrue:[
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12669
            aStream nextPutAll:'; samplesPerPixel:('. samplesPerPixel storeOn:aStream. aStream nextPutAll:')'. 
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12670
        ].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12671
        needSemi := true.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12672
    ].
5533
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12673
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12674
    "/ assert that all bits are there...
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12675
    "/ self assert:(self bits size) >= (self bytesPerRow * height).
2e7c216c76cf comment/format in: #storeOn:
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
 12676
    "/ 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
 12677
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12678
    needSemi ifTrue:[aStream nextPutAll:';'].
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12679
    aStream nextPutAll:' bits:(ByteArray fromPackedString:'. self bits asPackedString storeOn:aStream.
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12680
    aStream nextPutAll:')'.
2068
3bc8754883ae store on the color map in an array of rgb-byte values
tz
parents: 2059
diff changeset
 12681
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 12682
    colorMap notNil ifTrue:[
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12683
        self depth <= 8 ifTrue:[
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12684
            "/ cut off unused colors ...
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12685
            usedValues := self usedValues.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12686
            colors := colorMap copyFrom:1 to:((usedValues max+1) min:colorMap size).
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12687
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12688
            colorMapArray := OrderedCollection new.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12689
            colors do:[:clr| colorMapArray add:(clr redByte); add:(clr greenByte); add:(clr blueByte)].
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12690
            aStream nextPutAll:' colorMapFromArray:'.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12691
            colorMapArray asByteArray storeOn:aStream.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12692
        ] ifFalse:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12693
            aStream nextPutAll:' colorMap:('.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12694
            colorMap storeOn:aStream.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12695
            aStream nextPutAll:')'
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12696
        ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12697
    ].
4187
411b7b76a8bb fixedPalette has more functionality
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
 12698
    mask notNil ifTrue:[
6900
ad20df4aec7a class: Image
Claus Gittinger <cg@exept.de>
parents: 6899
diff changeset
 12699
        aStream nextPutAll:' mask:('.
6311
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12700
        mask storeOn:aStream.
0986d91407d9 class: Image
Claus Gittinger <cg@exept.de>
parents: 6308
diff changeset
 12701
        aStream nextPutAll:')'.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12702
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12703
    aStream nextPutAll:'; yourself'
2266
72460683cc97 fixed maskedPixelsAre0 flag setting when copying images.
Claus Gittinger <cg@exept.de>
parents: 2249
diff changeset
 12704
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 12705
    "Modified: / 22-08-1998 / 12:55:21 / cg"
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 12706
    "Modified: / 01-09-2015 / 17:24:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 12707
! !
48194c26a46c Initial revision
claus
parents:
diff changeset
 12708
48194c26a46c Initial revision
claus
parents:
diff changeset
 12709
!Image methodsFor:'private'!
48194c26a46c Initial revision
claus
parents:
diff changeset
 12710
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12711
bestSupportedImageFormatFor:aDevice
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12712
    "scan through the image formats as supported by aDevice,
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12713
     and return the best to use when the receiver is to be represented
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12714
     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
 12715
     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
 12716
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12717
    |bestDeviceDepth
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12718
     bestDeviceBitsPerPixel "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12719
     "maxDepth"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12720
     bestInfo maxInfo
2530
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12721
     myDepth                "{ Class: SmallInteger }"
81b8ffe7662f use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2527
diff changeset
 12722
     maxBitsPerPixel        "{ Class: SmallInteger }"|
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12723
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12724
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12725
    maxBitsPerPixel := 0.
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12726
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12727
    aDevice supportedImageFormats do:[:entry |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12728
	|deviceImageDepth        "{ Class: SmallInteger }"
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12729
	 deviceImageBitsPerPixel "{ Class: SmallInteger }" |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12730
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12731
	deviceImageDepth := entry at:#depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12732
	deviceImageBitsPerPixel := entry at:#bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12733
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12734
	"/ 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
 12735
	"/ devices depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12736
	"/ (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
 12737
	"/ 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
 12738
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12739
	((deviceImageDepth == 1) or:[deviceImageDepth == aDevice depth]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12740
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12741
	    deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12742
		maxInfo := entry.
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12743
    "/            maxBitsPerPixel := deviceImageBitsPerPixel.
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12744
    "/            maxDepth := deviceImageDepth.
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12745
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12746
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12747
	    deviceImageDepth >= myDepth ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12748
		deviceImageDepth == myDepth ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12749
		    "/ take the better one ...
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12750
		    (bestDeviceDepth isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12751
		     or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12752
			and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12753
			bestInfo := entry.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12754
			bestDeviceDepth := deviceImageDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12755
			bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12756
		    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12757
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12758
		    "/ take the next-larger depth
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12759
		    (bestDeviceDepth isNil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12760
		     or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12761
			bestInfo := entry.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12762
			bestDeviceDepth := deviceImageDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12763
			bestDeviceBitsPerPixel := deviceImageBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12764
		    ]
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12765
		]
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12766
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12767
	].
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12768
    ].
851
c9511f8945ce fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents: 841
diff changeset
 12769
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12770
    bestDeviceDepth isNil ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12771
	maxBitsPerPixel == 0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12772
	    "/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12773
	    "/ oops - nothing appropriate
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12774
	    "/
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12775
	    maxInfo notNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12776
		^ maxInfo
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12777
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12778
	    bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12779
	    bestInfo := IdentityDictionary new.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12780
	    bestInfo at:#depth put:bestDeviceDepth.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12781
	    bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12782
	    bestInfo at:#padding put:32.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12783
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12784
	    bestInfo := maxInfo.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12785
	]
193
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
 12786
    ].
235
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 12787
    ^ bestInfo
579f3f804a46 padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents: 230
diff changeset
 12788
2050
d1f21c75b5eb when asking a device for its supported pixmap formats,
Claus Gittinger <cg@exept.de>
parents: 2043
diff changeset
 12789
    "Modified: / 7.2.1998 / 11:23:24 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12790
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12791
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12792
colormapFromImage:anImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12793
    "setup the receivers colormap from another image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12794
     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
 12795
     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
 12796
     for fromImage:/fromSubImake:"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12797
3259
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12798
    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
 12799
!
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12800
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12801
colormapFromImage:anImage photometric:photometricOrNil
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12802
    "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
 12803
     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
 12804
     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
 12805
     for fromImage:/fromSubImake:"
85e0044678b5 fixed conversion from rgb to palette image (for gif-saving)
Claus Gittinger <cg@exept.de>
parents: 3256
diff changeset
 12806
2447
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 12807
    |usedColors|
5b3d802d602b allow Image fromImage with rgb source-image and palette receiver
Claus Gittinger <cg@exept.de>
parents: 2415
diff changeset
 12808
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12809
    samplesPerPixel == 3 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12810
	photometric := photometricOrNil ? #rgb
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12811
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12812
	photometricOrNil isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12813
	    photometric := anImage photometric.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12814
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12815
	    photometric := photometricOrNil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12816
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12817
	photometric == #palette ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12818
	    self setColorMap:(anImage colorMap copy).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12819
	    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12820
	     must generate/compress the colormap, if source image has higher depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12821
	     than myself.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12822
	    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12823
	    (colorMap isNil
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12824
	    or:[anImage bitsPerPixel > self bitsPerPixel]) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12825
		"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12826
		 get used colors are extracted into our colorMap
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12827
		 (the at-put below will set the pixelValue according the
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12828
		 new colorIndex
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12829
		"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12830
		self setColorMap:(anImage usedColors asArray).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12831
		colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12832
		    'Image [warning]: possibly too many colors in image' errorPrintCR
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12833
		]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12834
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12835
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12836
	    (photometric == #blackIs0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12837
	    or:[ photometric == #whiteIs0 ]) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12838
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12839
		usedColors := anImage usedColors asArray.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12840
		usedColors size > (1 bitShift:self bitsPerPixel) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12841
		    'Image [warning]: possibly too many colors in image' errorPrintCR.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12842
		    usedColors := usedColors copyTo:(1 bitShift:self bitsPerPixel).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12843
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12844
		self setColorMap:usedColors.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12845
		photometric := #palette
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12846
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 12847
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12848
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12849
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12850
    "Created: 20.9.1995 / 00:58:42 / claus"
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 12851
    "Modified: 10.1.1997 / 17:52:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12852
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12853
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12854
greyByteMapForRange:range
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12855
    "return a collection to map from pixelValues to greyLevels
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12856
     in the range 0..range.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12857
     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
 12858
     The values are rounded towards the nearest pixel."
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12859
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12860
    |d clr val greyMap r
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12861
     n "{ Class: SmallInteger }"|
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12862
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12863
    r := range.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12864
    r == 256 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12865
	r := 255
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12866
    ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12867
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12868
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12869
	n := colorMap size.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12870
	greyMap := ByteArray new:n.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12871
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12872
	1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12873
	    (clr := colorMap at:i) isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12874
		"/ an unused color
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12875
		val := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12876
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12877
		val := (r * clr brightness) rounded
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12878
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12879
	    greyMap at:i put:val
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12880
	].
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12881
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12882
	d := self bitsPerPixel.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12883
	n := 1 bitShift:d.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12884
	n >= 4096 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12885
	    self error:'size not supported - too large'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12886
	    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12887
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12888
	greyMap := ByteArray new:n.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12889
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12890
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12891
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12892
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12893
		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
 12894
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12895
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12896
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12897
		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
 12898
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12899
	    photometric == #blackIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12900
		"/ we are done
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12901
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12902
		photometric == #whiteIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12903
		    greyMap reverse
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12904
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12905
		    self error:'invalid format'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12906
		    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12907
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12908
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12909
	].
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12910
    ].
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12911
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12912
    ^ greyMap
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12913
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12914
    "
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12915
     Depth8Image new greyByteMapForRange:256
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12916
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12917
     Depth8Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12918
     Depth4Image new greyByteMapForRange:64
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12919
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
 12920
     Depth4Image new greyByteMapForRange:1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12921
    "
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12922
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12923
    "Created: 8.6.1996 / 08:34:14 / cg"
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12924
    "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
 12925
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12926
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12927
greyMapForRange:range
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12928
    "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
 12929
     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
 12930
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12931
    |d r clr val
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12932
     n "{Class: SmallInteger }"
1927
d1bbdf03e5a1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1919
diff changeset
 12933
     n2 "{Class: SmallInteger }"
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12934
     greyArray|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12935
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12936
    d := self bitsPerPixel.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12937
    n := 1 bitShift:d.
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12938
    n >= 4096 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12939
	self error:'size not supported - too large'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12940
	^ nil
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12941
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12942
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12943
    greyArray := Array new:n.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12944
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12945
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12946
	n2 := colorMap size.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12947
	1 to:n2 do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12948
	    (clr := colorMap at:i) isNil ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12949
		"/ an unused color
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12950
		val := 0.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12951
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12952
		val := range * clr brightness
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12953
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12954
	    greyArray at:i put:val
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12955
	].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12956
	n2 < n ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12957
	    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
 12958
	]
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 12959
    ] ifFalse:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12960
	photometric == #rgb ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12961
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12962
		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
 12963
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12964
	] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12965
	    r := range asFloat.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12966
	    1 to:n do:[:i |
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12967
		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
 12968
	    ].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12969
	    photometric == #blackIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12970
		"/ we are done
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12971
	    ] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12972
		photometric == #whiteIs0 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12973
		    greyArray reverse
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12974
		] ifFalse:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12975
		    self error:'invalid format'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12976
		    ^ nil
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12977
		]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12978
	    ]
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 12979
	]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12980
    ].
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12981
    ^ greyArray
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12982
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12983
    "
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12984
     Depth8Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12985
     Depth4Image new greyMapForRange:64
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12986
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12987
     Depth16Image new greyMapForRange:1
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12988
     Depth4Image new greyMapForRange:1
809
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12989
     Depth2Image new greyMapForRange:1
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12990
    "
f66955a8200e more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
 12991
1403
4b132381579e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1386
diff changeset
 12992
    "Modified: 1.3.1997 / 15:48:49 / cg"
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12993
!
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 766
diff changeset
 12994
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 12995
magnifyRowFrom:srcBytes offset:srcStart
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 12996
	  into:dstBytes offset:dstStart factor:mX
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12997
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12998
    "magnify a single pixel row - can only magnify by integer factors,
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 12999
     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
 13000
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13001
    ^ self subclassResponsibility
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13002
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13003
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13004
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13005
    "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
 13006
     pixels interpreted as greyValues, 0 is black,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13007
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13008
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13009
    |f|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13010
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 13011
    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
 13012
    f isNil ifTrue:[^ nil].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13013
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13014
    f bits:bits.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13015
    f initGC.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13016
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13017
    (aDevice blackpixel ~~ 0) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13018
	"/ have to invert bits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13019
	f function:#copyInverted
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13020
    ].
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13021
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13022
	drawBits:bits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13023
	depth:depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13024
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13025
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13026
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13027
	into:(f id)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13028
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13029
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13030
	with:(f gcId).
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13031
    ^ f
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13032
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13033
    "Created: 10.6.1996 / 20:10:31 / cg"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13034
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13035
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13036
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13037
    "given the bits of a monochrome bitmap, 8-bit padded and
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13038
     0-bits as black, create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13039
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 13040
"/    monoBits invert.
4769
0cabcf1481a0 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4762
diff changeset
 13041
    ^ (Form width:width height:height fromArray:monoBits onDevice:aDevice)
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13042
	colorMap:(Array with:Color black with:Color white).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13043
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13044
    "Created: 10.6.1996 / 20:18:09 / cg"
1608
edf60801e6c0 comments
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
 13045
    "Modified: 17.4.1997 / 01:07:38 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13046
!
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13047
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13048
makeDevicePixmapOn:aDevice depth:depth fromArray:bits
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13049
    "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
 13050
     pixels interpreted as in the devices colormap,
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13051
     create a device form for it"
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13052
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13053
    |f|
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13054
4780
03c3e810a584 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4769
diff changeset
 13055
    f := Form width:width height:height depth:depth onDevice:aDevice.
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13056
    f isNil ifTrue:[^ nil].
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13057
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13058
    f bits:bits.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13059
    f initGC.
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13060
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13061
    aDevice
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13062
	drawBits:bits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13063
	depth:depth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13064
	padding:8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13065
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13066
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13067
	into:(f id)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13068
	x:0 y:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13069
	width:width height:height
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13070
	with:(f gcId).
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13071
    ^ f
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13072
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
 13073
    "Created: 10.6.1996 / 17:56:08 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
 13074
    "Modified: 10.6.1996 / 20:11:27 / cg"
5237
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13075
!
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13076
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13077
repairPhotometric
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13078
    "/ kludge: repair a 'should not happen' situation...
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13079
    photometric isNil ifTrue:[
6390
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
 13080
        (self depth == 24 and:[ bitsPerSample size == 3 ]) ifTrue:[
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
 13081
            photometric := #rgb
f9a4a09ff2a1 class: Image
Stefan Vogel <sv@exept.de>
parents: 6379
diff changeset
 13082
        ].
5237
e28aca881988 repairPhotometric
Claus Gittinger <cg@exept.de>
parents: 5235
diff changeset
 13083
    ].
2
b35336ab0de3 *** empty log message ***
claus
parents: 0
diff changeset
 13084
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 13085
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13086
!Image methodsFor:'queries'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13087
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13088
alphaBitsOf:pixel
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13089
    "if the receiver is an rgb-image:
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13090
     return the alpha component of a pixelValue as integer 0..maxAlphaValue.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13091
     MaxAlphaValue is of course the largest integer representable by the number
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13092
     of alpha bits i.e. (1 bitShift:bitsAlpha)-1.
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13093
     This has to be redefined by subclasses."
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13094
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13095
    |redBits greenBits blueBits alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13096
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13097
    samplesPerPixel >= 4 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13098
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13099
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13100
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13101
	alphaBits := bitsPerSample at:4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13102
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13103
	^ (pixel bitShift:(redBits + greenBits + blueBits) negated)
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13104
	   bitAnd:(1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13105
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13106
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13107
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13108
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13109
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13110
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13111
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13112
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13113
alphaMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13114
    "return the mask used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13115
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13116
    |alphaBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13117
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13118
    samplesPerPixel >= 4 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13119
	alphaBits := bitsPerSample at:4.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13120
	^ (1 bitShift:alphaBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13121
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13122
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13123
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13124
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13125
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13126
alphaShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13127
    "return the shift amount used with translation from pixelValues to alphaBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13128
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13129
    |redBits greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13130
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13131
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13132
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13133
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13134
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13135
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13136
	^ (greenBits + blueBits + redBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13137
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13138
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13139
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13140
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13141
3813
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13142
ascentOn:aGC
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13143
    "I will not draw myself above the baseline"
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13144
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13145
    ^ 0
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13146
!
662c6386828e ascentOn:
Claus Gittinger <cg@exept.de>
parents: 3811
diff changeset
 13147
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13148
averageColor
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13149
    "return the average color of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13150
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13151
     (i.e. to compute shadow & light colors for viewBackgrounds).
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13152
     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
 13153
     a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13154
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13155
    ^ self averageColorIn:(0@0 corner:(width-1)@(height-1))
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13156
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13157
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13158
averageColorIn:aRectangle
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13159
    "return the images average color in an area.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13160
     The implementation below is slow - so you may want to
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13161
     create tuned versions for DepthXImage if you plan to do
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13162
     heavy image processing ...
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13163
     (also, creating tuned versions of the enumeration messages helps a lot)"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13164
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13165
    |x0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13166
     y0 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13167
     x1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13168
     y1 "{ Class:SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13169
     sumRed sumGreen sumBlue n|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13170
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13171
    sumRed := sumGreen := sumBlue := 0.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13172
    y0 := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13173
    y1 := aRectangle bottom.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13174
    x0 := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13175
    x1 := aRectangle right.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13176
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13177
    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
 13178
    mask isNil ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13179
	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
 13180
	    sumRed := sumRed + colorAtXY red.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13181
	    sumGreen := sumGreen + colorAtXY green.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13182
	    sumBlue := sumBlue + colorAtXY blue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13183
	].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13184
    ] ifFalse:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13185
	"/ masked pixels are not counted.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13186
	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
 13187
	    (mask pixelAtX:x y:y) == 0 ifTrue:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13188
		n := n - 1.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13189
	    ] ifFalse:[
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13190
		sumRed := sumRed + colorAtXY red.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13191
		sumGreen := sumGreen + colorAtXY green.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13192
		sumBlue := sumBlue + colorAtXY blue.
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13193
	    ].
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13194
	].
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13195
    ].
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13196
    n == 0 ifTrue:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13197
	"/ all masked
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 13198
	^ Color black
3761
44b96cd84bb8 ignore masked pixels when computing the average
Claus Gittinger <cg@exept.de>
parents: 3760
diff changeset
 13199
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13200
    ^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n)
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13201
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13202
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13203
bitsPerPixel
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13204
    "return the number of bits per pixel"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13205
5926
95dab34aeea2 changed: #bitsPerPixel
Stefan Vogel <sv@exept.de>
parents: 5919
diff changeset
 13206
    ^ bitsPerSample sum
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13207
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13208
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13209
bitsPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13210
    "return the number of bits in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13211
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
 13212
    ^ width * (self bitsPerPixel).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13213
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13214
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13215
blackComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13216
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13217
     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
 13218
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13219
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13220
	"/ 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
 13221
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13222
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13223
	    ^ 100.0 / 255 * (pixel bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13224
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13225
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13226
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13227
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13228
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13229
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13230
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13231
blueBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13232
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13233
     return the blue bits of a pixelValue as integer 0..maxBlueValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13234
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13235
     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
 13236
     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
 13237
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13238
    |blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13239
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13240
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13241
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13242
	^ 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
 13243
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13244
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13245
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13246
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13247
    "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
 13248
    "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
 13249
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13250
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13251
blueComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13252
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13253
     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
 13254
     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
 13255
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13256
    |blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13257
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13258
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13259
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13260
	"/ 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
 13261
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13262
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13263
	blueBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13264
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13265
	s := (1 bitShift:blueBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13266
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13267
	^ 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
 13268
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13269
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13270
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13271
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13272
    "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
 13273
    "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
 13274
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13275
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13276
blueMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13277
    "return the mask used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13278
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13279
    |blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13280
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13281
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13282
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13283
	^ (1 bitShift:blueBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13284
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13285
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13286
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13287
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13288
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13289
blueShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13290
    "return the shift amount used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13291
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13292
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13293
	^ 0
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13294
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13295
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13296
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13297
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13298
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13299
bounds
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13300
    "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
 13301
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13302
    ^ 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
 13303
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13304
    "Created: 13.5.1996 / 10:27:06 / cg"
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13305
!
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13306
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13307
brightness
6755
cee1206f74db class: Image
Claus Gittinger <cg@exept.de>
parents: 6653
diff changeset
 13308
    "return the (average) brightness of the image as number in 0..1.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13309
     This usually only makes sense for textures and patterns
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13310
     (i.e. to compute shadow & light colors for viewBackgrounds).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13311
     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
 13312
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13313
    ^ (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
 13314
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13315
    "Modified: 8.6.1996 / 08:46:46 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13316
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13317
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13318
bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13319
    "return the number of bytes in one scanline of the image"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13320
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13321
    |bitsPerRow bytesPerRow|
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13322
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13323
    bitsPerRow := width * (self bitsPerPixel).
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13324
    bytesPerRow := bitsPerRow // 8.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13325
    ((bitsPerRow \\ 8) ~~ 0) ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13326
	bytesPerRow := bytesPerRow + 1
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13327
    ].
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13328
    ^ bytesPerRow
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13329
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13330
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13331
bytesPerRowPaddedTo:padding
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13332
    "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
 13333
     if scanlines are to be padded to padding-bits."
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13334
2005
525f712084b3 oops - padding stuff was wrong (16-bit display)
tz
parents: 2001
diff changeset
 13335
    ^ self class
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13336
	bytesPerRowForWidth:width depth:(self bitsPerPixel) padding:padding
1993
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13337
!
b3cf63f64e15 added query for padded bytesPerLine
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
 13338
1935
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13339
center
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13340
    "for compatibility with GC protocol - return the centerPoint"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13341
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13342
    ^ (width // 2) @ (height // 2)
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13343
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13344
    "Created: 22.10.1997 / 23:52:40 / cg"
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13345
!
b71d2b3766b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
 13346
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13347
colorFromValue:pixelValue
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13348
    "given a pixel value, return the corresponding color.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13349
     Pixel values start with 0.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13350
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13351
     - 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
 13352
5126
d3f2baf80581 color conversions fixed (16bit images)
Claus Gittinger <cg@exept.de>
parents: 5074
diff changeset
 13353
    |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
 13354
     numRedBits numGreenBits numBlueBits numAlphaBits|
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13355
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13356
    p := photometric.
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13357
    p isNil ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13358
        colorMap notNil ifTrue:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13359
            p := #palette
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13360
        ] ifFalse:[
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13361
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13362
            p := #blackIs0
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13363
        ]
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13364
    ].
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13365
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13366
    p == #blackIs0 ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13367
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13368
        ^ Color gray:(pixelValue * (100 / maxPixel)).
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13369
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13370
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13371
    p == #whiteIs0 ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13372
        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13373
        ^ 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
 13374
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13375
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13376
    p == #palette ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13377
        pixelValue >= colorMap size ifTrue:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13378
            ^ Color black
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13379
        ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13380
        clr := colorMap at:(pixelValue + 1).
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13381
        clr isNil ifTrue:[
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13382
            ^ Color black.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13383
        ].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13384
        ^ clr.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13385
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13386
1289
bcce666a0f35 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1288
diff changeset
 13387
    p == #rgb ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13388
        r := self redBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13389
        g := self greenBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13390
        b := self blueBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13391
        "/ scale...
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13392
        numRedBits := bitsPerSample at:1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13393
        numGreenBits := bitsPerSample at:2.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13394
        numBlueBits := bitsPerSample at:3.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13395
        r := (r = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numRedBits)-1) * r)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13396
        g := (g = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numGreenBits)-1) * g)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13397
        b := (b = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numBlueBits)-1) * b)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13398
        ^ Color redPercent:r greenPercent:g bluePercent:b
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13399
    ].
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13400
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 13401
    ((p == #rgba) or:[p == #argb]) ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13402
        r := self redBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13403
        g := self greenBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13404
        b := self blueBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13405
        a := self alphaBitsOf:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13406
        "/ scale...
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13407
        numRedBits := bitsPerSample at:1.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13408
        numGreenBits := bitsPerSample at:2.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13409
        numBlueBits := bitsPerSample at:3.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13410
        numAlphaBits := bitsPerSample at:4.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13411
        r := (r = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numRedBits)-1) * r)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13412
        g := (g = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numGreenBits)-1) * g)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13413
        b := (b = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numBlueBits)-1) * b)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13414
        a := (a = 0) ifTrue:[0] ifFalse:[(100 / ((1 bitShift:numAlphaBits)-1) * a)].
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13415
        ^ Color redPercent:r greenPercent:g bluePercent:b alphaPercent:a
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13416
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13417
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13418
    p == #cmyk ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13419
        c := self cyanComponentOfCMYK:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13420
        m := self magentaComponentOfCMYK:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13421
        y := self yellowComponentOfCMYK:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13422
        k := self blackComponentOfCMYK:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13423
        ^ 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
 13424
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13425
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13426
    p == #cmy ifTrue:[
6826
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13427
        c := self cyanComponentOfCMY:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13428
        m := self magentaComponentOfCMY:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13429
        y := self yellowComponentOfCMY:pixelValue.
1081ccc4cbd8 class: Image
Claus Gittinger <cg@exept.de>
parents: 6797
diff changeset
 13430
        ^ Color cyan:c magenta:m yellow:y.
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13431
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13432
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13433
    self error:'invalid (unsupported) photometric'
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13434
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13435
    "Created: / 08-06-1996 / 08:46:18 / cg"
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13436
    "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
 13437
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13438
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13439
cyanComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13440
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13441
     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
 13442
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13443
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13444
	"/ 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
 13445
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13446
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13447
	    ^ 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
 13448
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13449
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13450
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13451
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13452
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13453
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13454
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13455
cyanComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13456
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13457
     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
 13458
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13459
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13460
	"/ 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
 13461
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13462
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13463
	    ^ 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
 13464
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13465
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13466
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13467
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13468
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13469
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13470
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13471
greenBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13472
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13473
     return the green bits of a pixelValue as integer 0..maxGreenValue.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13474
     MaxGreenValue is of course the largest integer representable by the number
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13475
     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
 13476
     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
 13477
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13478
    |blueBits greenBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13479
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13480
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13481
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13482
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13483
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13484
	^ (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
 13485
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13486
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13487
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13488
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13489
    "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
 13490
    "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
 13491
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13492
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13493
greenComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13494
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13495
     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
 13496
     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
 13497
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13498
    |greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13499
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13500
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13501
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13502
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13503
	"/ 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
 13504
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13505
	greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13506
	greenBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13507
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13508
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13509
	s := (1 bitShift:greenBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13510
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13511
	^ 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
 13512
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13513
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13514
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13515
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13516
    "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
 13517
    "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
 13518
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13519
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13520
greenMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13521
    "return the mask used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13522
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13523
    |greenBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13524
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13525
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13526
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13527
	^ (1 bitShift:greenBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13528
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13529
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13530
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13531
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13532
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13533
greenShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13534
    "return the shift amount used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13535
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 13536
    |greenBits|
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13537
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13538
    samplesPerPixel >= 3 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13539
	greenBits := bitsPerSample at:3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13540
	^ greenBits negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13541
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13542
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13543
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13544
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13545
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13546
heightOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13547
    "return my height, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13548
     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
 13549
     return the pixel-height"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13550
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 13551
    ^ height
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13552
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13553
    "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
 13554
    "Modified: 13.5.1996 / 10:26:36 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13555
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13556
3700
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13557
isDithered
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13558
    "for compatibility with color protocol"
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13559
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13560
    ^ false
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13561
!
9b40f1e55270 dummy isDithered - for color compatibility
Claus Gittinger <cg@exept.de>
parents: 3656
diff changeset
 13562
3507
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13563
isGrayscaleImage
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13564
    ^ (photometric ~= #palette)
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13565
      and:[photometric ~= #rgb]
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13566
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13567
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13568
    "Created: 22.4.1997 / 14:12:02 / cg"
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13569
!
2edb2b607331 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
 13570
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13571
isImage
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13572
    "return true, if the receiver is some kind of image;
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13573
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13574
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13575
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13576
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13577
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13578
isImageOrForm
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13579
    "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
 13580
     true is returned here - the method is redefined from Object."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13581
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13582
    ^ true
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13583
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13584
1630
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13585
isMask
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13586
    ^ false
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13587
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13588
    "Created: 22.4.1997 / 14:12:02 / cg"
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13589
!
e75c600b1c2a added #isMask query;
Claus Gittinger <cg@exept.de>
parents: 1623
diff changeset
 13590
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13591
magentaComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13592
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13593
     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
 13594
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13595
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13596
	"/ 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
 13597
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13598
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13599
	    ^ 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
 13600
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13601
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13602
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13603
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13604
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13605
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13606
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13607
magentaComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13608
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13609
     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
 13610
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13611
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13612
	"/ 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
 13613
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13614
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13615
	    ^ 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
 13616
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13617
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13618
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13619
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13620
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13621
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 13622
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13623
pixelArraySpecies
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13624
    "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
 13625
6648
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13626
    |d|
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13627
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13628
    (d := self depth) <= 8 ifTrue:[^ ByteArray].
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13629
    "/ d <= 16 ifTrue:[^ WordArray].
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13630
    "/ ^ IntegerArray
dc88bb5f9231 class: Image
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
 13631
    ^ Array
1433
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13632
!
f243ebc8d043 more ST80 mimicri stuff
Claus Gittinger <cg@exept.de>
parents: 1403
diff changeset
 13633
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13634
realColorMap
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13635
    "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
 13636
     For palette images, this is the internal colormap;
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13637
     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
 13638
     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
 13639
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13640
    |d nEntries "{ Class: SmallInteger }"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13641
     colorArray|
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13642
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13643
    photometric == #palette ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13644
	^ colorMap asArray
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13645
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13646
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13647
    d := self depth.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13648
    d > 12 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13649
	self error:'deep palette images not supported'.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13650
	^ nil.
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13651
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13652
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13653
    nEntries := 1 bitShift:d.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13654
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13655
    colorArray := Array new:nEntries.
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13656
    1 to:nEntries do:[:idx |
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13657
	colorArray at:idx put:(self colorFromValue:(idx-1)).
940
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13658
    ].
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13659
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13660
    ^ colorArray
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13661
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13662
    "Created: 11.7.1996 / 20:20:35 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13663
    "Modified: 11.7.1996 / 20:49:21 / cg"
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13664
!
3883a336b8be checkin from browser
Claus Gittinger <cg@exept.de>
parents: 936
diff changeset
 13665
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13666
realUsedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13667
    "return a collection of colors which are really used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13668
     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
 13669
     (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
 13670
6379
a8d53c1947f2 class: Image
Stefan Vogel <sv@exept.de>
parents: 6375
diff changeset
 13671
    ^ self realUsedValues collect:[:pixel | self colorFromValue:pixel] as:Set
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13672
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13673
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13674
realUsedValues
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13675
    "return a collection of color values used in the receiver.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13676
     Notice, that the interpretation of the pixels depends on the photometric
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13677
     of the image.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13678
     This is a general and therefore slow implementation; subclasses
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13679
     may want to redefine this method for more performance.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13680
     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
 13681
     (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
 13682
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13683
    |set last|
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13684
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13685
    set := IdentitySet new.
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13686
    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
 13687
	pixel ~~ last ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13688
	    set add:pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13689
	    last := pixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13690
	]
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13691
    ].
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13692
    ^ set
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13693
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13694
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13695
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13696
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedValues
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13697
    "
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13698
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13699
    "Modified: / 29.7.1998 / 21:29:44 / cg"
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13700
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13701
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13702
redBitsOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13703
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13704
     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
 13705
     MaxRedValue is the largest integer representable by the number
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13706
     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
 13707
     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
 13708
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13709
    |redBits greenBits blueBits|
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13710
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13711
    samplesPerPixel >= 3 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13712
	redBits := bitsPerSample at:1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13713
	greenBits := bitsPerSample at:2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13714
	blueBits := bitsPerSample at:3.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13715
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13716
	^ (pixel bitShift:(greenBits + blueBits) negated)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13717
	   bitAnd:(1 bitShift:redBits)-1
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13718
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13719
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13720
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13721
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13722
    "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
 13723
    "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
 13724
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13725
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13726
redComponentOf:pixel
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13727
    "if the receiver is an rgb-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 13728
     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
 13729
     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
 13730
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13731
    |redBits   "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13732
     greenBits "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13733
     blueBits  "{ Class: SmallInteger }"
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13734
     s         "{ Class: SmallInteger }"|
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13735
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13736
    samplesPerPixel >= 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13737
	"/ 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
 13738
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13739
	redBits := bitsPerSample at:1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13740
	redBits == 0 ifTrue:[^ 0].
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13741
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13742
	greenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13743
	blueBits := bitsPerSample at:3.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13744
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13745
	s := (1 bitShift:redBits) - 1.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13746
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13747
	^ 100.0 / s *
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13748
	  ((pixel bitShift:(greenBits + blueBits) negated)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 13749
	   bitAnd:(1 bitShift:redBits)-1)
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13750
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13751
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13752
    self subclassResponsibility
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13753
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13754
    "Created: 8.6.1996 / 08:45:30 / cg"
854
36f47b36b463 support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 852
diff changeset
 13755
    "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
 13756
!
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13757
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13758
redMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13759
    "return the mask used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13760
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13761
    |redBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13762
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13763
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13764
	redBits := bitsPerSample at:1.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13765
	^ (1 bitShift:redBits)-1
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13766
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13767
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13768
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13769
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13770
    "Created: 8.6.1996 / 09:44:51 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13771
    "Modified: 10.6.1996 / 14:59:05 / cg"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13772
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13773
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13774
redShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13775
    "return the shift amount used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13776
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13777
    |greenBits blueBits|
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13778
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13779
    samplesPerPixel >= 3 ifTrue:[
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13780
	greenBits := bitsPerSample at:2.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13781
	blueBits := bitsPerSample at:3.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13782
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 13783
	^ (greenBits + blueBits) negated
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13784
    ].
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13785
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13786
    self subclassResponsibility
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13787
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
 13788
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13789
rgbFromValue:pixelValue
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13790
    "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13791
     Pixel value is in 0..2^depth - 1.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13792
     The implementation below is generic and slow
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13793
     - this method is typically redefined in subclasses."
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13794
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13795
    |p maxPixel clr r g b c m y k|
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13796
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13797
    p := photometric.
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13798
    p isNil ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13799
	colorMap notNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13800
	    p := #palette
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13801
	] ifFalse:[
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13802
"/            'Image [warning]: no photometric - assume greyscale' infoPrintCR
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13803
	    p := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13804
	]
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13805
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13806
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13807
    p == #blackIs0 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13808
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13809
	b := pixelValue * 255 // maxPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13810
	^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13811
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13812
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13813
    p == #whiteIs0 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13814
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13815
	b := 255 - (pixelValue * 255 // maxPixel).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13816
	^ (((b bitShift:8) bitOr:b) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13817
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13818
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13819
    p == #palette ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13820
	pixelValue >= colorMap size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13821
	    ^ 0 "/ black
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13822
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13823
	clr := colorMap at:(pixelValue + 1).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13824
	clr isNil ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13825
	    ^ 0 "/ black
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13826
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13827
	^ clr rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13828
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13829
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13830
    p == #rgb ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13831
	r := self redBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13832
	g := self greenBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13833
	b := self blueBitsOf:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13834
	"/ must scale to byte value...
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13835
	r := r bitShift:(8 - (bitsPerSample at:1)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13836
	g := g bitShift:(8 - (bitsPerSample at:2)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13837
	b := b bitShift:(8 - (bitsPerSample at:3)).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13838
	^ (((r bitShift:8) bitOr:g) bitShift:8) bitOr:b
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13839
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13840
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13841
    p == #cmyk ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13842
	c := self cyanComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13843
	m := self magentaComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13844
	y := self yellowComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13845
	k := self blackComponentOfCMYK:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13846
	^ (Color cyan:c magenta:m yellow:y black:k) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13847
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13848
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13849
    p == #cmy ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13850
	c := self cyanComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13851
	m := self magentaComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13852
	y := self yellowComponentOfCMY:pixelValue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 13853
	^ (Color cyan:c magenta:m yellow:y) rgbValue.
4117
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13854
    ].
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13855
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13856
    self error:'invalid (unsupported) photometric'
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13857
!
Claus Gittinger <cg@exept.de>
parents: 4115
diff changeset
 13858
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13859
usedColors
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13860
    "return a collection of colors used in the receiver.
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13861
     This looks at the colorMap only if present.
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13862
     (as opposed to #realUsedColors, which goes through the pixels of the bitmap)"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13863
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13864
    |colors|
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13865
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13866
    colors := self usedColorsMax:4096.
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13867
    colors isNil ifTrue:[
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13868
        self error:'too many colors in image'.
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13869
    ].
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13870
    ^ colors
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13871
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13872
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13873
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13874
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13875
    "
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13876
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13877
    "Modified: / 7.9.1998 / 17:56:12 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13878
!
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13879
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13880
usedColorsMax:nMax
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13881
    "return a collection of colors used in the receiver;
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13882
     This looks at the colorMap only if present
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13883
     (as opposed to #realUsedColors, which goes through the pixels of the bitmap).
3964
31e7b1921e24 comments
Claus Gittinger <cg@exept.de>
parents: 3940
diff changeset
 13884
     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
 13885
     (useful when searching rgb images)."
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13886
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 13887
    |usedValues max colors|
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13888
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13889
    photometric == #rgb ifTrue:[
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13890
        usedValues := IdentitySet new.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13891
        self valuesFromX:0 y:0 toX:(width-1) y:(height-1)
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13892
          do:[:x :y :pixel |
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13893
            usedValues add:pixel.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13894
            usedValues size > nMax ifTrue:[
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13895
                "/ too many to be returned here (think of the mass of
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13896
                "/ data to be returned by a 24bit image ... ;-)
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13897
                ^ nil
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13898
            ]
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13899
        ].
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13900
        "/ code below is slightly faster ...
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13901
        "/ colors := usedValues collect:[:pixel | self colorFromValue:pixel].
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13902
        colors := usedValues collect:[:pixel | |r g b|
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13903
                                        r := self redBitsOf:pixel.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13904
                                        g := self greenBitsOf:pixel.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13905
                                        b := self blueBitsOf:pixel.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13906
                                        "/ must scale to byte value...
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13907
                                        r := r bitShift:(8 - (bitsPerSample at:1)).
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13908
                                        g := g bitShift:(8 - (bitsPerSample at:2)).
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13909
                                        b := b bitShift:(8 - (bitsPerSample at:3)).
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13910
                                        Color redByte:r greenByte:g blueByte:b
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13911
                                     ].
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13912
        ^ colors.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13913
    ].
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13914
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13915
    usedValues := self usedValues asArray.
804
f1921926e324 better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 800
diff changeset
 13916
    photometric == #palette ifTrue:[
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13917
        colors := usedValues collect:[:val | (colorMap at:val+1 ifAbsent:[Color black])] as:Set.
2199
ac56b54c59a5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2185
diff changeset
 13918
    ] ifFalse:[
6896
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13919
        "/ (photometric == #blackIs0 or:[photometric == #whiteIs0])
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13920
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13921
        max := (1 bitShift:self depth) - 1.
6dde273a9c0b class: Image
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
 13922
        colors :=  usedValues collect:[:val | (Color gray:(100 * val / max ))] as:Set.
6037
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 13923
    ].
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 13924
    ^ colors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13925
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13926
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13927
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedColors
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13928
     (Image fromFile:'libtool/bitmaps/SBrowser.xbm') usedColors
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13929
    "
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
 13930
2311
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13931
    "Created: / 7.9.1998 / 17:54:17 / cg"
1c7e68532808 better #usedColors for rgb images.
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
 13932
    "Modified: / 7.9.1998 / 17:56:21 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13933
!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13934
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13935
usedValues
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13936
    "return a collection of color values used in the receiver.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13937
     Notice, that the interpretation of the pixels depends on the photometric
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13938
     of the image.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13939
     This is a general and therefore slow implementation; subclasses
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13940
     may want to redefine this method for more performance."
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13941
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
 13942
    ^ self realUsedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13943
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13944
    "
4168
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13945
     (Image fromFile:'goodies/bitmaps/gifImages/garfield.gif') usedValues
4dc7af1c9538 Fix method-examples
Stefan Vogel <sv@exept.de>
parents: 4160
diff changeset
 13946
     (Image fromFile:'lib tool/bitmaps/SBrowser.xbm') usedValues
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 13947
    "
2206
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 13948
8bf0549762b8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2205
diff changeset
 13949
    "Modified: / 29.7.1998 / 21:29:44 / cg"
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13950
!
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 13951
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13952
valueFromColor:color
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13953
    "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
 13954
     Non-representable colors return nil."
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13955
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 13956
    |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
 13957
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 13958
    color colorId notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13959
	color == Color noColor ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13960
	    ^ nil "/ mask
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13961
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13962
	color device isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13963
	    ^ color colorId
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13964
	]
5051
492727d3e5f3 oops valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 5037
diff changeset
 13965
    ].
5037
2e515c9ee849 changed #valueFromColor:
Claus Gittinger <cg@exept.de>
parents: 4998
diff changeset
 13966
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13967
    photometric == #whiteIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13968
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13969
	^ maxPixel - (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13970
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13971
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13972
    photometric == #blackIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13973
	maxPixel := (1 bitShift:self bitsPerPixel) - 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13974
	^ (color brightness * maxPixel) rounded.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13975
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13976
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13977
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13978
	colorMap isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13979
	    "/ same as blackIs0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13980
	    maxPixel := (1 bitShift:self bitsPerPixel) - 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13981
	    ^ (color brightness * maxPixel) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13982
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13983
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13984
	pixel := colorMap indexOf:color.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13985
	pixel == 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13986
	    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13987
	     the color is not in the images colormap
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13988
	    "
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13989
	    ^ nil
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13990
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13991
	^ pixel - 1
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13992
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13993
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 13994
    photometric == #rgb ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13995
	samplesPerPixel >= 3 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13996
	    redBits := bitsPerSample at:1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13997
	    greenBits := bitsPerSample at:2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13998
	    blueBits := bitsPerSample at:3.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 13999
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14000
	    "/ map r/g/b to 0..255
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14001
	    r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14002
	    g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14003
	    b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14004
	    pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14005
	    ^ pixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14006
	]
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14007
    ].
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14008
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14009
    photometric == #rgba ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14010
	samplesPerPixel >= 4 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14011
	    redBits := bitsPerSample at:1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14012
	    greenBits := bitsPerSample at:2.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14013
	    blueBits := bitsPerSample at:3.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14014
	    alphaBits := bitsPerSample at:4.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14015
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14016
	    "/ map r/g/b/a to 0..255
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14017
	    r := (color red / 100.0 * ((1 bitShift:redBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14018
	    g := (color green / 100.0 * ((1 bitShift:greenBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14019
	    b := (color blue / 100.0 * ((1 bitShift:blueBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14020
	    a := (color alpha * ((1 bitShift:alphaBits)-1)) rounded.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14021
	    pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14022
	    ^ pixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14023
	]
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14024
    ].
2380
b9ac30f8e5ba made all my signals children of a common imageErrorSignal;
Claus Gittinger <cg@exept.de>
parents: 2350
diff changeset
 14025
    ImageErrorSignal raiseErrorString:'format not supported'.
861
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14026
    ^ nil
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14027
4788
0d07247aee8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
 14028
    "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
 14029
!
5d897dbd681a oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
 14030
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14031
valueFromRGB:rgb
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14032
    "given a color, return the corresponding pixel value.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14033
     Non-representable colors return nil."
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14034
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14035
    |pixel redBits greenBits blueBits alphaBits r g b a|
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14036
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14037
    r := rgb bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14038
    g := (rgb bitShift:-8) bitAnd:16rFF.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14039
    b := (rgb bitShift:-16) bitAnd:16rFF.
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14040
    a := 255.
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14041
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14042
"/    photometric == #whiteIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14043
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14044
"/        ^ maxPixel - (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14045
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14046
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14047
"/    photometric == #blackIs0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14048
"/        maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14049
"/        ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14050
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14051
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14052
"/    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14053
"/        colorMap isNil ifTrue:[
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14054
"/            "/ same as blackIs0
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14055
"/            maxPixel := (1 bitShift:self bitsPerPixel) - 1.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14056
"/            ^ (color brightness * maxPixel) rounded.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14057
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14058
"/
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14059
"/        pixel := colorMap indexOf:color.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14060
"/        pixel == 0 ifTrue:[
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14061
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14062
"/             the color is not in the images colormap
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14063
"/            "
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14064
"/            ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14065
"/        ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14066
"/        ^ pixel - 1
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14067
"/    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14068
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14069
    photometric == #rgb ifTrue:[
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14070
        samplesPerPixel >= 3 ifTrue:[
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14071
            "/ r,g,b  b at low end
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14072
            redBits := bitsPerSample at:1.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14073
            greenBits := bitsPerSample at:2.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14074
            blueBits := bitsPerSample at:3.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14075
            pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14076
            ^ pixel
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14077
        ]
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14078
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14079
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14080
    photometric == #rgba ifTrue:[
7123
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14081
        samplesPerPixel >= 4 ifTrue:[
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14082
            "/ a,r,g,b  b at low end
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14083
            redBits := bitsPerSample at:1.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14084
            greenBits := bitsPerSample at:2.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14085
            blueBits := bitsPerSample at:3.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14086
            alphaBits := bitsPerSample at:4.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14087
            pixel := (((((a bitShift:redBits) + r) bitShift:greenBits) + g) bitShift:blueBits) + b.
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14088
            ^ pixel
320a7ec771f3 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 7101
diff changeset
 14089
        ]
4858
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14090
    ].
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14091
    ImageErrorSignal raiseErrorString:'format not supported'.
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14092
    ^ nil
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14093
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14094
    "Created: / 15-01-2008 / 15:55:08 / cg"
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14095
!
bb9e88541077 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4843
diff changeset
 14096
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14097
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14098
    "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
 14099
     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
 14100
     For now, only useful with RGB images"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14101
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14102
    |pixel numGreenBits numBlueBits|
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14103
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14104
    photometric == #rgb ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14105
	samplesPerPixel >= 3 ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14106
	    numGreenBits := bitsPerSample at:2.
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14107
	    numBlueBits := bitsPerSample at:3.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14108
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14109
	    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
 14110
	    ^ pixel
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14111
	]
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14112
    ].
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14113
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14114
    ImageErrorSignal raiseErrorString:'format not supported'.
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14115
    ^ nil
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14116
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14117
    "Modified: / 30.9.1998 / 22:03:50 / cg"
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14118
!
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14119
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14120
widthOn:aGC
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14121
    "return my width, if displayed on aGC;
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14122
     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
 14123
     return the pixel-width"
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14124
680
a905d02dcb82 added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents: 674
diff changeset
 14125
    ^ width
674
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14126
e0f6bd36a99d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
 14127
    "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
 14128
    "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
 14129
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14130
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14131
yellowComponentOfCMY:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14132
    "if the receiver is a cmy-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14133
     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
 14134
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14135
    samplesPerPixel == 3 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14136
	"/ 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
 14137
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14138
	bitsPerSample = #(8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14139
	    ^ 100.0 / 255 * (pixel bitAnd:16rFF)
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14140
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14141
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14142
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14143
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14144
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14145
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14146
!
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14147
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14148
yellowComponentOfCMYK:pixel
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14149
    "if the receiver is a cmyk-image:
2916
79eedd2e05ac checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2913
diff changeset
 14150
     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
 14151
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14152
    samplesPerPixel == 4 ifTrue:[
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14153
	"/ 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
 14154
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14155
	bitsPerSample = #(8 8 8 8) ifTrue:[
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14156
	    ^ 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
 14157
	]
2890
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14158
    ].
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14159
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14160
    self subclassResponsibility
50b8c2e70c14 support cmyk and cmy separated images
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
 14161
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14162
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14163
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14164
!Image methodsFor:'saving on file'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14165
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14166
saveOn:aFileName
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14167
    "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
 14168
     Currently, not all formats may be supported
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14169
     (see ImageReader subclasses implementing save:onFile:).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 14170
     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
 14171
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14172
    |suffix readerClass|
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14173
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14174
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14175
    "/ from the extension, get the imageReader class
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14176
    "/ (which should know how to write images as well)
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14177
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14178
    suffix := aFileName asFilename suffix.
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 14179
    readerClass := MIMETypes imageReaderForSuffix:suffix.
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14180
    readerClass notNil ifTrue:[
6797
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
 14181
        ^ self saveOn:aFileName using:readerClass
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14182
    ].
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14183
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14184
    "/
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14185
    "/ no known extension - could ask user for the format here.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14186
    "/ currently default to tiff format.
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14187
    "/
6797
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
 14188
    'Image [warning]: unknown extension - cannot figure out format - using default (tiff)' errorPrintCR.
161685b0d113 class: Image
Claus Gittinger <cg@exept.de>
parents: 6755
diff changeset
 14189
    ^ self saveOn:aFileName using:(self class defaultImageFileWriter)
1175
5595569cfbd3 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1170
diff changeset
 14190
1385
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14191
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14192
     |image|
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14193
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14194
     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
 14195
     image saveOn:'myImage.tiff'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14196
     image saveOn:'myImage.xbm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14197
     image saveOn:'myImage.xpm'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14198
     image saveOn:'myImage.xwd'.
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14199
    "
461b3901950e more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents: 1374
diff changeset
 14200
1799
054302440308 moved all mime-knowledge to MIMETypes
Claus Gittinger <cg@exept.de>
parents: 1786
diff changeset
 14201
    "Modified: 30.6.1997 / 22:06:34 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 14202
!
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
 14203
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14204
saveOn:aFileName using:readerClass
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14205
    "save the receiver using the representation class
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14206
     (which is usually a concrete subclasses of ImageReader).
3913
25e103c84773 comments
Claus Gittinger <cg@exept.de>
parents: 3912
diff changeset
 14207
     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
 14208
1307
f1223fbd4e15 new suffix table
Claus Gittinger <cg@exept.de>
parents: 1306
diff changeset
 14209
    ^ readerClass save:self onFile:aFileName
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14210
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14211
    "
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14212
     |anImage|
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14213
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14214
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14215
     anImage saveOn:'myImage.tiff' using:TIFFReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14216
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14217
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14218
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14219
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14220
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14221
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14222
     anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14223
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14224
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14225
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14226
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14227
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14228
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14229
     Image cannotRepresentImageSignal handle:[:ex |
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 14230
	self warn:'cannot save the image in this format'
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14231
     ] do:[
4033
9af502584519 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3966
diff changeset
 14232
	anImage saveOn:'myImage.xbm' using:XBMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14233
     ]
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14234
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14235
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14236
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14237
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14238
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14239
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14240
     anImage saveOn:'myImage.xpm' using:XPMReader.
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14241
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14242
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14243
    "
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14244
     |anImage|
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14245
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14246
     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
1573
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14247
     anImage saveOn:'myImage.gif' using:GIFReader.
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14248
    "
61046386f41f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1572
diff changeset
 14249
1575
d93e15f64146 comments
Claus Gittinger <cg@exept.de>
parents: 1573
diff changeset
 14250
    "Modified: 10.4.1997 / 17:49:26 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
 14251
! !
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14252
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14253
!Image methodsFor:'screen capture'!
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14254
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14255
from:aDrawable in:aRectangle
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14256
    "read an image from aDrawable.
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14257
     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
 14258
     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
 14259
     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
 14260
     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
 14261
     and to read hardcopy images from the screen."
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14262
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14263
    | visType
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14264
     x        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14265
     y        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14266
     w        "{ Class: SmallInteger }"
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14267
     h        "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14268
     dstIndex "{ Class: SmallInteger }"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14269
     srcIndex "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14270
     srcRow   "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14271
     dstRow   "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14272
     inData tmpData usedPixels mapSize
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14273
     map bytesPerLine
2534
35d91dcc4604 removed unused local
Claus Gittinger <cg@exept.de>
parents: 2533
diff changeset
 14274
     bitOrder spaceBitsPerPixel
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14275
     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
 14276
     bitsR "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14277
     bitsG "{ Class: SmallInteger }"
e2c3f84ff31f fixed pixmap readout for win32, where red and green are exchanged
Claus Gittinger <cg@exept.de>
parents: 3518
diff changeset
 14278
     bitsB "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14279
     maskR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14280
     maskG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14281
     maskB "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14282
     shR "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14283
     shG "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14284
     shB "{ Class: SmallInteger }"
401
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14285
     shR2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14286
     shG2 "{ Class: SmallInteger }"
f163a93a0987 grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents: 399
diff changeset
 14287
     shB2 "{ Class: SmallInteger }"
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14288
     r "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14289
     g "{ Class: SmallInteger }"
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14290
     b "{ Class: SmallInteger }"
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14291
     word "{ Class: SmallInteger }"
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14292
     lword
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14293
     device ddepth isMSB|
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14294
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14295
    depth := self depth.
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14296
    bitsPerPixel := self bitsPerPixel.
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14297
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
 14298
    device := aDrawable graphicsDevice.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14299
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14300
    (aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14301
	"/ a monochrome bitmap ?
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14302
	visType := #StaticGray.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14303
	ddepth := 1.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14304
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14305
	(aDrawable isForm) ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14306
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14307
	     get some attributes of the display device
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14308
	    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14309
	    visType := device visualType.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14310
	    ddepth := device depth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14311
	] ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14312
	    ddepth := aDrawable depth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14313
	    visType := aDrawable photometric
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14314
	].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14315
    ].
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14316
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14317
    "/ kludge for 15bit XFree server
2019
0de58c8e3262 fixed screen-capture (for 16bit)
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
 14318
    ddepth == 15 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14319
	ddepth := 16
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14320
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14321
4421
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14322
    aDrawable isForm ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14323
	photometric := aDrawable photometric.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14324
	samplesPerPixel := ddepth == 24 ifTrue:3 ifFalse:1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14325
	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
 14326
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14327
	(visType == #StaticGray) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14328
	    (device blackpixel == 0) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14329
		photometric := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14330
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14331
		photometric := #whiteIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14332
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14333
	    samplesPerPixel := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14334
	    bitsPerPixel := ddepth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14335
	    bitsPerSample := ByteArray with:bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14336
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14337
	    ((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14338
		photometric := #palette.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14339
		samplesPerPixel := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14340
		bitsPerPixel := ddepth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14341
		bitsPerSample := ByteArray with:bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14342
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14343
		((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14344
		    photometric := #rgb.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14345
		    samplesPerPixel := 3.
4421
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14346
    "/                bitsPerPixel := depth.
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14347
    "/                bitsPerSample := ByteArray with:device bitsRed
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14348
    "/                                       with:device bitsGreen
bcc5886c989c form -> image conversion fixes
james
parents: 4420
diff changeset
 14349
    "/                                       with:device bitsBlue
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14350
		    bitsPerPixel := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14351
		    bitsPerSample := #(8 8 8).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14352
		] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14353
		    self error:'screen visual not supported'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14354
		    ^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14355
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14356
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14357
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14358
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14359
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14360
    "
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14361
     dont know yet, how the display pads; assume worst case,
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14362
     offering enough space for 32 bit padding
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14363
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14364
    w := width := aRectangle width.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14365
    h := height := aRectangle height.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14366
    x := aRectangle left.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14367
    y := aRectangle top.
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14368
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14369
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14370
     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
 14371
     (its too late when info is present ...)
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14372
    "
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14373
    spaceBitsPerPixel := bitsPerPixel.
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14374
    (bitsPerPixel > 8) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14375
	spaceBitsPerPixel := 16.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14376
	(bitsPerPixel > 16) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14377
	    spaceBitsPerPixel := 32.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14378
	    (bitsPerPixel > 32) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14379
		spaceBitsPerPixel := bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14380
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14381
	]
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14382
    ].
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14383
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14384
    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
 14385
    "/ 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
 14386
    inData := ByteArray new:(bytesPerLine * height).
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14387
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14388
    "
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14389
     get the pixels
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14390
    "
1459
84e80b355553 splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents: 1446
diff changeset
 14391
    aDrawable isForm ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14392
	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
 14393
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14394
	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
 14395
    ].
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14396
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14397
    bitsPerPixelIn := info at:#bitsPerPixel.
2533
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 14398
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 14399
    isMSB := ((info at:#byteOrder) == #msbFirst).
3af95252b1b3 oops - ISMSB was not assigned
Claus Gittinger <cg@exept.de>
parents: 2532
diff changeset
 14400
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14401
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14402
    "/ check if bitorder is what I like (msbFirst)
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14403
    "/
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14404
    "/ mhmh - thats not needed
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14405
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14406
    bitsPerPixelIn < 8 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14407
	bitOrder := info at:#bitOrder.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14408
	bitOrder ~~ #msbFirst ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14409
	    inData
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14410
		expandPixels:8
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14411
		width:(inData size)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14412
		height:1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14413
		into:inData
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14414
		mapping:(ImageReader reverseBits "TODO: reverseBitsForDepth:bitsPerPixelIn").
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14415
	].
2029
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14416
    ].
99961ce13c2a oops - must care for bitOrder, if depth is <= 8
ca
parents: 2023
diff changeset
 14417
396
d088e672be8a handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents: 394
diff changeset
 14418
    "
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14419
     check, if the devices padding is different ..
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14420
     or if the bitsPerPixels are different
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14421
    "
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14422
    bytesPerLineIn := (info at:#bytesPerLine).                    "what I got"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14423
    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
 14424
3563
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 14425
    maskR := info at:#redMask ifAbsent:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 14426
    maskG := info at:#greenMask ifAbsent:0.
53da1b7dea33 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3561
diff changeset
 14427
    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
 14428
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14429
    ((bytesPerLine ~~ bytesPerLineIn)
399
0b6e43843204 handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents: 396
diff changeset
 14430
    or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14431
	tmpData := inData.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14432
	inData := ByteArray uninitializedNew:(bytesPerLine * height).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14433
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14434
	srcRow := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14435
	dstRow := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14436
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14437
	bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14438
	    "/ for now, only 32 -> 24 is supported
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14439
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14440
	    maskR == 0 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14441
		bitsR := device bitsRed.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14442
		bitsG := device bitsGreen.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14443
		bitsB := device bitsBlue.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14444
		maskR := (1 bitShift:bitsR) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14445
		maskG := (1 bitShift:bitsG) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14446
		maskB := (1 bitShift:bitsB) - 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14447
		shR := device shiftRed negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14448
		shG := device shiftGreen negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14449
		shB := device shiftBlue negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14450
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14451
		shR := (maskR lowBit - 1) negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14452
		bitsR := maskR highBit - maskR lowBit + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14453
		maskR := maskR bitShift:shR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14454
		shG := (maskG lowBit - 1) negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14455
		bitsG := maskG highBit - maskG lowBit + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14456
		maskG := maskG bitShift:shG.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14457
		shB := (maskB lowBit - 1) negated.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14458
		bitsB := maskB highBit - maskB lowBit + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14459
		maskB := maskB bitShift:shB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14460
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14461
	    shR2 := (8 - bitsR).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14462
	    shG2 := (8 - bitsG).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14463
	    shB2 := (8 - bitsB).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14464
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14465
	    ((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14466
		"/ 'reformatting 32->24...' printNL.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14467
		1 to:h do:[:hi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14468
		    srcIndex := srcRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14469
		    dstIndex := dstRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14470
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14471
		    1 to:w do:[:wi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14472
			lword := tmpData doubleWordAt:srcIndex MSB:isMSB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14473
			r := (lword bitShift:shR) bitAnd:maskR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14474
			g := (lword bitShift:shG) bitAnd:maskG.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14475
			b := (lword bitShift:shB) bitAnd:maskB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14476
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14477
			inData at:dstIndex   put:r.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14478
			inData at:dstIndex+1 put:g.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14479
			inData at:dstIndex+2 put:b.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14480
			srcIndex := srcIndex + 4.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14481
			dstIndex := dstIndex + 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14482
		    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14483
		    dstRow := dstRow + bytesPerLine.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14484
		    srcRow := srcRow + bytesPerLineIn
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14485
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14486
	    ] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14487
		((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14488
		    "/ 'reformatting 16->24...' printNL.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14489
		    1 to:h do:[:hi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14490
			srcIndex := srcRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14491
			dstIndex := dstRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14492
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14493
			1 to:w do:[:wi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14494
			    word := tmpData wordAt:srcIndex MSB:isMSB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14495
			    r := (word bitShift:shR) bitAnd:maskR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14496
			    g := (word bitShift:shG) bitAnd:maskG.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14497
			    b := (word bitShift:shB) bitAnd:maskB.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14498
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14499
			    inData at:dstIndex   put:(r bitShift:shR2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14500
			    inData at:dstIndex+1 put:(g bitShift:shG2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14501
			    inData at:dstIndex+2 put:(b bitShift:shB2).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14502
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14503
			    srcIndex := srcIndex + 2.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14504
			    dstIndex := dstIndex + 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14505
			].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14506
			dstRow := dstRow + bytesPerLine.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14507
			srcRow := srcRow + bytesPerLineIn
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14508
		    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14509
		] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14510
		    ('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' ,
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14511
							bitsPerPixel printString) errorPrintCR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14512
		    self shouldImplement.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14513
		    ^ nil
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14514
		]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14515
	    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14516
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14517
	    "/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14518
	    "/ repad in the buffer
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14519
	    "/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14520
	    1 to:h do:[:hi |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14521
		inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14522
			      with:tmpData startingAt:srcRow.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14523
		dstRow := dstRow + bytesPerLine.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14524
		srcRow := srcRow + bytesPerLineIn
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14525
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14526
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14527
    ] ifFalse:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14528
	(bytesPerLine * height) ~~ inData size ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14529
	    tmpData := inData.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14530
	    inData := ByteArray uninitializedNew:(bytesPerLine * height).
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14531
	    inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14532
	]
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14533
    ].
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
 14534
    self bits:inData.
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14535
3864
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 14536
    "/
b04f2f0c5eae *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
 14537
    "/  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
 14538
    "/
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 14539
    photometric == #palette ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14540
	"/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14541
	"/ 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
 14542
	"/ find out, which colors are in the picture
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14543
	"/
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14544
	usedPixels := inData usedValues.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14545
	mapSize := usedPixels max + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14546
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14547
	"get the palette"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14548
	map := Array new:mapSize.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14549
	usedPixels do:[:colorIndex |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14550
	    |i|
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14551
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14552
	    i := colorIndex + 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14553
	    device getRGBFrom:colorIndex into:[:r :g :b |
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14554
		map at:i put:(Color red:r green:g blue:b)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14555
	    ]
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14556
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14557
	self setColorMap:map.
1644
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 14558
    ].
e06e1c7869fc care for bitOrder, when reading out device bits.
Claus Gittinger <cg@exept.de>
parents: 1642
diff changeset
 14559
1975
5b1a7d5e0b6a Fix #from:in: (screen capture) for palette (8 bit) displays.
Stefan Vogel <sv@exept.de>
parents: 1972
diff changeset
 14560
    "Modified: / 9.1.1998 / 21:32:36 / stefan"
2054
3d1619286006 fixed readout from 32bit servers
Claus Gittinger <cg@exept.de>
parents: 2050
diff changeset
 14561
    "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
 14562
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14563
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14564
fromScreen:aRectangle
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14565
    "read an image from the display screen.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14566
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14567
	      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
 14568
	      (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
 14569
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14570
    ^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14571
	fromScreen:aRectangle
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14572
	on:Screen current
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14573
	grab:true
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14574
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14575
    "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
 14576
!
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14577
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14578
fromScreen:aRectangle on:aDevice
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14579
    "read an image from aDevices display screen.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14580
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14581
     and PseudoColor cases have been tested ...
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14582
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14583
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14584
     WARNING: this temporarily grabs the display
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14585
	      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
 14586
	      (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
 14587
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14588
    ^ self
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14589
	fromScreen:aRectangle
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14590
	on:aDevice
3389
f8294b5fe0aa #asGray8FormOn: didnt work with partially filled colorMaps
Stefan Vogel <sv@exept.de>
parents: 3380
diff changeset
 14591
	grab:true
1662
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14592
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14593
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14594
     Image fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14595
     Image fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14596
    "
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14597
93de4bcdca85 commentary
Claus Gittinger <cg@exept.de>
parents: 1660
diff changeset
 14598
    "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
 14599
!
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14600
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14601
fromScreen:aRectangle on:aDevice grab:doGrab
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14602
    "read an image from aDevices display screen.
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14603
     If the doGrab argument is true, the display
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14604
     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
 14605
     shown while the readout is done.
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14606
     Since I have no other displays, only the MonoChrome, StaticGrey
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14607
     and PseudoColor cases have been tested ...
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14608
     (especially True- and DirectColor may be wrong).
1488
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14609
     Late note: 24bit rgb now also works.
436e5944129b comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents: 1487
diff changeset
 14610
     WARNING: with doGrab true, this temporarily grabs the display
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14611
              and it may not work from within a buttonMotion
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14612
              (use with a false grabArg then)."
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14613
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14614
    |curs rootView prevGrab|
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14615
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14616
    curs := nil.
4160
6d31e4e6a432 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 4159
diff changeset
 14617
"/    doGrab ifTrue:[ |cid|
3476
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14618
"/        curs := Cursor sourceForm:(Image fromFile:'bitmaps/Camera.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14619
"/                         maskForm:(Image fromFile:'bitmaps/Camera_m.xbm')
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14620
"/                          hotSpot:16@16.
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14621
"/        curs notNil ifTrue:[
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14622
"/            cid := (curs onDevice:aDevice) id
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14623
"/        ].
55a239ccd829 examples fixed
Claus Gittinger <cg@exept.de>
parents: 3475
diff changeset
 14624
"/    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14625
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14626
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14627
     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
 14628
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14629
    rootView := aDevice rootView.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14630
    doGrab ifTrue:[
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14631
        prevGrab := aDevice activePointerGrab.
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14632
        aDevice grabPointerInView:rootView withCursor:curs.
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14633
    ].
924
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14634
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14635
    "
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14636
     get the pixels
d6d5d427b176 fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents: 916
diff changeset
 14637
    "
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14638
    [
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14639
        self from:rootView in:aRectangle.
3605
b5c70808fc8c #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3563
diff changeset
 14640
    ] ensure:[
6613
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14641
        doGrab ifTrue:[
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14642
            aDevice ungrabPointer.
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14643
            prevGrab notNil ifTrue:[
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14644
                 aDevice grabPointerInView:prevGrab.
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14645
            ]
3b0f0fb40c2c class: Image
Claus Gittinger <cg@exept.de>
parents: 6592
diff changeset
 14646
        ]
1487
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14647
    ]
1d8efd4d85c3 allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
 14648
3092
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14649
    "
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14650
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:false
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14651
     Image fromScreen:((100@100) corner:(200@200)) on:Display grab:true
0f1a9ec64574 restore grab after #imageFromUser
ca
parents: 3059
diff changeset
 14652
    "
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14653
!
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14654
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14655
photometricFromScreen:aDevice
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14656
    "read aDevices display photometric and set my colormap for it.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14657
     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
 14658
     or from an offScreen bitmap, for correct pixel interpretation."
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14659
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14660
    |depth visType bitsPerPixel|
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14661
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14662
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14663
     get some attributes of the display device
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14664
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14665
    visType := aDevice visualType.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14666
    depth := aDevice depth.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14667
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14668
    "/ kludge for 15bit XFree server
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14669
    depth == 15 ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14670
	depth := 16
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14671
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14672
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14673
    (visType == #StaticGray) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14674
	(aDevice blackpixel == 0) ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14675
	    photometric := #blackIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14676
	] ifFalse:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14677
	    photometric := #whiteIs0
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14678
	].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14679
	samplesPerPixel := 1.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14680
	bitsPerPixel := depth.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14681
	bitsPerSample := ByteArray with:bitsPerPixel.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14682
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14683
	 were done, the pixel values are the grey values
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14684
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14685
	^ self
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14686
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14687
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14688
    ((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14689
	photometric := #rgb.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14690
	samplesPerPixel := 3.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14691
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14692
	"/ for now - only support 24bit TrueColor
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14693
	depth ~~ 24 ifTrue:[
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14694
	    'IMAGE: unsupported display depth' errorPrintCR.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14695
	].
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14696
"/                bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 14697
"/                bitsPerSample := ByteArray with:aDevice bitsRed
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14698
"/                                       with:aDevice bitsGreen
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14699
"/                                       with:aDevice bitsBlue
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14700
	bitsPerPixel := 24.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14701
	bitsPerSample := #[8 8 8].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14702
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14703
	 were done, the pixel values are the rgb values
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14704
	"
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14705
	^ self
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14706
    ].
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14707
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14708
    ((visType ~~ #PseudoColor)
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14709
    and:[(visType ~~ #StaticColor)
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14710
    and:[visType ~~ #GrayScale]]) ifTrue:[
4717
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14711
	self error:'screen visual not supported'.
c25149336a26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
 14712
	^ nil
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14713
    ].
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14714
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14715
    photometric := #palette.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14716
    samplesPerPixel := 1.
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14717
    bitsPerPixel := depth.
4115
0e783379a6b0 Use ByteArray for bitsPerSample (255 should be enough ;-)
Stefan Vogel <sv@exept.de>
parents: 4109
diff changeset
 14718
    bitsPerSample := ByteArray with:bitsPerPixel.
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14719
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14720
    "
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14721
     still need the pixels r/g/b values ...
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14722
    "
3863
b7ba8a04be25 always ensure colorMap is a real colorMap
Claus Gittinger <cg@exept.de>
parents: 3861
diff changeset
 14723
    self setColorMap:aDevice colorMap
936
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14724
e30ea164ccbf fromForm: fixes
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
 14725
    "Modified: 11.7.1996 / 11:11:34 / cg"
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14726
! !
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14727
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14728
!Image methodsFor:'virtual anti-aliased'!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14729
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14730
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
 14731
    |isBottom isLeft additionalY workPoint startX endX pixels pixelPos percent distance nearestKey tmp|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14732
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14733
    isBottom := bottomOrTop sameAs:'bottom'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14734
    isBottom ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14735
	additionalY := -1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14736
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14737
	additionalY := 1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14738
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14739
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14740
    isLeft := leftOrRight sameAs:'left'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14741
    isLeft ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14742
	workPoint := (xRun - 1)@yRun.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14743
	[(
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14744
	    (tempForm atX:workPoint x y:workPoint y) == 0 and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14745
	    (tempForm atX:workPoint x y:workPoint y + additionalY) == 1]) and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14746
	    (tempForm atX:workPoint x - 1 y:workPoint y + additionalY) == 1]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14747
	] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14748
	    startX := workPoint x.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14749
	    endX isNil ifTrue:[endX := workPoint x].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14750
	    workPoint := (workPoint x - 1)@yRun.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14751
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14752
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14753
	workPoint := (xRun + 1)@yRun.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14754
	[(
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14755
	    (tempForm atX:workPoint x y:workPoint y) == 0 and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14756
	    (tempForm atX:workPoint x y:workPoint y + additionalY) == 1]) and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14757
	    (tempForm atX:workPoint x + 1 y:workPoint y + additionalY) == 1]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14758
	] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14759
	    endX := workPoint x.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14760
	    startX isNil ifTrue:[startX := workPoint x].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14761
	    workPoint := (workPoint x + 1)@yRun.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14762
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14763
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14764
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14765
    (startX notNil and:[endX notNil]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14766
	startX = endX ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14767
	    self atImageAndMask:startX@yRun putValue:((colorDictionary at:aColor) at:blendStart).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14768
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14769
	    pixels := (endX - startX) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14770
	    startX to:endX do:[:x |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14771
		isLeft ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14772
		    pixelPos := (x - startX) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14773
		] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14774
		    pixelPos := (endX - x) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14775
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14776
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14777
		percent := (100 / (pixels / pixelPos)) asFloat / 100.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14778
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14779
		(colorDictionary at:aColor) keys do:[:aKey |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14780
		    nearestKey isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14781
			distance := percent dist:aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14782
			nearestKey := aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14783
		    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14784
			tmp := percent dist:aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14785
			distance > tmp ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14786
			    distance := tmp.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14787
			    nearestKey := aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14788
			].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14789
		    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14790
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14791
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14792
		self atImageAndMask:x@yRun putValue:((colorDictionary at:aColor) at:nearestKey).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14793
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14794
		distance := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14795
		nearestKey := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14796
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14797
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14798
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14799
!
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14800
5135
0a2a850a20cc *** empty log message ***
sr
parents: 5126
diff changeset
 14801
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
 14802
    |isLeft isBottom additionalX workPoint startY endY pixels pixelPos percent distance nearestKey tmp|
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14803
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14804
    isLeft := leftOrRight sameAs:'left'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14805
    isLeft ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14806
	additionalX := 1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14807
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14808
	additionalX := -1.
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14809
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14810
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14811
    isBottom := bottomOrTop sameAs:'bottom'.
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14812
    isBottom ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14813
	workPoint := xRun@(yRun + 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14814
	[(
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14815
	    (tempForm atX:workPoint x y:workPoint y) == 0 and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14816
	    (tempForm atX:workPoint x + additionalX y:workPoint y) == 1]) and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14817
	    (tempForm atX:workPoint x + additionalX y:workPoint y + 1) == 1]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14818
	] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14819
	    endY := workPoint y.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14820
	    startY isNil ifTrue:[startY := workPoint y].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14821
	    workPoint := xRun@(workPoint y + 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14822
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14823
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14824
	workPoint := xRun@(yRun - 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14825
	[(
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14826
	    (tempForm atX:workPoint x y:workPoint y) == 0 and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14827
	    (tempForm atX:workPoint x + additionalX y:workPoint y) == 1]) and:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14828
	    (tempForm atX:workPoint x + additionalX y:workPoint y - 1) == 1]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14829
	] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14830
	    startY := workPoint y.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14831
	    endY isNil ifTrue:[endY := workPoint y].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14832
	    workPoint := xRun@(workPoint y - 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14833
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14834
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14835
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14836
    (startY notNil and:[endY notNil]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14837
	startY = endY ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14838
	    self atImageAndMask:xRun@startY putValue:((colorDictionary at:aColor) at:blendStart).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14839
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14840
	    pixels := (endY - startY) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14841
	    startY to:endY do:[:y |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14842
		isBottom ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14843
		    pixelPos := (endY - y) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14844
		] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14845
		    pixelPos := (y - startY) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14846
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14847
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14848
		percent := (100 / (pixels / pixelPos)) asFloat / 100.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14849
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14850
		(colorDictionary at:aColor) keys do:[:aKey |
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14851
		    nearestKey isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14852
			distance := percent dist:aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14853
			nearestKey := aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14854
		    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14855
			tmp := percent dist:aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14856
			distance > tmp ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14857
			    distance := tmp.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14858
			    nearestKey := aKey.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14859
			].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14860
		    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14861
		].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14862
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14863
		self atImageAndMask:xRun@y putValue:((colorDictionary at:aColor) at:nearestKey).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14864
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14865
		distance := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14866
		nearestKey := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14867
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6037
diff changeset
 14868
	].
4998
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14869
    ].
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14870
! !
2ed2f4e7931e *** empty log message ***
sr
parents: 4997
diff changeset
 14871
1086
269243c32f69 added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1070
diff changeset
 14872
!Image class methodsFor:'documentation'!
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14873
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14874
version
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
 14875
    ^ '$Header$'
5476
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 14876
!
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 14877
06e08505bc6f __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5352
diff changeset
 14878
version_CVS
6894
0fc111a48edf class: Image
Claus Gittinger <cg@exept.de>
parents: 6862
diff changeset
 14879
    ^ '$Header$'
6912
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 14880
!
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 14881
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 14882
version_HG
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 14883
feaaf525e0d4 Added support for converting images to raw ARGB32 bits.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6900
diff changeset
 14884
    ^ '$Changeset: <not expanded> $'
650
14fc51fc3a4e comments
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
 14885
! !
3759
5b083b0ad909 fixed stupid flood-fill algorithm
Claus Gittinger <cg@exept.de>
parents: 3729
diff changeset
 14886
6037
eea2343b0b1e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5956
diff changeset
 14887
283
c4ff5f26ff44 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 237
diff changeset
 14888
Image initialize!